Exemplo n.º 1
0
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 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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
static apt_bool_t mrcp_sofia_task_run(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());

        /* 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;
}