예제 #1
0
void my_handle_message(struct cfw_message * msg, void * param) {
	pr_info(LOG_MODULE_MAIN, "%s:%s for param: %s conn:%p", __FILE__, __func__, (char*)param, msg->conn);
	cfw_dump_message(msg);

	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CFW_OPEN_SERVICE_RSP: {
		pr_info(LOG_MODULE_MAIN, "%s:%s for conn: %s", __FILE__, __func__, (char*)msg->priv);
		cfw_open_conn_rsp_msg_t * cnf = (cfw_open_conn_rsp_msg_t*)msg;
		int events[1] = {MSG_ID_TEST_1_EVT};
		test_service_conn = cnf->service_conn;
		cfw_register_events(test_service_conn, events, 1, msg->priv);
	}
	break;

	case MSG_ID_CFW_REGISTER_EVT_RSP:
		if (!strcmp(msg->priv, "Conn2")) {
			test_service_test_1(test_service_conn, "Coucou");
		}
		break;

	case MSG_ID_TEST_1_RSP: {
		pr_info(LOG_MODULE_MAIN, "got MSG_ID_TEST_1_RSP Priv: %s", (char*)msg->priv);
		test_service_test_2(test_service_conn, "Testing 2");
		break;
	}
	case MSG_ID_TEST_2_RSP: {
		pr_info(LOG_MODULE_MAIN, "got MSG_ID_TEST_2_RSP Priv: %s", (char*)msg->priv);
		test_service_test_1(test_service_conn, "Testing 1");
		break;
	}
	}
	cfw_msg_free(msg);

}
예제 #2
0
파일: ble_app.c 프로젝트: SDICurie/main
static void on_batt_service_open(cfw_service_conn_t *p_conn, void *param)
{
	int client_events[] = { MSG_ID_BATTERY_SERVICE_LEVEL_UPDATED_EVT };

	if (_ble_app_cb.p_batt_conn) {
		pr_warning(LOG_MODULE_BLE, "BATT twice?");
		return;
	}
	_ble_app_cb.p_batt_conn = p_conn;

	cfw_register_events(_ble_app_cb.p_batt_conn, client_events,
			    sizeof(client_events) / sizeof(int), &_ble_app_cb);

	battery_service_get_info(_ble_app_cb.p_batt_conn, BATTERY_DATA_LEVEL,
				 NULL);
}
예제 #3
0
파일: ble_app.c 프로젝트: SDICurie/main
static void on_ble_service_open(cfw_service_conn_t *p_conn, void *param)
{
	if (_ble_app_cb.p_ble_conn) {
		pr_warning(LOG_MODULE_BLE, "BLE twice?");
		return;
	}
	_ble_app_cb.p_ble_conn = p_conn;
	_ble_app_cb.conn_periph = NULL;
	_ble_app_cb.flags = 0;

	/* read device name, will be used at BLE enable */
	ble_app_prop_read(BLE_PROPERTY_ID_DEVICE_NAME, on_storage_ble_name_read,
			  0);

	/* List of events to receive */
	int client_events[] = {
		MSG_ID_BLE_ADV_TO_EVT,
	};
	cfw_register_events(_ble_app_cb.p_ble_conn, client_events,
			    sizeof(client_events) / sizeof(int), &_ble_app_cb);
}
예제 #4
0
/**@brief Function to handle messages from framework.
 *
 * @details In this function are handled messages of
 *          communications with the Audio service.
 * @param[in]  msg   Message from framework.
 * @param[in]  param Additional data. NULL if not used.
 * @return   none.
 */
void ui_audio_svc_handle_message(message_t * msg, void *param)
{
    int client_events[4];
    cfw_open_conn_rsp_msg_t *cnf = NULL;
    audio_stream_mgr_evt_msg *evt = NULL;

    pr_debug(LOG_MODULE_UI_SVC,
        "Audio: received msg: %d src: %d dst: %d",
        msg->id,
        msg->src,
        msg->dst);

    /* Dump message content. */
    cfw_dump_message(msg);

    ui_port = msg->dst;

    switch (msg->id) {
    case MSG_ID_CFW_OPEN_SERVICE_RSP:{
        cnf = (cfw_open_conn_rsp_msg_t *) msg;
        if (cnf == NULL) force_panic();

        audio_client_cfw_hdl = cnf->service_conn;
        if (audio_client_cfw_hdl == NULL) force_panic();

        client_events[0] = MSG_ID_AS_LPAL_EVT;
        client_events[1] = MSG_ID_AS_ASR_EVT;
        client_events[2] = MSG_ID_AS_STREAM_STOPPED_EVT;
        client_events[3] = MSG_ID_AS_STREAM_TERMINATED_EVT;

        /* Events registration. */
        cfw_register_events(audio_client_cfw_hdl,
                    client_events, 4, msg->priv);

        pr_info(LOG_MODULE_UI_SVC,
            "Audio: Audio service id %lu opened",
            UI_SVC_ID);
        }
        break;
    case MSG_ID_CFW_CLOSE_SERVICEi_RSP:
        pr_info(LOG_MODULE_UI_SVC,
            "Audio: Audio service has been closed");
        break;
    case MSG_ID_CFW_REGISTER_EVT_RSP:
        pr_debug(LOG_MODULE_UI_SVC,
            "Audio: Events registered for Audio service");
        break;
    case MSG_ID_AS_LPAL_EVT:
        ui_broadcast_svc_lpal_event(msg);
        break;
    case MSG_ID_AS_ASR_EVT:
        ui_broadcast_svc_asr_event(msg);
        break;
    case MSG_ID_AS_STREAM_STOPPED_EVT:
        /* Need to filter MSG_ID_AS_STREAM_XX messages, as the UI SVC is */
        /* not the only one listening to them.                           */
        /* If not tone or speech sequence initialized, msg is ignored.   */
        evt = (audio_stream_mgr_evt_msg *)msg;

        if ((evt->sHandle == tone_stream) || (evt->sHandle == sps_stream)) {
            pr_debug(LOG_MODULE_UI_SVC,
                "Audio: stream 0x%08x stopped, reason %d",
                evt->sHandle,
                evt->sHandle->reason);

            if (evt->sHandle->reason == AUDIO_STREAM_STATE_INIT_SUCCESS) {
                if (tone_stream)
                    ui_tone_play_start();
                else if (sps_stream)
                    ui_sps_play_start();
            }
        }
        break;
    case MSG_ID_AS_STREAM_TERMINATED_EVT:
        ui_handle_as_stream_end(msg);
        break;
    default:
        break;
    }

    cfw_msg_free(msg);
}
예제 #5
0
파일: service_api.c 프로젝트: CurieBSP/main
void client_handle_message(struct cfw_message *msg, void *param)
{
	_cfw_client_t *c = (_cfw_client_t *)param;
	bool handled = false;

	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP:
		if (get_conn_helper(c, msg->priv))
			handled = true;
		break;

	case MSG_ID_CFW_SVC_AVAIL_EVT:
	{
		cfw_svc_available_evt_msg_t *evt =
			(cfw_svc_available_evt_msg_t *)msg;
		if (get_conn_helper(c, evt->header.priv)) {
			cfw_open_service_conn(c, evt->service_id,
					      evt->header.priv);
			handled = true;
		}
	}
	break;

	case MSG_ID_CFW_OPEN_SERVICE_RSP:
	{
		cfw_open_conn_rsp_msg_t *cnf = (cfw_open_conn_rsp_msg_t *)msg;
		/** Make client handle point to server handle */
		((cfw_service_conn_t *)cnf->service_conn)->server_handle =
			cnf->svc_server_handle;
		/** Initialize service port. */
		((cfw_service_conn_t *)cnf->service_conn)->port = cnf->port;
#ifndef CONFIG_PORT_IS_MASTER
		/* Set local port and cpu id */
		if (get_cpu_id() != cnf->cpu_id) {
			port_set_port_id(cnf->port);
			port_set_cpu_id(cnf->port, cnf->cpu_id);
		}
#endif
		struct conn_helper_data *helper = get_conn_helper(
			c, cnf->header.priv);
		if (helper != NULL) {
			helper->service_conn =
				(cfw_service_conn_t *)cnf->service_conn;
			if (helper->event_count > 0) {
				cfw_register_events(helper->service_conn,
						    helper->events,
						    helper->event_count,
						    helper);
			} else {
				/* call the helper callback and free it */
				cfw_open_service_helper_done(c, helper);
			}
			handled = true;
		}

		break;
	}
	case MSG_ID_CFW_REGISTER_EVT_RSP:
	{
		struct conn_helper_data *helper = get_conn_helper(
			c, CFW_MESSAGE_PRIV(msg));
		if (helper != NULL) {
			helper->cb(helper->service_conn, helper->cb_data);
			list_remove(&c->helper_list, &helper->list);
			bfree(helper);
			handled = true;
		}
	}
	break;
	case MSG_ID_CFW_CLOSE_SERVICE_RSP:
	{
		/* Free client-side conn */
		bfree(msg->conn);
		break;
	}
	default:
		//Nothing to do
		break;
	}
	if (handled)
		/* message handled here: free it */
		bfree(msg);
	else {
		/* defer processing to message handler */
		if (CFW_MESSAGE_CB(msg)) {
			/* A specific callback was specified for this message */
			CFW_MESSAGE_CB(msg) (msg);
		} else {
			/* Call client global message handler  */
			c->handle_msg(msg, c->data);
		}
	}
}