/** Start execution of MPF test suite scenario */ static void mpf_suite_on_start_complete(apt_task_t *task) { mpf_suite_session_t *session; apt_task_t *consumer_task; mpf_suite_engine_t *suite_engine; mpf_task_msg_t *task_msg = NULL; void *descriptor; apr_pool_t *pool = NULL; consumer_task = apt_task_object_get(task); suite_engine = apt_task_object_get(consumer_task); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"On MPF Suite Start"); pool = apt_pool_create(); session = apr_palloc(pool,sizeof(mpf_suite_session_t)); session->pool = pool; session->context = NULL; session->termination1 = NULL; session->termination2 = NULL; session->rtp_mode = TRUE; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create MPF Context"); session->context = mpf_engine_context_create(suite_engine->engine,session,2,pool); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [1]"); session->termination1 = mpf_termination_create(suite_engine->file_termination_factory,session,session->pool); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [1]"); descriptor = mpf_file_reader_descriptor_create(session); mpf_engine_termination_message_add( suite_engine->engine, MPF_ADD_TERMINATION,session->context,session->termination1,descriptor, &task_msg); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [2]"); if(session->rtp_mode == TRUE) { session->termination2 = mpf_termination_create(suite_engine->rtp_termination_factory,session,session->pool); } else { session->termination2 = mpf_termination_create(suite_engine->file_termination_factory,session,session->pool); } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [2]"); descriptor = NULL; if(session->rtp_mode == TRUE) { descriptor = mpf_rtp_local_descriptor_create(session); } else { descriptor = mpf_file_writer_descriptor_create(session); } mpf_engine_termination_message_add( suite_engine->engine, MPF_ADD_TERMINATION,session->context,session->termination2,descriptor, &task_msg); mpf_engine_message_send(suite_engine->engine,&task_msg); }
/** Start execution of MPF test suite scenario */ static void mpf_suite_on_start_complete(apt_task_t *task) { apt_task_t *consumer_task; mpf_suite_agent_t *agent; consumer_task = apt_task_object_get(task); agent = apt_task_object_get(consumer_task); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"On MPF Suite Start"); agent->rx_session = mpf_suite_rx_session_create(agent); agent->tx_session = mpf_suite_tx_session_create(agent); }
static void demo_framework_on_terminate_request(apt_task_t *task) { /*TODO::send terminate to all demo_application*/ apt_consumer_task_t *consumer_task = apt_task_object_get(task); demo_framework_t *framework = apt_consumer_task_object_get(consumer_task); demo_application_t** appp = (demo_application_t**)mrcp_client_application_get(framework->client, "recog"); demo_application_t* app = *appp; app->handler(app, NULL); /* apt_task_msg_t *task_msg = apt_task_msg_get(task); mrcp_app_message_t *app_message = apr_palloc(framework->pool, sizeof(mrcp_app_message_t)); app_message->message_type = MRCP_APP_MESSAGE_TYPE_SIGNALING; app_message->sig_message.message_type = MRCP_SIG_MESSAGE_TYPE_EVENT; app_message->sig_message.event_id = MRCP_SIG_EVENT_TERMINATE; if(task_msg) { framework_task_data_t *framework_task_data = (framework_task_data_t*)task_msg->data; task_msg->type = TASK_MSG_USER; task_msg->sub_type = DEMO_APPLICATION_MSG_ID; framework_task_data->app_message = app_message; framework_task_data->demo_application = app; apt_task_msg_signal(task,task_msg); }*/ }
static void mrcp_server_on_terminate_complete(apt_task_t *task) { apt_consumer_task_t *consumer_task = apt_task_object_get(task); mrcp_server_t *server = apt_consumer_task_object_get(consumer_task); mrcp_resource_engine_t *resource_engine; apr_dso_handle_t *plugin; apr_hash_index_t *it; void *val; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Close Resource Engines"); it=apr_hash_first(server->pool,server->resource_engine_table); for(; it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); resource_engine = val; if(resource_engine) { mrcp_resource_engine_close(resource_engine); } } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Unload Plugins"); it=apr_hash_first(server->pool,server->plugin_table); for(; it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); plugin = val; if(plugin) { apr_dso_unload(plugin); } } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"On Server Task Terminate"); }
static void mrcp_client_on_start_complete(apt_task_t *task) { apt_consumer_task_t *consumer_task = apt_task_object_get(task); mrcp_client_t *client = apt_consumer_task_object_get(consumer_task); void *val; mrcp_application_t *application; mrcp_app_message_t *app_message; apr_hash_index_t *it; apt_log(APT_PRIO_INFO,"On Client Task Start"); it = apr_hash_first(client->pool,client->app_table); for(; it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); application = val; if(!application) continue; /* raise one-time ready event */ app_message = apr_palloc(client->pool,sizeof(mrcp_app_message_t)); app_message->message_type = MRCP_APP_MESSAGE_TYPE_SIGNALING; app_message->sig_message.message_type = MRCP_SIG_MESSAGE_TYPE_EVENT; app_message->sig_message.event_id = MRCP_SIG_EVENT_READY; app_message->sig_message.status = MRCP_SIG_STATUS_CODE_SUCCESS; app_message->application = application; application->handler(app_message); } }
static void mrcp_sofia_task_initialize(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); mrcp_sofia_server_config_t *sofia_config = sofia_agent->config; /* Initialize Sofia-SIP library and create event loop */ su_init(); sofia_agent->root = su_root_create(NULL); /* Create a user agent instance. The stack will call the 'event_callback()' * callback when events such as succesful registration to network, * an incoming call, etc, occur. */ sofia_agent->nua = nua_create( sofia_agent->root, /* Event loop */ mrcp_sofia_event_callback, /* Callback for processing events */ sofia_agent, /* Additional data to pass to callback */ NUTAG_URL(sofia_agent->sip_bind_str), /* Address to bind to */ NUTAG_AUTOANSWER(0), NUTAG_APPL_METHOD("OPTIONS"), TAG_IF(sofia_config->sip_t1,NTATAG_SIP_T1(sofia_config->sip_t1)), TAG_IF(sofia_config->sip_t2,NTATAG_SIP_T2(sofia_config->sip_t2)), TAG_IF(sofia_config->sip_t4,NTATAG_SIP_T4(sofia_config->sip_t4)), TAG_IF(sofia_config->sip_t1x64,NTATAG_SIP_T1X64(sofia_config->sip_t1x64)), SIPTAG_USER_AGENT_STR(sofia_config->user_agent_name), TAG_IF(sofia_config->tport_log == TRUE,TPTAG_LOG(1)), /* Print out SIP messages to the console */ TAG_IF(sofia_config->tport_dump_file,TPTAG_DUMP(sofia_config->tport_dump_file)), /* Dump SIP messages to the file */ TAG_END()); /* Last tag should always finish the sequence */ if(!sofia_agent->nua) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create NUA [%s] %s", apt_task_name_get(task), sofia_agent->sip_bind_str); } }
static void mrcp_sofia_task_initialize(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); /* Initialize Sofia-SIP library and create event loop */ su_init(); sofia_agent->root = su_root_create(NULL); /* Create a user agent instance. The stack will call the 'event_callback()' * callback when events such as succesful registration to network, * an incoming call, etc, occur. */ sofia_agent->nua = nua_create( sofia_agent->root, /* Event loop */ mrcp_sofia_event_callback, /* Callback for processing events */ sofia_agent, /* Additional data to pass to callback */ NUTAG_URL(sofia_agent->sip_bind_str), /* Address to bind to */ TAG_END()); /* Last tag should always finish the sequence */ if(sofia_agent->nua) { nua_set_params( sofia_agent->nua, NUTAG_AUTOANSWER(0), NUTAG_APPL_METHOD("OPTIONS"), SIPTAG_USER_AGENT_STR(sofia_agent->config->user_agent_name), TAG_END()); } }
static apt_bool_t apt_consumer_task_run(apt_task_t *task) { apr_status_t rv; void *msg; apt_bool_t *running; apt_consumer_task_t *consumer_task; consumer_task = apt_task_object_get(task); if(!consumer_task) { return FALSE; } running = apt_task_running_flag_get(task); if(!running) { return FALSE; } while(*running) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Wait for Messages [%s]",apt_task_name_get(task)); rv = apr_queue_pop(consumer_task->msg_queue,&msg); if(rv == APR_SUCCESS) { if(msg) { apt_task_msg_t *task_msg = msg; apt_task_msg_process(consumer_task->base,task_msg); } } } return TRUE; }
apt_bool_t UmcProcessMsg(apt_task_t *pTask, apt_task_msg_t *pMsg) { if(pMsg->type != TASK_MSG_USER) return FALSE; apt_consumer_task_t* pConsumerTask = (apt_consumer_task_t*) apt_task_object_get(pTask); UmcFramework* pFramework = (UmcFramework*) apt_consumer_task_object_get(pConsumerTask); UmcTaskMsg* pUmcMsg = (UmcTaskMsg*) pMsg->data; switch(pMsg->sub_type) { case UMC_TASK_CLIENT_MSG: { static const mrcp_app_message_dispatcher_t applicationDispatcher = { AppOnSessionUpdate, AppOnSessionTerminate, AppOnChannelAdd, AppOnChannelRemove, AppOnMessageReceive, AppOnTerminateEvent, AppOnResourceDiscover }; mrcp_application_message_dispatch(&applicationDispatcher,pUmcMsg->m_pAppMessage); break; } case UMC_TASK_RUN_SESSION_MSG: { pFramework->ProcessRunRequest(pUmcMsg->m_ScenarioName,pUmcMsg->m_ProfileName); break; } case UMC_TASK_STOP_SESSION_MSG: { pFramework->ProcessStopRequest(pUmcMsg->m_SessionId); break; } case UMC_TASK_KILL_SESSION_MSG: { pFramework->ProcessKillRequest(pUmcMsg->m_SessionId); break; } case UMC_TASK_SHOW_SCENARIOS_MSG: { pFramework->ProcessShowScenarios(); break; } case UMC_TASK_SHOW_SESSIONS_MSG: { pFramework->ProcessShowSessions(); break; } case UMC_TASK_EXIT_SESSION_MSG: { pFramework->ProcessSessionExit(pUmcMsg->m_pSession); break; } } return TRUE; }
void UmcOnTerminateComplete(apt_task_t* pTask) { apt_consumer_task_t* pConsumerTask = (apt_consumer_task_t*) apt_task_object_get(pTask); UmcFramework* pFramework = (UmcFramework*) apt_consumer_task_object_get(pConsumerTask); pFramework->DestroyMrcpClient(); pFramework->DestroyScenarios(); }
void UmcOnStartComplete(apt_task_t* pTask) { apt_consumer_task_t* pConsumerTask = (apt_consumer_task_t*) apt_task_object_get(pTask); UmcFramework* pFramework = (UmcFramework*) apt_consumer_task_object_get(pConsumerTask); pFramework->CreateMrcpClient(); pFramework->LoadScenarios(); }
static apt_bool_t mpf_engine_terminate(apt_task_t *task) { mpf_engine_t *engine = apt_task_object_get(task); mpf_scheduler_stop(engine->scheduler); apt_task_child_terminate(task); return TRUE; }
static apt_bool_t rtsp_server_on_destroy(apt_task_t *task) { apt_poller_task_t *poller_task = apt_task_object_get(task); rtsp_server_t *server = apt_poller_task_object_get(poller_task); rtsp_server_listening_socket_destroy(server); apt_poller_task_cleanup(poller_task); return TRUE; }
static apt_bool_t mrcp_server_agent_on_destroy(apt_task_t *task) { apt_poller_task_t *poller_task = apt_task_object_get(task); mrcp_connection_agent_t *agent = apt_poller_task_object_get(poller_task); mrcp_server_agent_listening_socket_destroy(agent); apt_poller_task_cleanup(poller_task); return TRUE; }
/** Process task messages */ static apt_bool_t mpf_suite_task_msg_process(apt_task_t *task, apt_task_msg_t *msg) { apr_size_t i; const mpf_message_t *mpf_message; apt_task_t *consumer_task = apt_task_object_get(task); mpf_suite_engine_t *suite_engine = apt_task_object_get(consumer_task); const mpf_message_container_t *container = (const mpf_message_container_t*) msg->data; for(i=0; i<container->count; i++) { mpf_message = &container->messages[i]; if(mpf_message->message_type == MPF_MESSAGE_TYPE_RESPONSE) { mpf_suite_response_process(suite_engine,mpf_message); } else { mpf_suite_event_process(suite_engine,mpf_message); } } return TRUE; }
static apt_bool_t mrcp_sofia_task_terminate(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); if(sofia_agent->nua) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Send Shutdown Signal to NUA"); nua_shutdown(sofia_agent->nua); } return TRUE; }
static apt_bool_t mpf_engine_destroy(apt_task_t *task) { mpf_engine_t *engine = apt_task_object_get(task); apt_timer_queue_destroy(engine->timer_queue); mpf_scheduler_destroy(engine->scheduler); mpf_context_factory_destroy(engine->context_factory); apt_cyclic_queue_destroy(engine->request_queue); apr_thread_mutex_destroy(engine->request_queue_guard); return TRUE; }
static apt_bool_t mpf_engine_msg_signal(apt_task_t *task, apt_task_msg_t *msg) { mpf_engine_t *engine = apt_task_object_get(task); apr_thread_mutex_lock(engine->request_queue_guard); if(apt_cyclic_queue_push(engine->request_queue,msg) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_ERROR,"MPF Request Queue is Full [%s]",apt_task_name_get(task)); } apr_thread_mutex_unlock(engine->request_queue_guard); return TRUE; }
static apt_bool_t mrcp_server_agent_task_run(apt_task_t *task) { mrcp_connection_agent_t *agent = apt_task_object_get(task); apt_bool_t running = TRUE; apr_status_t status; apr_int32_t num; const apr_pollfd_t *ret_pfd; int i; if(!agent) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start MRCPv2 Agent"); return FALSE; } if(mrcp_server_agent_pollset_create(agent) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset"); return FALSE; } /* explicitly indicate task is ready to process messages */ apt_task_ready(agent->task); while(running) { status = apt_pollset_poll(agent->pollset, -1, &num, &ret_pfd); if(status != APR_SUCCESS) { continue; } for(i = 0; i < num; i++) { if(ret_pfd[i].desc.s == agent->listen_sock) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Accept MRCPv2 Connection"); mrcp_server_agent_connection_accept(agent); continue; } if(apt_pollset_is_wakeup(agent->pollset,&ret_pfd[i])) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Control Message"); if(mrcp_server_agent_control_process(agent) == FALSE) { running = FALSE; break; } continue; } apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process MRCPv2 Message"); mrcp_server_agent_messsage_receive(agent,ret_pfd[i].client_data); } } mrcp_server_agent_pollset_destroy(agent); apt_task_child_terminate(agent->task); return TRUE; }
/** Virtual destroy handler. */ static apt_bool_t mrcp_server_agent_task_on_destroy(apt_task_t *task) { mrcp_connection_agent_t *agent = apt_task_object_get(task); if(agent->guard) { apr_thread_mutex_destroy(agent->guard); agent->guard = NULL; } if(agent->msg_queue) { apt_cyclic_queue_destroy(agent->msg_queue); agent->msg_queue = NULL; } return TRUE; }
static apt_bool_t apt_net_client_task_msg_signal(apt_task_t *base, apt_task_msg_t *msg) { apt_bool_t status; apt_net_client_task_t *task = apt_task_object_get(base); apr_thread_mutex_lock(task->guard); status = apt_cyclic_queue_push(task->msg_queue,msg); apr_thread_mutex_unlock(task->guard); if(apt_pollset_wakeup(task->pollset) != TRUE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Signal Control Message"); status = FALSE; } return status; }
static apt_bool_t mrcp_server_agent_on_destroy(apt_task_t *task) { apt_poller_task_t *poller_task = apt_task_object_get(task); mrcp_connection_agent_t *agent = apt_poller_task_object_get(poller_task); apt_pollset_t *pollset = apt_poller_task_pollset_get(poller_task); if(pollset) { apt_pollset_remove(pollset,&agent->listen_sock_pfd); } mrcp_server_agent_listening_socket_destroy(agent); apt_poller_task_cleanup(poller_task); return TRUE; }
/* Process task message */ static apt_bool_t rtsp_server_task_msg_process(apt_task_t *task, apt_task_msg_t *task_msg) { apt_poller_task_t *poller_task = apt_task_object_get(task); rtsp_server_t *server = apt_poller_task_object_get(poller_task); task_msg_data_t *data = (task_msg_data_t*) task_msg->data; switch(data->type) { case TASK_MSG_SEND_MESSAGE: rtsp_server_session_response_process(server,data->session,data->message); break; case TASK_MSG_TERMINATE_SESSION: rtsp_server_session_do_terminate(server,data->session); break; } return TRUE; }
/* Process task message */ static apt_bool_t rtsp_client_task_msg_process(apt_task_t *task, apt_task_msg_t *task_msg) { apt_net_client_task_t *net_task = apt_task_object_get(task); rtsp_client_t *client = apt_net_client_task_object_get(net_task); task_msg_data_t *data = (task_msg_data_t*) task_msg->data; switch(data->type) { case TASK_MSG_SEND_MESSAGE: rtsp_client_session_message_process(client,data->session,data->message); break; case TASK_MSG_TERMINATE_SESSION: rtsp_client_session_terminate_process(client,data->session); break; } return TRUE; }
static apt_bool_t mrcp_client_agent_task_terminate(apt_task_t *task) { apt_bool_t status = FALSE; mrcp_connection_agent_t *agent = apt_task_object_get(task); if(agent->control_sock) { connection_task_msg_data_t task_msg_data; apr_size_t size = sizeof(connection_task_msg_data_t); task_msg_data.type = CONNECTION_TASK_MSG_TERMINATE; if(apr_socket_sendto(agent->control_sock,agent->control_sockaddr,0,(const char*)&task_msg_data,&size) == APR_SUCCESS) { status = TRUE; } else { apt_log(APT_PRIO_WARNING,"Failed to Send Control Message"); } } return status; }
static void mrcp_client_on_start_complete(apt_task_t *task) { apt_consumer_task_t *consumer_task = apt_task_object_get(task); mrcp_client_t *client = apt_consumer_task_object_get(consumer_task); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,CLIENT_TASK_NAME" Started"); if(client->on_start_complete) { /* async start */ client->on_start_complete(TRUE); } else { /* sync start */ apr_thread_mutex_lock(client->sync_start_mutex); apr_thread_cond_signal(client->sync_start_object); apr_thread_mutex_unlock(client->sync_start_mutex); } }
static apt_bool_t mrcp_client_agent_task_run(apt_task_t *task) { mrcp_connection_agent_t *agent = apt_task_object_get(task); apt_bool_t running = TRUE; apr_status_t status; apr_int32_t num; const apr_pollfd_t *ret_pfd; int i; if(!agent) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start MRCPv2 Agent"); return FALSE; } agent->pollset = apt_pollset_create((apr_uint32_t)agent->max_connection_count,agent->pool); if(!agent->pollset) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset"); return FALSE; } while(running) { status = apt_pollset_poll(agent->pollset, -1, &num, &ret_pfd); if(status != APR_SUCCESS) { continue; } for(i = 0; i < num; i++) { if(apt_pollset_is_wakeup(agent->pollset,&ret_pfd[i])) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Control Message"); if(mrcp_client_agent_control_process(agent) == FALSE) { running = FALSE; break; } continue; } mrcp_client_agent_messsage_receive(agent,ret_pfd[i].client_data); } } apt_pollset_destroy(agent->pollset); agent->pollset = NULL; apt_task_child_terminate(agent->task); return TRUE; }
static void mrcp_server_on_start_complete(apt_task_t *task) { apt_consumer_task_t *consumer_task = apt_task_object_get(task); mrcp_server_t *server = apt_consumer_task_object_get(consumer_task); mrcp_resource_engine_t *resource_engine; apr_hash_index_t *it; void *val; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Open Resource Engines"); it = apr_hash_first(server->pool,server->resource_engine_table); for(; it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); resource_engine = val; if(resource_engine) { mrcp_resource_engine_open(resource_engine); } } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"On Server Task Start"); }
static apt_bool_t apt_net_client_task_run(apt_task_t *base) { apt_net_client_task_t *task = apt_task_object_get(base); apt_bool_t running = TRUE; apr_status_t status; apr_int32_t num; const apr_pollfd_t *ret_pfd; int i; if(!task) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Network Client Task"); return FALSE; } if(apt_net_client_task_pollset_create(task) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset"); return FALSE; } while(running) { status = apt_pollset_poll(task->pollset, -1, &num, &ret_pfd); if(status != APR_SUCCESS) { continue; } for(i = 0; i < num; i++) { if(apt_pollset_is_wakeup(task->pollset,&ret_pfd[i])) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Control Message"); if(apt_net_client_task_process(task) == FALSE) { running = FALSE; break; } continue; } apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Message"); task->client_vtable->on_receive(task,ret_pfd[i].client_data); } } apt_net_client_task_pollset_destroy(task); apt_task_child_terminate(task->base); return TRUE; }
static apt_bool_t mrcp_sofia_task_run(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); if(sofia_agent->nua) { /* Run event loop */ su_root_run(sofia_agent->root); /* Destroy allocated resources */ nua_destroy(sofia_agent->nua); sofia_agent->nua = NULL; } su_root_destroy(sofia_agent->root); sofia_agent->root = NULL; su_deinit(); apt_task_child_terminate(task); return TRUE; }