Beispiel #1
0
int main(int argc, const char * const *argv)
{
	apr_pool_t *pool;
	server_options_t options;
	const char *log_conf_path;
	apt_dir_layout_t *dir_layout = NULL;

	/* APR global initialization */
	if(apr_initialize() != APR_SUCCESS) {
		apr_terminate();
		return 0;
	}

	/* create APR pool */
	pool = apt_pool_create();
	if(!pool) {
		apr_terminate();
		return 0;
	}

	/* load options */
	if(options_load(&options,argc,argv,pool) != TRUE) {
		apr_pool_destroy(pool);
		apr_terminate();
		return 0;
	}

	if(options.dir_layout_conf) {
		/* create and load directories layout from the configuration file */
		dir_layout = apt_dir_layout_create(pool);
		if(dir_layout)
			apt_dir_layout_load(dir_layout,options.dir_layout_conf,pool);
	}
	else {
		/* create default directories layout */
		dir_layout = apt_default_dir_layout_create(options.root_dir_path,pool);
	}

	if(!dir_layout) {
		printf("Failed to Create Directories Layout\n");
		apr_pool_destroy(pool);
		apr_terminate();
		return 0;
	}

	/* get path to logger configuration file */
	log_conf_path = apt_confdir_filepath_get(dir_layout,"logger.xml",pool);
	/* create and load singleton logger */
	apt_log_instance_load(log_conf_path,pool);

	if(options.log_priority) {
		/* override the log priority, if specified in command line */
		apt_log_priority_set(atoi(options.log_priority));
	}
	if(options.log_output) {
		/* override the log output mode, if specified in command line */
		apt_log_output_mode_set(atoi(options.log_output));
	}

	if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) {
		/* open the log file */
		const char *log_dir_path = apt_dir_layout_path_get(dir_layout,APT_LAYOUT_LOG_DIR);
		apt_log_file_open(log_dir_path,"unimrcpserver",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool);
	}

	if(options.foreground == TRUE) {
		/* run command line */
		uni_cmdline_run(dir_layout,pool);
	}
#ifdef WIN32
	else {
		/* run as windows service */
		uni_service_run(options.svcname,dir_layout,pool);
	}
#else
	else {
/** Create ASR engine */
ASR_CLIENT_DECLARE(asr_engine_t*) asr_engine_create(
									const char *root_dir_path,
									apt_log_priority_e log_priority,
									apt_log_output_e log_output)
{
	apr_pool_t *pool = NULL;
	apt_dir_layout_t *dir_layout;
	asr_engine_t *engine;
	mrcp_client_t *mrcp_client;
	mrcp_application_t *mrcp_app;

	/* create APR pool */
	pool = apt_pool_create();
	if(!pool) {
		return NULL;
	}

	/* create the structure of default directories layout */
	dir_layout = apt_default_dir_layout_create(root_dir_path,pool);
	/* create singleton logger */
	apt_log_instance_create(log_output,log_priority,pool);

	if((log_output & APT_LOG_OUTPUT_FILE) == APT_LOG_OUTPUT_FILE) {
		/* open the log file */
		apt_log_file_open(dir_layout->log_dir_path,"unimrcpclient",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,FALSE,pool);
	}

	engine = apr_palloc(pool,sizeof(asr_engine_t));
	engine->pool = pool;
	engine->mrcp_client = NULL;
	engine->mrcp_app = NULL;

	/* create UniMRCP client stack */
	mrcp_client = unimrcp_client_create(dir_layout);
	if(!mrcp_client) {
		apt_log_instance_destroy();
		apr_pool_destroy(pool);
		return NULL;
	}
	
	/* create an application */
	mrcp_app = mrcp_application_create(
								app_message_handler,
								engine,
								pool);
	if(!mrcp_app) {
		mrcp_client_destroy(mrcp_client);
		apt_log_instance_destroy();
		apr_pool_destroy(pool);
		return NULL;
	}

	/* register application in client stack */
	mrcp_client_application_register(mrcp_client,mrcp_app,"ASRAPP");

	/* start client stack */
	if(mrcp_client_start(mrcp_client) != TRUE) {
		mrcp_client_destroy(mrcp_client);
		apt_log_instance_destroy();
		apr_pool_destroy(pool);
		return NULL;
	}

	engine->mrcp_client = mrcp_client;
	engine->mrcp_app = mrcp_app;
	return engine;
}
Beispiel #3
0
int main(int argc, const char * const *argv)
{
	apr_pool_t *pool = NULL;
	client_options_t options;
	apt_dir_layout_t *dir_layout;
	const char *log_conf_path;
	demo_framework_t *framework;

	/* APR global initialization */
	if(apr_initialize() != APR_SUCCESS) {
		apr_terminate();
		return 0;
	}

	/* create APR pool */
	pool = apt_pool_create();
	if(!pool) {
		apr_terminate();
		return 0;
	}

	/* set the default options */
	options.root_dir_path = "../";
	options.log_priority = NULL;
	options.log_output = NULL;

	/* load options */
	if(demo_framework_options_load(&options,argc,argv,pool) != TRUE) {
		apr_pool_destroy(pool);
		apr_terminate();
		return 0;
	}

	/* create the structure of default directories layout */
	dir_layout = apt_default_dir_layout_create(options.root_dir_path,pool);

	/* get path to logger configuration file */
	log_conf_path = apt_confdir_filepath_get(dir_layout,"logger.xml",pool);
	/* create and load singleton logger */
	apt_log_instance_load(log_conf_path,pool);

	if(options.log_priority) {
		/* override the log priority, if specified in command line */
		apt_log_priority_set(atoi(options.log_priority));
	}
	if(options.log_output) {
		/* override the log output mode, if specified in command line */
		apt_log_output_mode_set(atoi(options.log_output));
	}

	if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) {
		/* open the log file */
		apt_log_file_open(dir_layout->log_dir_path,"unimrcpclient",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,pool);
	}

	/* create demo framework */
	framework = demo_framework_create(dir_layout);
	if(framework) {
		/* run command line  */
		demo_framework_cmdline_run(framework);
		/* destroy demo framework */
		demo_framework_destroy(framework);
	}

	/* destroy singleton logger */
	apt_log_instance_destroy();
	/* destroy APR pool */
	apr_pool_destroy(pool);
	/* APR global termination */
	apr_terminate();
	return 0;
}
/** \brief Load UniMRCP engine */
static apt_bool_t uni_engine_load()
{
	apr_pool_t *pool;
	apt_dir_layout_t *dir_layout;

	/* APR global initialization */
	if(apr_initialize() != APR_SUCCESS) {
		ast_log(LOG_ERROR, "Failed to initialize APR\n");
		return FALSE;
	}

	uni_engine.pool = NULL;
	uni_engine.client = NULL;
	uni_engine.application = NULL;
	uni_engine.profile = NULL;
	uni_engine.log_level = APT_PRIO_INFO;
	uni_engine.log_output = APT_LOG_OUTPUT_CONSOLE | APT_LOG_OUTPUT_FILE;
	uni_engine.grammars = NULL;

	pool = apt_pool_create();
	if(!pool) {
		ast_log(LOG_ERROR, "Failed to create APR pool\n");
		uni_engine_unload();
		return FALSE;
	}

	uni_engine.pool = pool;
	uni_engine.v2_properties = NULL;
	uni_engine.v1_properties = NULL;

	/* Load engine configuration */
	uni_engine_config_load(pool);

	if(!uni_engine.profile) {
		uni_engine.profile = "uni2";
	}

	dir_layout = apt_default_dir_layout_create(UNIMRCP_DIR_LOCATION,pool);
	/* Create singleton logger */
	apt_log_instance_create(uni_engine.log_output, uni_engine.log_level, pool);
	/* Open the log file */
	apt_log_file_open(dir_layout->log_dir_path,"astuni",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool);

	uni_engine.client = unimrcp_client_create(dir_layout);
	if(uni_engine.client) {
		uni_engine.application = mrcp_application_create(
										uni_message_handler,
										&uni_engine,
										pool);
		if(uni_engine.application) {
			mrcp_client_application_register(
							uni_engine.client,
							uni_engine.application,
							"ASTMRCP");
		}
	}

	if(!uni_engine.client || !uni_engine.application) {
		ast_log(LOG_ERROR, "Failed to initialize client stack\n");
		uni_engine_unload();
		return FALSE;
	}

	return TRUE;
}
/** \brief Load UniMRCP engine */
static apt_bool_t uni_engine_load()
{
	apr_pool_t *pool;
	apt_dir_layout_t *dir_layout;

	/* APR global initialization */
	if(apr_initialize() != APR_SUCCESS) {
		ast_log(LOG_ERROR, "Failed to initialize APR\n");
		return FALSE;
	}

	uni_engine.pool = NULL;
	uni_engine.client = NULL;
	uni_engine.application = NULL;
	uni_engine.profile = NULL;
	uni_engine.log_level = APT_PRIO_INFO;
	uni_engine.log_output = APT_LOG_OUTPUT_CONSOLE | APT_LOG_OUTPUT_FILE;
	uni_engine.grammars = NULL;
	uni_engine.v2_properties = NULL;
	uni_engine.v1_properties = NULL;
	uni_engine.mutex = NULL;
	uni_engine.current_speech_index = 0;

	pool = apt_pool_create();
	if(!pool) {
		ast_log(LOG_ERROR, "Failed to create APR pool\n");
		uni_engine_unload();
		return FALSE;
	}

	uni_engine.pool = pool;

	if(apr_thread_mutex_create(&uni_engine.mutex, APR_THREAD_MUTEX_DEFAULT, pool) != APR_SUCCESS) {
		ast_log(LOG_ERROR, "Failed to create engine mutex\n");
		uni_engine_unload();
		return FALSE;
	}

	/* Load engine configuration */
	uni_engine_config_load(pool);

	if(!uni_engine.profile) {
		uni_engine.profile = "uni2";
	}

	dir_layout = apt_default_dir_layout_create(UNIMRCP_DIR_LOCATION,pool);
	/* Create singleton logger */
	apt_log_instance_create(uni_engine.log_output, uni_engine.log_level, pool);
	if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) {
#ifdef OPAQUE_DIR_LAYOUT
		const char *log_dir_path = apt_dir_layout_path_get(dir_layout,APT_LAYOUT_LOG_DIR);
#else
		const char *log_dir_path = dir_layout->log_dir_path;
#endif
		/* Open the log file */
		apt_log_file_open(log_dir_path,"astuni",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool);
	}

	uni_engine.client = unimrcp_client_create(dir_layout);
	if(uni_engine.client) {
		uni_engine.application = mrcp_application_create(
										uni_message_handler,
										&uni_engine,
										pool);
		if(uni_engine.application) {
			mrcp_client_application_register(
							uni_engine.client,
							uni_engine.application,
							"ASTMRCP");
		}
	}

	if(!uni_engine.client || !uni_engine.application) {
		ast_log(LOG_ERROR, "Failed to initialize MRCP client\n");
		uni_engine_unload();
		return FALSE;
	}

	return TRUE;
}
Beispiel #6
0
bool UmcConsole::Run(int argc, const char * const *argv)
{
	apr_pool_t* pool = NULL;
	apt_dir_layout_t* pDirLayout = NULL;
	const char *logConfPath;

	/* APR global initialization */
	if(apr_initialize() != APR_SUCCESS) 
	{
		apr_terminate();
		return false;
	}

	/* create APR pool */
	pool = apt_pool_create();
	if(!pool) 
	{
		apr_terminate();
		return false;
	}

	/* load options */
	if(!LoadOptions(argc,argv,pool))
	{
		apr_pool_destroy(pool);
		apr_terminate();
		return false;
	}

	if(m_Options.m_DirLayoutConf)
	{
		/* create and load directories layout from the configuration file */
		pDirLayout = apt_dir_layout_create(pool);
		if(pDirLayout)
			apt_dir_layout_load(pDirLayout,m_Options.m_DirLayoutConf,pool);
	}
	else
	{
		/* create default directories layout */
		pDirLayout = apt_default_dir_layout_create(m_Options.m_RootDirPath,pool);
	}

	if(!pDirLayout)
	{
		printf("Failed to Create Directories Layout\n");
		apr_pool_destroy(pool);
		apr_terminate();
		return false;
	}

	/* get path to logger configuration file */
	logConfPath = apt_confdir_filepath_get(pDirLayout,"logger.xml",pool);
	/* create and load singleton logger */
	apt_log_instance_load(logConfPath,pool);

	if(m_Options.m_LogPriority) 
	{
		/* override the log priority, if specified in command line */
		apt_log_priority_set((apt_log_priority_e)atoi(m_Options.m_LogPriority));
	}
	if(m_Options.m_LogOutput) 
	{
		/* override the log output mode, if specified in command line */
		apt_log_output_mode_set((apt_log_output_e)atoi(m_Options.m_LogOutput));
	}

	if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) 
	{
		/* open the log file */
		const char *logDirPath = apt_dir_layout_path_get(pDirLayout,APT_LAYOUT_LOG_DIR);
		apt_log_file_open(logDirPath,"unimrcpclient",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,FALSE,pool);
	}

	/* create demo framework */
	if(m_pFramework->Create(pDirLayout,pool))
	{
		/* run command line  */
		RunCmdLine();
		/* destroy demo framework */
		m_pFramework->Destroy();
	}

	/* destroy singleton logger */
	apt_log_instance_destroy();
	/* destroy APR pool */
	apr_pool_destroy(pool);
	/* APR global termination */
	apr_terminate();
	return true;
}