/** Create UniRTSP Signaling Agent */ MRCP_DECLARE(mrcp_sig_agent_t*) mrcp_unirtsp_server_agent_create(const char *id, rtsp_server_config_t *config, apr_pool_t *pool) { apt_task_t *task; mrcp_unirtsp_agent_t *agent; agent = apr_palloc(pool,sizeof(mrcp_unirtsp_agent_t)); agent->sig_agent = mrcp_signaling_agent_create(id,agent,MRCP_VERSION_1,pool); agent->config = config; if(rtsp_config_validate(agent,config,pool) == FALSE) { return NULL; } agent->rtsp_server = rtsp_server_create( config->local_ip, config->local_port, config->max_connection_count, agent, &session_request_vtable, pool); if(!agent->rtsp_server) { return NULL; } task = rtsp_server_task_get(agent->rtsp_server); apt_task_name_set(task,id); agent->sig_agent->task = task; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create UniRTSP Agent [%s] %s:%hu [%"APR_SIZE_T_FMT"]", id, config->local_ip, config->local_port, config->max_connection_count); return agent->sig_agent; }
/** Create MRCP client instance */ MRCP_DECLARE(mrcp_client_t*) mrcp_client_create(apt_dir_layout_t *dir_layout) { mrcp_client_t *client; apr_pool_t *pool; apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; pool = apt_pool_create(); if(!pool) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "CLIENT_TASK_NAME); client = apr_palloc(pool,sizeof(mrcp_client_t)); client->pool = pool; client->dir_layout = dir_layout; client->resource_factory = NULL; client->media_engine_table = NULL; client->rtp_factory_table = NULL; client->sig_agent_table = NULL; client->sig_settings_table = NULL; client->cnt_agent_table = NULL; client->rtp_settings_table = NULL; client->profile_table = NULL; client->app_table = NULL; client->session_table = NULL; client->cnt_msg_pool = NULL; msg_pool = apt_task_msg_pool_create_dynamic(0,pool); client->task = apt_consumer_task_create(client,msg_pool,pool); if(!client->task) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Client Task"); return NULL; } task = apt_consumer_task_base_get(client->task); apt_task_name_set(task,CLIENT_TASK_NAME); vtable = apt_task_vtable_get(task); if(vtable) { vtable->process_msg = mrcp_client_msg_process; vtable->on_start_complete = mrcp_client_on_start_complete; vtable->on_terminate_complete = mrcp_client_on_terminate_complete; } client->media_engine_table = apr_hash_make(client->pool); client->rtp_factory_table = apr_hash_make(client->pool); client->sig_agent_table = apr_hash_make(client->pool); client->sig_settings_table = apr_hash_make(client->pool); client->cnt_agent_table = apr_hash_make(client->pool); client->rtp_settings_table = apr_hash_make(client->pool); client->profile_table = apr_hash_make(client->pool); client->app_table = apr_hash_make(client->pool); client->session_table = apr_hash_make(client->pool); client->on_start_complete = NULL; client->sync_start_object = NULL; client->sync_start_mutex = NULL; return client; }
/** Create demo verification engine */ MRCP_PLUGIN_DECLARE(mrcp_engine_t*) mrcp_plugin_create(apr_pool_t *pool) { demo_verifier_engine_t *demo_engine = apr_palloc(pool,sizeof(demo_verifier_engine_t)); apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(demo_verifier_msg_t),pool); demo_engine->task = apt_consumer_task_create(demo_engine,msg_pool,pool); if(!demo_engine->task) { return NULL; } task = apt_consumer_task_base_get(demo_engine->task); apt_task_name_set(task,VERIFIER_ENGINE_TASK_NAME); vtable = apt_task_vtable_get(task); if(vtable) { vtable->process_msg = demo_verifier_msg_process; } /* create engine base */ return mrcp_engine_create( MRCP_VERIFIER_RESOURCE, /* MRCP resource identifier */ demo_engine, /* object to associate */ &engine_vtable, /* virtual methods table of engine */ pool); /* pool to allocate memory from */ }
/** Create connection agent. */ MRCP_DECLARE(mrcp_connection_agent_t*) mrcp_client_connection_agent_create( apr_size_t max_connection_count, apt_bool_t offer_new_connection, apr_pool_t *pool) { apt_task_vtable_t *vtable; mrcp_connection_agent_t *agent; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "MRCPV2_CONNECTION_TASK_NAME" [%d]",max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->pollset = NULL; agent->max_connection_count = max_connection_count; agent->offer_new_connection = offer_new_connection; agent->task = apt_task_create(agent,NULL,pool); if(!agent->task) { return NULL; } apt_task_name_set(agent->task,MRCPV2_CONNECTION_TASK_NAME); vtable = apt_task_vtable_get(agent->task); if(vtable) { vtable->run = mrcp_client_agent_task_run; vtable->terminate = mrcp_client_agent_task_terminate; vtable->destroy = mrcp_client_agent_task_on_destroy; } agent->connection_list = apt_list_create(pool); agent->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&agent->guard,APR_THREAD_MUTEX_UNNESTED,pool); return agent; }
/** Create Sofia-SIP Signaling Agent */ MRCP_DECLARE(mrcp_sig_agent_t*) mrcp_sofiasip_server_agent_create(mrcp_sofia_server_config_t *config, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; mrcp_sofia_agent_t *sofia_agent; sofia_agent = apr_palloc(pool,sizeof(mrcp_sofia_agent_t)); sofia_agent->sig_agent = mrcp_signaling_agent_create(sofia_agent,MRCP_VERSION_2,pool); sofia_agent->config = config; sofia_agent->root = NULL; sofia_agent->nua = NULL; if(mrcp_sofia_config_validate(sofia_agent,config,pool) == FALSE) { return NULL; } task = apt_task_create(sofia_agent,NULL,pool); if(!task) { return NULL; } apt_task_name_set(task,SOFIA_TASK_NAME); vtable = apt_task_vtable_get(task); if(vtable) { vtable->on_pre_run = mrcp_sofia_task_initialize; vtable->run = mrcp_sofia_task_run; vtable->terminate = mrcp_sofia_task_terminate; } sofia_agent->sig_agent->task = task; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "SOFIA_TASK_NAME" ["SOFIA_SIP_VERSION"] %s:%hu %s", config->local_ip, config->local_port, config->transport ? config->transport : ""); return sofia_agent->sig_agent; }
/** Create Sofia-SIP Signaling Agent */ MRCP_DECLARE(mrcp_sig_agent_t*) mrcp_sofiasip_client_agent_create(const char *id, mrcp_sofia_client_config_t *config, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; mrcp_sofia_agent_t *sofia_agent; sofia_agent = apr_palloc(pool,sizeof(mrcp_sofia_agent_t)); sofia_agent->sig_agent = mrcp_signaling_agent_create(id,sofia_agent,MRCP_VERSION_2,pool); sofia_agent->sig_agent->create_client_session = mrcp_sofia_session_create; sofia_agent->root = NULL; sofia_agent->nua = NULL; if(mrcp_sofia_config_validate(sofia_agent,config,pool) == FALSE) { return NULL; } task = apt_task_create(sofia_agent,NULL,pool); if(!task) { return NULL; } apt_task_name_set(task,id); vtable = apt_task_vtable_get(task); if(vtable) { vtable->on_pre_run = mrcp_sofia_task_initialize; vtable->run = mrcp_sofia_task_run; vtable->terminate = mrcp_sofia_task_terminate; } sofia_agent->sig_agent->task = task; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SofiaSIP Agent [%s] ["SOFIA_SIP_VERSION"] %s", id,sofia_agent->sip_bind_str); return sofia_agent->sig_agent; }
/** Create connection agent */ MRCP_DECLARE(mrcp_connection_agent_t*) mrcp_server_connection_agent_create( const char *listen_ip, apr_port_t listen_port, apr_size_t max_connection_count, apt_bool_t force_new_connection, apr_pool_t *pool) { apt_task_vtable_t *vtable; mrcp_connection_agent_t *agent; if(!listen_ip) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "MRCPV2_CONNECTION_TASK_NAME" %s:%hu [%"APR_SIZE_T_FMT"]", listen_ip,listen_port,max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->sockaddr = NULL; agent->listen_sock = NULL; agent->pollset = NULL; agent->max_connection_count = max_connection_count; agent->force_new_connection = force_new_connection; apr_sockaddr_info_get(&agent->sockaddr,listen_ip,APR_INET,listen_port,0,agent->pool); if(!agent->sockaddr) { return NULL; } agent->task = apt_task_create(agent,NULL,pool); if(!agent->task) { return NULL; } apt_task_name_set(agent->task,MRCPV2_CONNECTION_TASK_NAME); vtable = apt_task_vtable_get(agent->task); if(vtable) { vtable->run = mrcp_server_agent_task_run; vtable->terminate = mrcp_server_agent_task_terminate; vtable->destroy = mrcp_server_agent_task_on_destroy; } apt_task_auto_ready_set(agent->task,FALSE); agent->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&agent->guard,APR_THREAD_MUTEX_UNNESTED,pool); agent->connection_list = NULL; agent->null_connection = NULL; return agent; }
/** Create RTSP client */ RTSP_DECLARE(rtsp_client_t*) rtsp_client_create( const char *id, apr_size_t max_connection_count, apr_size_t request_timeout, void *obj, const rtsp_client_vtable_t *handler, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; rtsp_client_t *client; apt_log(RTSP_LOG_MARK,APT_PRIO_NOTICE,"Create RTSP Client [%s] [%"APR_SIZE_T_FMT"]", id, max_connection_count); client = apr_palloc(pool,sizeof(rtsp_client_t)); client->pool = pool; client->obj = obj; client->vtable = handler; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(task_msg_data_t),pool); client->task = apt_poller_task_create( max_connection_count, rtsp_client_poller_signal_process, client, msg_pool, pool); if(!client->task) { return NULL; } task = apt_poller_task_base_get(client->task); if(task) { apt_task_name_set(task,id); } vtable = apt_poller_task_vtable_get(client->task); if(vtable) { vtable->process_msg = rtsp_client_task_msg_process; } APR_RING_INIT(&client->connection_list, rtsp_client_connection_t, link); client->request_timeout = (apr_uint32_t)request_timeout; return client; }
/** Create connection agent. */ MRCP_DECLARE(mrcp_connection_agent_t*) mrcp_client_connection_agent_create( const char *id, apr_size_t max_connection_count, apt_bool_t offer_new_connection, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; mrcp_connection_agent_t *agent; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create MRCPv2 Agent [%s] [%"APR_SIZE_T_FMT"]", id, max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->request_timeout = 0; agent->offer_new_connection = offer_new_connection; agent->rx_buffer_size = MRCP_STREAM_BUFFER_SIZE; agent->tx_buffer_size = MRCP_STREAM_BUFFER_SIZE; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(connection_task_msg_t),pool); agent->task = apt_poller_task_create( max_connection_count, mrcp_client_poller_signal_process, agent, msg_pool, pool); if(!agent->task) { return NULL; } task = apt_poller_task_base_get(agent->task); if(task) { apt_task_name_set(task,id); } vtable = apt_poller_task_vtable_get(agent->task); if(vtable) { vtable->process_msg = mrcp_client_agent_msg_process; } APR_RING_INIT(&agent->connection_list, mrcp_connection_t, link); return agent; }
MPF_DECLARE(mpf_engine_t*) mpf_engine_create(const char *id, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; mpf_engine_t *engine = apr_palloc(pool,sizeof(mpf_engine_t)); engine->pool = pool; engine->request_queue = NULL; engine->context_factory = NULL; engine->codec_manager = NULL; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mpf_message_container_t),pool); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Media Engine [%s]",id); engine->task = apt_task_create(engine,msg_pool,pool); if(!engine->task) { return NULL; } apt_task_name_set(engine->task,id); vtable = apt_task_vtable_get(engine->task); if(vtable) { vtable->destroy = mpf_engine_destroy; vtable->start = mpf_engine_start; vtable->terminate = mpf_engine_terminate; vtable->signal_msg = mpf_engine_msg_signal; vtable->process_msg = mpf_engine_msg_process; } engine->task_msg_type = TASK_MSG_USER; engine->context_factory = mpf_context_factory_create(engine->pool); engine->request_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&engine->request_queue_guard,APR_THREAD_MUTEX_UNNESTED,engine->pool); engine->scheduler = mpf_scheduler_create(engine->pool); mpf_scheduler_media_clock_set(engine->scheduler,CODEC_FRAME_TIME_BASE,mpf_engine_main,engine); engine->timer_queue = apt_timer_queue_create(engine->pool); mpf_scheduler_timer_clock_set(engine->scheduler,MPF_TIMER_RESOLUTION,mpf_engine_timer_proc,engine); return engine; }
static apt_bool_t demo_framework_consumer_task_create(demo_framework_t *framework) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(framework_task_data_t),framework->pool); framework->task = apt_consumer_task_create(framework,msg_pool,framework->pool); if(!framework->task) { return FALSE; } task = apt_consumer_task_base_get(framework->task); apt_task_name_set(task,FRAMEWORK_TASK_NAME); vtable = apt_consumer_task_vtable_get(framework->task); if(vtable) { vtable->process_msg = demo_framework_msg_process; vtable->on_start_complete = demo_framework_on_start_complete; } return TRUE; }
bool UmcFramework::CreateTask() { apt_task_t* pTask; apt_task_vtable_t* pVtable; apt_task_msg_pool_t* pMsgPool; pMsgPool = apt_task_msg_pool_create_dynamic(sizeof(UmcTaskMsg),m_pPool); m_pTask = apt_consumer_task_create(this,pMsgPool,m_pPool); if(!m_pTask) return false; pTask = apt_consumer_task_base_get(m_pTask); apt_task_name_set(pTask,"Framework Agent"); pVtable = apt_consumer_task_vtable_get(m_pTask); if(pVtable) { pVtable->process_msg = UmcProcessMsg; pVtable->on_start_complete = UmcOnStartComplete; pVtable->on_terminate_complete = UmcOnTerminateComplete; } apt_task_start(pTask); return true; }
/** Create RTSP server */ RTSP_DECLARE(rtsp_server_t*) rtsp_server_create( const char *id, const char *listen_ip, apr_port_t listen_port, apr_size_t max_connection_count, void *obj, const rtsp_server_vtable_t *handler, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; rtsp_server_t *server; if(!listen_ip) { return NULL; } apt_log(RTSP_LOG_MARK,APT_PRIO_NOTICE,"Create RTSP Server [%s] %s:%hu [%"APR_SIZE_T_FMT"]", id, listen_ip, listen_port, max_connection_count); server = apr_palloc(pool,sizeof(rtsp_server_t)); server->pool = pool; server->obj = obj; server->vtable = handler; server->listen_sock = NULL; server->sockaddr = NULL; apr_sockaddr_info_get(&server->sockaddr,listen_ip,APR_INET,listen_port,0,pool); if(!server->sockaddr) { return NULL; } msg_pool = apt_task_msg_pool_create_dynamic(sizeof(task_msg_data_t),pool); server->task = apt_poller_task_create( max_connection_count + 1, rtsp_server_poller_signal_process, server, msg_pool, pool); if(!server->task) { return NULL; } task = apt_poller_task_base_get(server->task); if(task) { apt_task_name_set(task,id); } vtable = apt_poller_task_vtable_get(server->task); if(vtable) { vtable->destroy = rtsp_server_on_destroy; vtable->process_msg = rtsp_server_task_msg_process; } APR_RING_INIT(&server->connection_list, rtsp_server_connection_t, link); if(rtsp_server_listening_socket_create(server) != TRUE) { apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Listening Socket [%s] %s:%hu", id, listen_ip, listen_port); } return server; }
/** Create connection agent */ MRCP_DECLARE(mrcp_connection_agent_t*) mrcp_server_connection_agent_create( const char *id, const char *listen_ip, apr_port_t listen_port, apr_size_t max_connection_count, apt_bool_t force_new_connection, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; mrcp_connection_agent_t *agent; if(!listen_ip) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create MRCPv2 Agent [%s] %s:%hu [%"APR_SIZE_T_FMT"]", id,listen_ip,listen_port,max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->sockaddr = NULL; agent->listen_sock = NULL; agent->force_new_connection = force_new_connection; agent->rx_buffer_size = MRCP_STREAM_BUFFER_SIZE; agent->tx_buffer_size = MRCP_STREAM_BUFFER_SIZE; apr_sockaddr_info_get(&agent->sockaddr,listen_ip,APR_INET,listen_port,0,pool); if(!agent->sockaddr) { return NULL; } msg_pool = apt_task_msg_pool_create_dynamic(sizeof(connection_task_msg_t),pool); agent->task = apt_poller_task_create( max_connection_count + 1, mrcp_server_poller_signal_process, agent, msg_pool, pool); if(!agent->task) { return NULL; } task = apt_poller_task_base_get(agent->task); if(task) { apt_task_name_set(task,id); } vtable = apt_poller_task_vtable_get(agent->task); if(vtable) { vtable->destroy = mrcp_server_agent_on_destroy; vtable->process_msg = mrcp_server_agent_msg_process; } APR_RING_INIT(&agent->connection_list, mrcp_connection_t, link); agent->pending_channel_table = apr_hash_make(pool); if(mrcp_server_agent_listening_socket_create(agent) != TRUE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Listening Socket [%s] %s:%hu", id, listen_ip, listen_port); } return agent; }
/** Create MRCP server instance */ MRCP_DECLARE(mrcp_server_t*) mrcp_server_create(apt_dir_layout_t *dir_layout) { mrcp_server_t *server; apr_pool_t *pool; apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; pool = apt_pool_create(); if(!pool) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "SERVER_TASK_NAME); server = apr_palloc(pool,sizeof(mrcp_server_t)); server->pool = pool; server->dir_layout = dir_layout; server->resource_factory = NULL; server->engine_factory = NULL; server->engine_loader = NULL; server->media_engine_table = NULL; server->rtp_factory_table = NULL; server->sig_agent_table = NULL; server->cnt_agent_table = NULL; server->rtp_settings_table = NULL; server->profile_table = NULL; server->session_table = NULL; server->connection_msg_pool = NULL; server->engine_msg_pool = NULL; msg_pool = apt_task_msg_pool_create_dynamic(0,pool); server->task = apt_consumer_task_create(server,msg_pool,pool); if(!server->task) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Server Task"); return NULL; } task = apt_consumer_task_base_get(server->task); apt_task_name_set(task,SERVER_TASK_NAME); vtable = apt_task_vtable_get(task); if(vtable) { vtable->process_msg = mrcp_server_msg_process; vtable->on_start_request = mrcp_server_on_start_request; vtable->on_terminate_request = mrcp_server_on_terminate_request; vtable->on_start_complete = mrcp_server_on_start_complete; vtable->on_terminate_complete = mrcp_server_on_terminate_complete; } server->engine_factory = mrcp_engine_factory_create(server->pool); server->engine_loader = mrcp_engine_loader_create(server->pool); server->media_engine_table = apr_hash_make(server->pool); server->rtp_factory_table = apr_hash_make(server->pool); server->rtp_settings_table = apr_hash_make(server->pool); server->sig_agent_table = apr_hash_make(server->pool); server->cnt_agent_table = apr_hash_make(server->pool); server->profile_table = apr_hash_make(server->pool); server->session_table = apr_hash_make(server->pool); return server; }
/** Run MPF test suite */ static apt_bool_t mpf_test_run(apt_test_suite_t *suite, int argc, const char * const *argv) { mpf_suite_agent_t *agent; mpf_codec_manager_t *codec_manager; mpf_rtp_config_t *rtp_config; mpf_rtp_settings_t *rtp_settings; mpf_engine_t *engine; apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; agent = apr_palloc(suite->pool,sizeof(mpf_suite_agent_t)); agent->dir_layout = apt_default_dir_layout_create(NULL,suite->pool); engine = mpf_engine_create("MPF-Engine",suite->pool); if(!engine) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create MPF Engine"); return FALSE; } codec_manager = mpf_engine_codec_manager_create(suite->pool); if(!codec_manager) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Codec Manager"); return FALSE; } mpf_engine_codec_manager_register(engine,codec_manager); agent->engine = engine; rtp_config = mpf_rtp_config_alloc(suite->pool); apt_string_set(&rtp_config->ip,"127.0.0.1"); rtp_config->rtp_port_min = 5000; rtp_config->rtp_port_max = 6000; agent->rtp_config = rtp_config; rtp_settings = mpf_rtp_settings_alloc(suite->pool); rtp_settings->ptime = 20; rtp_settings->jb_config.adaptive = 1; rtp_settings->jb_config.time_skew_detection = 1; rtp_settings->jb_config.min_playout_delay = 0; rtp_settings->jb_config.initial_playout_delay = 50; rtp_settings->jb_config.max_playout_delay = 800; mpf_codec_manager_codec_list_load(codec_manager,&rtp_settings->codec_list,"PCMU",suite->pool); agent->rtp_settings = rtp_settings; agent->rtp_termination_factory = mpf_rtp_termination_factory_create(rtp_config,suite->pool); agent->file_termination_factory = mpf_file_termination_factory_create(suite->pool); agent->rx_session = NULL; agent->tx_session = NULL; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mpf_message_t),suite->pool); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Consumer Task"); agent->consumer_task = apt_consumer_task_create(agent,msg_pool,suite->pool); if(!agent->consumer_task) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Consumer Task"); return FALSE; } task = apt_consumer_task_base_get(agent->consumer_task); apt_task_name_set(task,"MPF-Tester"); vtable = apt_task_vtable_get(task); if(vtable) { vtable->process_msg = mpf_suite_task_msg_process; vtable->on_start_complete = mpf_suite_on_start_complete; vtable->on_terminate_complete = mpf_suite_on_terminate_complete; } apt_task_add(task,mpf_task_get(engine)); apr_thread_mutex_create(&agent->wait_object_mutex,APR_THREAD_MUTEX_UNNESTED,suite->pool); apr_thread_cond_create(&agent->wait_object,suite->pool); if(apt_task_start(task) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Task"); apt_task_destroy(task); return FALSE; } apr_thread_mutex_lock(agent->wait_object_mutex); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Wait for Task to Complete"); apr_thread_cond_wait(agent->wait_object,agent->wait_object_mutex); apr_thread_mutex_unlock(agent->wait_object_mutex); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Terminate Task [wait till complete]"); apt_task_terminate(task,TRUE); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Task"); apt_task_destroy(task); apr_thread_cond_destroy(agent->wait_object); apr_thread_mutex_destroy(agent->wait_object_mutex); return TRUE; }
/** Create connection agent */ MRCP_DECLARE(mrcp_connection_agent_t*) mrcp_server_connection_agent_create( const char *listen_ip, apr_port_t listen_port, apr_size_t max_connection_count, apt_bool_t force_new_connection, apr_pool_t *pool) { apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; mrcp_connection_agent_t *agent; if(!listen_ip) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create "MRCPV2_CONNECTION_TASK_NAME" %s:%hu [%"APR_SIZE_T_FMT"]", listen_ip,listen_port,max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->sockaddr = NULL; agent->listen_sock = NULL; agent->force_new_connection = force_new_connection; agent->rx_buffer_size = MRCP_STREAM_BUFFER_SIZE; agent->tx_buffer_size = MRCP_STREAM_BUFFER_SIZE; apr_sockaddr_info_get(&agent->sockaddr,listen_ip,APR_INET,listen_port,0,agent->pool); if(!agent->sockaddr) { return NULL; } msg_pool = apt_task_msg_pool_create_dynamic(sizeof(connection_task_msg_t),pool); agent->task = apt_poller_task_create( max_connection_count + 1, mrcp_server_poller_signal_process, agent, msg_pool, pool); if(!agent->task) { return NULL; } task = apt_poller_task_base_get(agent->task); if(task) { apt_task_name_set(task,MRCPV2_CONNECTION_TASK_NAME); } vtable = apt_poller_task_vtable_get(agent->task); if(vtable) { vtable->destroy = mrcp_server_agent_on_destroy; vtable->process_msg = mrcp_server_agent_msg_process; } agent->connection_list = NULL; agent->null_connection = NULL; if(mrcp_server_agent_listening_socket_create(agent) == TRUE) { /* add listening socket to pollset */ apt_pollset_t *pollset = apt_poller_task_pollset_get(agent->task); memset(&agent->listen_sock_pfd,0,sizeof(apr_pollfd_t)); agent->listen_sock_pfd.desc_type = APR_POLL_SOCKET; agent->listen_sock_pfd.reqevents = APR_POLLIN; agent->listen_sock_pfd.desc.s = agent->listen_sock; agent->listen_sock_pfd.client_data = agent->listen_sock; if(apt_pollset_add(pollset, &agent->listen_sock_pfd) != TRUE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Add Listening Socket to Pollset"); mrcp_server_agent_listening_socket_destroy(agent); } } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Listening Socket"); } return agent; }