Esempio n. 1
0
static apt_bool_t demo_framework_options_load(const char **conf_dir_path, int argc, const char * const *argv, apr_pool_t *pool)
{
	apr_status_t rv;
	apr_getopt_t *opt;
	int optch;
	const char *optarg;

	static const apr_getopt_option_t opt_option[] = {
		/* long-option, short-option, has-arg flag, description */
		{ "conf-dir",     'c', TRUE,  "path to config dir" },/* -c arg or --conf-dir arg */
		{ "log",          'l', TRUE,  "log priority" },      /* -l arg or --log arg */
		{ "help",         'h', FALSE, "show help" },         /* -h or --help */
		{ NULL, 0, 0, NULL },                                /* end */
	};

	/* set the default log level */
	apt_log_priority_set(APT_PRIO_INFO);

	rv = apr_getopt_init(&opt, pool , argc, argv);
	if(rv != APR_SUCCESS) {
		return FALSE;
	}

	while((rv = apr_getopt_long(opt, opt_option, &optch, &optarg)) == APR_SUCCESS) {
		switch(optch) {
			case 'c':
				if(conf_dir_path) {
					*conf_dir_path = optarg;
				}
				break;
			case 'l':
				if(optarg) {
					apt_log_priority_set(atoi(optarg));
				}
				break;
			case 'h':
				usage();
				return FALSE;
		}
	}

	if(rv != APR_EOF) {
		usage();
		return FALSE;
	}

	return TRUE;
}
Esempio n. 2
0
static apt_bool_t cmdline_process(char *cmdline)
{
	apt_bool_t running = TRUE;
	char *name;
	char *last;
	name = apr_strtok(cmdline, " ", &last);

	if(strcasecmp(name,"loglevel") == 0) {
		char *priority = apr_strtok(NULL, " ", &last);
		if(priority) {
			apt_log_priority_set(atol(priority));
		}
	}
	else if(strcasecmp(name,"exit") == 0 || strcmp(name,"quit") == 0) {
		running = FALSE;
	}
	else if(strcasecmp(name,"help") == 0) {
		printf("usage:\n");
		printf("- loglevel [level] (set loglevel, one of 0,1...7)\n");
		printf("- quit, exit\n");
	}
	else {
		printf("unknown command: %s (input help for usage)\n",name);
	}
	return running;
}
Esempio n. 3
0
static apt_bool_t demo_framework_cmdline_process(demo_framework_t *framework, char *cmdline)
{
	apt_bool_t running = TRUE;
	char *name;
	char *last;
	name = apr_strtok(cmdline, " ", &last);

	if(strcasecmp(name,"run") == 0) {
		char *app_name = apr_strtok(NULL, " ", &last);
		if(app_name) {
			char *profile_name = apr_strtok(NULL, " ", &last);
			if(!profile_name) {
				profile_name = "uni2";
			}
			demo_framework_app_run(framework,app_name,profile_name);
		}
	}
	else if(strcasecmp(name,"loglevel") == 0) {
		char *priority = apr_strtok(NULL, " ", &last);
		if(priority) {
			apt_log_priority_set(atol(priority));
		}
	}
	else if(strcasecmp(name,"exit") == 0 || strcmp(name,"quit") == 0) {
		running = FALSE;
	}
	else if(strcasecmp(name,"help") == 0) {
		printf("usage:\n"
		       "\n- run [app_name] [profile_name] (run demo application)\n"
			   "       app_name is one of 'synth', 'recog', 'bypass', 'discover'\n"
			   "       profile_name is one of 'uni2', 'uni1', ...\n"
			   "\n       examples: \n"
			   "           run synth\n"
			   "           run recog\n"
			   "           run synth uni1\n"
			   "           run recog uni1\n"
		       "\n- loglevel [level] (set loglevel, one of 0,1...7)\n"
		       "\n- quit, exit\n");
	}
	else {
		printf("unknown command: %s (input help for usage)\n",name);
	}
	return running;
}
Esempio n. 4
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 {
Esempio n. 5
0
/** Set log priority */
ASR_CLIENT_DECLARE(apt_bool_t) asr_engine_log_priority_set(apt_log_priority_e log_priority)
{
	return apt_log_priority_set(log_priority);
}
Esempio n. 6
0
AST_COMPAT_STATIC int load_module(void)
{
	int res = 0;
	apr_hash_index_t *hi;

	if (apr_initialized == 0) {
		if (apr_initialize() != APR_SUCCESS) {
			ast_log(LOG_ERROR, "Unable to initialize APR\n");
			apr_terminate();
			apr_initialized = 0;
			return AST_MODULE_LOAD_DECLINE;
		} else {
			ast_log(LOG_DEBUG, "APR initialized\n");
			apr_initialized = 1;
		}
	}

	/* Initialize globals. */
	if (globals_init() != 0) {
		ast_log(LOG_DEBUG, "Unable to initialize globals\n");
		apr_terminate();
		apr_initialized = 0;
		return AST_MODULE_LOAD_DECLINE;
	}

	/* Load the configuration file mrcp.conf. */
#if AST_VERSION_AT_LEAST(1,6,0)
	struct ast_flags config_flags = { 0 };
	struct ast_config *cfg = ast_config_load(MRCP_CONFIG, config_flags);
#else
	struct ast_config *cfg = ast_config_load(MRCP_CONFIG);
#endif
	if (!cfg) {
		ast_log(LOG_WARNING, "No such configuration file %s\n", MRCP_CONFIG);
		globals_destroy();
		apr_terminate();
		apr_initialized = 0;
		return AST_MODULE_LOAD_DECLINE;
	}

	if (load_mrcp_config(cfg) != 0) {
		ast_log(LOG_DEBUG, "Unable to load configuration\n");
		globals_destroy();
		apr_terminate();
		apr_initialized = 0;
		return AST_MODULE_LOAD_DECLINE;
	}

	/* Link UniMRCP logs to Asterisk. */
	ast_log(LOG_NOTICE, "UniMRCP log level = %s\n", globals.unimrcp_log_level);
	apt_log_priority_e log_priority = apt_log_priority_translate(globals.unimrcp_log_level);
	if (apt_log_instance_create(APT_LOG_OUTPUT_NONE, log_priority, globals.pool) == FALSE) {
		/* Already created. */
		apt_log_priority_set(log_priority);
	}
	apt_log_ext_handler_set(unimrcp_log);

	/* Create the MRCP client. */
	if ((globals.mrcp_client = mod_unimrcp_client_create(globals.pool)) == NULL) {
		ast_log(LOG_ERROR, "Failed to create MRCP client\n");
		if (!apt_log_instance_destroy())
			ast_log(LOG_WARNING, "Unable to destroy UniMRCP logger instance\n");
		globals_destroy();
		apr_terminate();
		apr_initialized = 0;
		return AST_MODULE_LOAD_DECLINE;
	}
	
	/* Load the applications. */
	load_mrcpsynth_app();
	load_mrcprecog_app();
	load_synthandrecog_app();

	/* Start the client stack. */
	if (!mrcp_client_start(globals.mrcp_client)) {
		ast_log(LOG_ERROR, "Failed to start MRCP client stack processing\n");
		if (!mrcp_client_destroy(globals.mrcp_client))
			ast_log(LOG_WARNING, "Unable to destroy MRCP client stack\n");
		else
			ast_log(LOG_DEBUG, "MRCP client stack destroyed\n");
		globals.mrcp_client = NULL;
		if (!apt_log_instance_destroy())
			ast_log(LOG_WARNING, "Unable to destroy UniMRCP logger instance\n");
		globals_destroy();
		apr_terminate();
		apr_initialized = 0;
		return AST_MODULE_LOAD_DECLINE;
	}

	/* Register the applications. */
	for (hi = apr_hash_first(NULL, globals.apps); hi; hi = apr_hash_next(hi)) {
		const void *key;
		void *val;
		const char *name;
		ast_mrcp_application_t *application;

		apr_hash_this(hi, &key, NULL, &val);

		name = (const char *) key;
		application = (ast_mrcp_application_t *) val;

#if AST_VERSION_AT_LEAST(1,6,2)
		res |= ast_register_application_xml(name, application->exec);
#else 
		res |= ast_register_application(name, application->exec, application->synopsis, application->description);
#endif
	}
	
	return res;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
0
bool UmcConsole::ProcessCmdLine(char* pCmdLine)
{
	bool running = true;
	char *name;
	char *last;
	name = apr_strtok(pCmdLine, " ", &last);

	if(strcasecmp(name,"run") == 0)
	{
		char* pScenarioName = apr_strtok(NULL, " ", &last);
		if(pScenarioName) 
		{
			const char* pProfileName = apr_strtok(NULL, " ", &last);
			if(!pProfileName) 
			{
				pProfileName = "uni2";
			}
			m_pFramework->RunSession(pScenarioName,pProfileName);
		}
	}
	else if(strcasecmp(name,"kill") == 0)
	{
		char* pID = apr_strtok(NULL, " ", &last);
		if(pID) 
		{
			m_pFramework->KillSession(pID);
		}
	}
	else if(strcasecmp(name,"stop") == 0)
	{
		char* pID = apr_strtok(NULL, " ", &last);
		if(pID) 
		{
			m_pFramework->StopSession(pID);
		}
	}
	else if(strcasecmp(name,"show") == 0)
	{
		char* pWhat = apr_strtok(NULL, " ", &last);
		if(pWhat) 
		{
			if(strcasecmp(pWhat,"sessions") == 0)
				m_pFramework->ShowSessions();
			else if(strcasecmp(pWhat,"scenarios") == 0)
				m_pFramework->ShowScenarios();
		}
	}
	else if(strcasecmp(name,"loglevel") == 0) 
	{
		char* pPriority = apr_strtok(NULL, " ", &last);
		if(pPriority) 
		{
			apt_log_priority_set((apt_log_priority_e)atol(pPriority));
		}
	}
	else if(strcasecmp(name,"exit") == 0 || strcmp(name,"quit") == 0) 
	{
		running = false;
	}
	else if(strcasecmp(name,"help") == 0) 
	{
		printf("usage:\n"
		       "\n- run [scenario] [profile] (run new session)\n"
			   "       scenario is one of 'synth', 'recog', ... (use 'show scenarios')\n"
			   "       profile is one of 'uni2', 'uni1', ... (see unimrcpclient.xml)\n"
			   "\n       examples: \n"
			   "           run synth\n"
			   "           run recog\n"
			   "           run synth uni1\n"
			   "           run recog uni1\n"
		       "\n- kill [id] (kill session)\n"
			   "       id is a session identifier: 1, 2, ... (use 'show sessions')\n"
			   "\n       example: \n"
			   "           kill 1\n"
		       "\n- show [what] (show either available scenarios or in-progress sessions)\n"
			   "\n       examples: \n"
			   "           show scenarios\n"
			   "           show sessions\n"
		       "\n- loglevel [level] (set loglevel, one of 0,1...7)\n"
		       "\n- quit, exit\n");
	}
	else 
	{
		printf("unknown command: %s (input help for usage)\n",name);
	}
	return running;
}