/** 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_PRIO_NOTICE,"Create TCP/MRCPv2 Connection Agent [%d]",max_connection_count); agent = apr_palloc(pool,sizeof(mrcp_connection_agent_t)); agent->pool = pool; agent->control_sockaddr = NULL; agent->control_sock = NULL; agent->pollset = NULL; agent->max_connection_count = max_connection_count; agent->offer_new_connection = offer_new_connection; apr_sockaddr_info_get(&agent->control_sockaddr,"127.0.0.1",APR_INET,7856,0,agent->pool); if(!agent->control_sockaddr) { return NULL; } apt_task_vtable_reset(&vtable); vtable.run = mrcp_client_agent_task_run; vtable.terminate = mrcp_client_agent_task_terminate; agent->task = apt_task_create(agent,&vtable,NULL,pool); if(!agent->task) { return NULL; } agent->connection_list = apt_list_create(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 Sofia-SIP Signaling Agent */ MRCP_DECLARE(mrcp_sig_agent_t*) mrcp_sofiasip_client_agent_create(mrcp_sofia_client_config_t *config, apr_pool_t *pool) { 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->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; } apt_task_vtable_reset(&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 = apt_task_create(sofia_agent,&vtable,NULL,pool); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Sofia SIP ["SOFIA_SIP_VERSION"] Agent %s:%hu -> %s:%hu %s", config->local_ip,config->local_port, config->remote_ip,config->remote_port, config->transport ? config->transport : ""); return sofia_agent->sig_agent; }
/** 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; }
APT_DECLARE(apt_consumer_task_t*) apt_consumer_task_create( void *obj, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_consumer_task_t *consumer_task = apr_palloc(pool,sizeof(apt_consumer_task_t)); consumer_task->obj = obj; consumer_task->msg_queue = NULL; if(apr_queue_create(&consumer_task->msg_queue,1024,pool) != APR_SUCCESS) { return NULL; } consumer_task->base = apt_task_create(consumer_task,msg_pool,pool); if(!consumer_task->base) { return NULL; } vtable = apt_task_vtable_get(consumer_task->base); if(vtable) { vtable->run = apt_consumer_task_run; vtable->signal_msg = apt_consumer_task_msg_signal; } return consumer_task; }
static apt_bool_t task_test_run(apt_test_suite_t *suite, int argc, const char * const *argv) { apt_task_t *task; apt_task_vtable_t *vtable; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Task"); task = apt_task_create(NULL,NULL,suite->pool); if(!task) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Task"); return FALSE; } vtable = apt_task_vtable_get(task); if(vtable) { vtable->run = task_main; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Start Task"); if(apt_task_start(task) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Task"); apt_task_destroy(task); return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Wait for Task to Complete"); apt_task_wait_till_complete(task); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Task"); apt_task_destroy(task); 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_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 poller task */ APT_DECLARE(apt_poller_task_t*) apt_poller_task_create( apr_size_t max_pollset_size, apt_poll_signal_f signal_handler, void *obj, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_poller_task_t *task; if(!signal_handler) { return NULL; } task = apr_palloc(pool,sizeof(apt_poller_task_t)); task->pool = pool; task->obj = obj; task->pollset = NULL; task->signal_handler = signal_handler; task->pollset = apt_pollset_create((apr_uint32_t)max_pollset_size,pool); if(!task->pollset) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset"); return NULL; } task->base = apt_task_create(task,msg_pool,pool); if(!task->base) { apt_pollset_destroy(task->pollset); return NULL; } vtable = apt_task_vtable_get(task->base); if(vtable) { vtable->run = apt_poller_task_run; vtable->destroy = apt_poller_task_on_destroy; vtable->signal_msg = apt_poller_task_msg_signal; } apt_task_auto_ready_set(task->base,FALSE); task->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&task->guard,APR_THREAD_MUTEX_UNNESTED,pool); task->timer_queue = apt_timer_queue_create(pool); return task; }
/** 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; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create TCP/MRCPv2 Connection Agent %s:%hu [%d]",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->control_sockaddr = NULL; agent->control_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; } apr_sockaddr_info_get(&agent->control_sockaddr,"127.0.0.1",APR_INET,listen_port,0,agent->pool); if(!agent->control_sockaddr) { return NULL; } apt_task_vtable_reset(&vtable); vtable.run = mrcp_server_agent_task_run; vtable.terminate = mrcp_server_agent_task_terminate; agent->task = apt_task_create(agent,&vtable,NULL,pool); if(!agent->task) { return NULL; } agent->connection_list = NULL; agent->null_connection = NULL; 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; }
/** 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_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; } apt_task_vtable_reset(&vtable); vtable.run = mrcp_sofia_task_run; vtable.terminate = mrcp_sofia_task_terminate; sofia_agent->sig_agent->task = apt_task_create(sofia_agent,&vtable,NULL,pool); apt_log(APT_PRIO_NOTICE,"Create Sofia SIP ["SOFIA_SIP_VERSION"] Agent %s:%hu",config->local_ip,config->local_port); return sofia_agent->sig_agent; }
/** Create connection task */ APT_DECLARE(apt_net_client_task_t*) apt_net_client_task_create( apr_size_t max_connection_count, void *obj, apt_task_vtable_t *task_vtable, const apt_net_client_vtable_t *client_vtable, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool) { apt_task_vtable_t vtable; apt_net_client_task_t *task; task = apr_palloc(pool,sizeof(apt_net_client_task_t)); task->pool = pool; task->obj = obj; task->pollset = NULL; task->max_connection_count = max_connection_count; if(!client_vtable || !client_vtable->on_receive) { return NULL; } task->client_vtable = client_vtable; apt_task_vtable_reset(&vtable); if(task_vtable) { vtable = *task_vtable; } vtable.run = apt_net_client_task_run; vtable.signal_msg = apt_net_client_task_msg_signal; task->base = apt_task_create(task,&vtable,msg_pool,pool); if(!task->base) { return NULL; } task->msg_queue = apt_cyclic_queue_create(100,pool); apr_thread_mutex_create(&task->guard,APR_THREAD_MUTEX_UNNESTED,pool); return task; }