Exemplo n.º 1
0
void UmcFramework::ProcessShowScenarios()
{
	UmcScenario* pScenario;
	void* pVal;
	printf("%d Scenario(s)\n", apr_hash_count(m_pScenarioTable));
	apr_hash_index_t* it = apr_hash_first(m_pPool,m_pScenarioTable);
	for(; it; it = apr_hash_next(it))
	{
		apr_hash_this(it,NULL,NULL,&pVal);
		pScenario = (UmcScenario*) pVal;
		if(pScenario)
		{
			printf("[%s]\n", pScenario->GetName());
		}
	}
}
Exemplo n.º 2
0
void UmcFramework::DestroyScenarios()
{
	UmcScenario* pScenario;
	void* pVal;
	apr_hash_index_t* it = apr_hash_first(m_pPool,m_pScenarioTable);
	for(; it; it = apr_hash_next(it)) 
	{
		apr_hash_this(it,NULL,NULL,&pVal);
		pScenario = (UmcScenario*) pVal;
		if(pScenario)
		{
			pScenario->Destroy();
			delete pScenario;
		}
	}
	apr_hash_clear(m_pScenarioTable);
}
Exemplo n.º 3
0
bool UmcFramework::ProcessRunRequest(const char* pScenarioName, const char* pProfileName)
{
	UmcScenario* pScenario = (UmcScenario*) apr_hash_get(m_pScenarioTable,pScenarioName,APR_HASH_KEY_STRING);
	if(!pScenario)
		return false;

	UmcSession* pSession = pScenario->CreateSession();
	if(!pSession)
		return false;

	printf("[%s]\n",pSession->GetId());
	pSession->SetMrcpProfile(pProfileName);
	pSession->SetMrcpApplication(m_pMrcpApplication);
	if(!pSession->Run())
	{
		delete pSession;
		return false;
	}

	AddSession(pSession);
	return true;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}