Example #1
0
bool UmcFramework::LoadScenarios()
{
	apr_xml_doc* pDoc = LoadDocument();
	if(!pDoc)
		return false;

	const apr_xml_attr* pAttr;
	const apr_xml_elem* pElem;
	const apr_xml_elem* pRoot = pDoc->root;
	if(!pRoot || strcasecmp(pRoot->name,"umcscenarios") != 0)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Document");
		return FALSE;
	}
	for(pElem = pRoot->first_child; pElem; pElem = pElem->next)
	{
		if(strcasecmp(pElem->name,"scenario") != 0)
		{
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",pElem->name);
			continue;
		}
		
		const char* pName = NULL;
		const char* pClass = NULL;
		const char* pMrcpProfile = NULL;
		for(pAttr = pElem->attr; pAttr; pAttr = pAttr->next) 
		{
			if(strcasecmp(pAttr->name,"name") == 0) 
			{
				pName = pAttr->value;
			}
			else if(strcasecmp(pAttr->name,"class") == 0) 
			{
				pClass = pAttr->value;
			}
			else if(strcasecmp(pAttr->name,"profile") == 0) 
			{
				pMrcpProfile = pAttr->value;
			}
		}

		if(pName && pClass)
		{
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Load Scenario name [%s] class [%s]",pName,pClass);
			UmcScenario* pScenario = CreateScenario(pClass);
			if(pScenario)
			{
				pScenario->SetDirLayout(m_pDirLayout);
				pScenario->SetName(pName);
				pScenario->SetMrcpProfile(pMrcpProfile);
				if(pScenario->Load(pElem,m_pPool))
					apr_hash_set(m_pScenarioTable,pScenario->GetName(),APR_HASH_KEY_STRING,pScenario);
				else
					delete pScenario;
			}
			else
			{
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No such scenario <%s>",pClass);
			}
		}
		else
		{
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Missing either name or class of the scenario");
		}
	}
	return true;
}
Example #2
0
bool UmcFramework::LoadScenario(const char* pFilePath)
{
	apr_xml_parser* pParser = NULL;
	apr_xml_doc* pDoc = NULL;
	apr_file_t* pFD = NULL;
	const apr_xml_attr* pAttr;
	const apr_xml_elem* pRoot;
	const char* pName = NULL;
	const char* pClass = NULL;
	const char* pMrcpProfile = NULL;
	apr_status_t rv;

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Open Scenario File [%s]",pFilePath);
	rv = apr_file_open(&pFD,pFilePath,APR_READ|APR_BINARY,0,m_pPool);
	if(rv != APR_SUCCESS) 
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Open Scenario File [%s]",pFilePath);
		return false;
	}

	rv = apr_xml_parse_file(m_pPool,&pParser,&pDoc,pFD,2000);
	apr_file_close(pFD);
	if(rv != APR_SUCCESS)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Parse Scenario File [%s]",pFilePath);
		return false;
	}

	pRoot = pDoc->root;
	if(!pRoot || strcasecmp(pRoot->name,"umcscenario") != 0)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Document");
		return false;
	}

	for(pAttr = pRoot->attr; pAttr; pAttr = pAttr->next)
	{
		if(strcasecmp(pAttr->name,"name") == 0) 
		{
			pName = pAttr->value;
		}
		else if(strcasecmp(pAttr->name,"class") == 0) 
		{
			pClass = pAttr->value;
		}
		else if(strcasecmp(pAttr->name,"profile") == 0) 
		{
			pMrcpProfile = pAttr->value;
		}
	}

	if(!pName)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Missing Scenario Name");
		return false;
	}

	if(!pClass)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Missing Scenario Class");
		return false;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Load Scenario Name [%s] Class [%s]",pName,pClass);
	UmcScenario* pScenario = CreateScenario(pClass);
	if(!pScenario)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Scenario Class [%s]",pClass);
		return false;
	}

	pScenario->SetDirLayout(m_pDirLayout);
	pScenario->SetName(pName);
	pScenario->SetMrcpProfile(pMrcpProfile);
	if(!pScenario->Load(pRoot,m_pPool))
	{
		delete pScenario;
		return false;
	}

	apr_hash_set(m_pScenarioTable,pScenario->GetName(),APR_HASH_KEY_STRING,pScenario);
	return true;
}