From b662ee6de9582180d8353ae743b2e8387afe86dc Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 30 Jun 2016 17:30:55 +0900 Subject: [PATCH] [Adapt:OAL]Added event_data size in OAL send_event This patch modifies OAL function send_event() to include size of the event_data along with event_data void ptr. This will help if later we need to copy event_data and release OAL context from bt-service-event-receiver. Change-Id: Ie215db21027a9c76680473b1c848c0fd0c7c1416 Signed-off-by: Atul Rai --- bt-oal/common/oal-event-dispatcher.c | 14 ++++++++------ bt-oal/include/oal-manager.h | 2 +- bt-oal/oal-adapter-mgr.c | 4 ++-- bt-oal/oal-internal.h | 8 ++++---- bt-oal/oal-manager.c | 4 ++-- bt-service-adaptation/services/bt-service-event-receiver.c | 4 ++-- .../services/include/bt-service-event-receiver.h | 2 +- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/bt-oal/common/oal-event-dispatcher.c b/bt-oal/common/oal-event-dispatcher.c index 7c68ee6..bc35cf4 100755 --- a/bt-oal/common/oal-event-dispatcher.c +++ b/bt-oal/common/oal-event-dispatcher.c @@ -34,6 +34,7 @@ typedef struct { int event; + unsigned int size; gpointer event_data; } event_t; @@ -80,7 +81,7 @@ static gboolean dispatch_idle (gpointer user_data) if (!event_handler_cb) { BT_ERR("Upstream handler not registered"); } else - (*event_handler_cb) (event_info->event, event_info->event_data); + (*event_handler_cb) (event_info->event, event_info->event_data, event_info->size); BT_DBG("-"); return G_SOURCE_REMOVE; @@ -109,7 +110,7 @@ void _bt_event_dispatcher_init(oal_event_callback cb) g_thread_new ("OALEventScheduler", __event_handler_loop, NULL); } -void send_event_no_trace(oal_event_t event, gpointer event_data) +void send_event_no_trace(oal_event_t event, gpointer event_data, gsize len) { event_t *event_info; @@ -117,6 +118,7 @@ void send_event_no_trace(oal_event_t event, gpointer event_data) * between threads. */ event_info = g_slice_new0 (event_t); event_info->event = event; + event_info->size = len; event_info->event_data = event_data; /* Invoke the function. */ @@ -131,13 +133,13 @@ void send_event_no_trace(oal_event_t event, gpointer event_data) (GDestroyNotify) event_data_free); } -void send_event_bda_trace(oal_event_t event, gpointer event_data, bt_address_t *address) +void send_event_bda_trace(oal_event_t event, gpointer event_data, gsize len, bt_address_t *address) { - send_event_no_trace(event, event_data); + send_event_no_trace(event, event_data, len); } -void send_event(oal_event_t event, gpointer event_data) +void send_event(oal_event_t event, gpointer event_data, gsize len) { - send_event_bda_trace(event, event_data, NULL); + send_event_bda_trace(event, event_data, len, NULL); } #undef _OAL_EVENT_DISPATCHER_C_ diff --git a/bt-oal/include/oal-manager.h b/bt-oal/include/oal-manager.h index 6ce9c76..0460cac 100755 --- a/bt-oal/include/oal-manager.h +++ b/bt-oal/include/oal-manager.h @@ -42,7 +42,7 @@ extern "C" { #define BLUETOOTH_UUID_STRING_MAX 50 -typedef void (*oal_event_callback)(int event, gpointer event_data); +typedef void (*oal_event_callback)(int event, gpointer event_data, gsize size); typedef struct { unsigned char addr[BT_ADDRESS_BYTES_NUM]; diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 0c9c5fa..0099338 100755 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -71,7 +71,7 @@ oal_status_t adapter_mgr_init(const bt_interface_t * stack_if) ret = blued_api->init(&callbacks); - if(ret != BT_STATUS_SUCCESS) { + if (ret != BT_STATUS_SUCCESS) { BT_ERR("Adapter callback registration failed: [%s]", status2string(ret)); blued_api->cleanup(); return convert_to_oal_status(ret); @@ -137,7 +137,7 @@ static void cb_adapter_state_change(bt_state_t status) event = (BT_STATE_ON == status)?OAL_EVENT_ADAPTER_ENABLED:OAL_EVENT_ADAPTER_DISABLED; - send_event(event, NULL); + send_event(event, NULL, 0); } static gboolean retry_enable_adapter(gpointer data) diff --git a/bt-oal/oal-internal.h b/bt-oal/oal-internal.h index 5398f6b..eb1b637 100755 --- a/bt-oal/oal-internal.h +++ b/bt-oal/oal-internal.h @@ -63,9 +63,9 @@ extern "C" { #define API_TRACE(fmt, args...) {LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_API", GREEN(fmt), ##args); \ LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_API]"fmt), ##args);} -#define send_event_trace(e,d,a, fmt, args...) do {\ +#define send_event_trace(e, d, l, a, fmt, args...) do {\ bdstr_t bdstr;\ - send_event_no_trace(e, d); \ + send_event_no_trace(e, d, l); \ LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_EVENT", GREEN(fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]); \ LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_EVENT]"fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]);\ } while(0) @@ -119,11 +119,11 @@ oal_status_t adapter_mgr_init(const bt_interface_t * stack_if); /* Event Manager */ /* Use this when Address is to be printed */ -void send_event_bda_trace(oal_event_t event, gpointer event_data, bt_address_t *address); +void send_event_bda_trace(oal_event_t event, gpointer event_data, gsize len, bt_address_t *address); /* Use this when no address printing is required */ #define _bt_dispatch_event send_event -void send_event(oal_event_t event, gpointer event_data); +void send_event(oal_event_t event, gpointer event_data, gsize len); void _bt_event_dispatcher_init(oal_event_callback cb); #ifdef __cplusplus diff --git a/bt-oal/oal-manager.c b/bt-oal/oal-manager.c index 7542d9d..a4b5c5b 100755 --- a/bt-oal/oal-manager.c +++ b/bt-oal/oal-manager.c @@ -103,9 +103,9 @@ gboolean oal_lib_init(gpointer data) } else { ret = oal_mgr_init_internal(); if(OAL_STATUS_SUCCESS == ret) - send_event(OAL_EVENT_OAL_INITIALISED_SUCCESS, NULL); + send_event(OAL_EVENT_OAL_INITIALISED_SUCCESS, NULL, 0); else - send_event(OAL_EVENT_OAL_INITIALISED_FAILED, NULL); + send_event(OAL_EVENT_OAL_INITIALISED_FAILED, NULL, 0); } } else { BT_DBG("Chip Not Yet Ready, try again..."); diff --git a/bt-service-adaptation/services/bt-service-event-receiver.c b/bt-service-adaptation/services/bt-service-event-receiver.c index c9bf166..89cc08a 100644 --- a/bt-service-adaptation/services/bt-service-event-receiver.c +++ b/bt-service-adaptation/services/bt-service-event-receiver.c @@ -60,9 +60,9 @@ void _bt_service_unregister_event_handler_callback(bt_service_module_t module) } } -void _bt_service_oal_event_receiver(int event_type, gpointer event_data) +void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize len) { - BT_INFO("event_type: [%d]", event_type); + BT_INFO("event_type: [%d], data size: [%d]", event_type, len); switch(event_type) { case OAL_EVENT_OAL_INITIALISED_SUCCESS: diff --git a/bt-service-adaptation/services/include/bt-service-event-receiver.h b/bt-service-adaptation/services/include/bt-service-event-receiver.h index d8e9c3e..1f18f7a 100644 --- a/bt-service-adaptation/services/include/bt-service-event-receiver.h +++ b/bt-service-adaptation/services/include/bt-service-event-receiver.h @@ -32,7 +32,7 @@ typedef enum { BT_ADAPTER_MODULE, } bt_service_module_t; -void _bt_service_oal_event_receiver(int event_type, gpointer event_data); +void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize len); void _bt_service_register_event_handler_callback( bt_service_module_t module, _bt_service_event_handler_callback cb); void _bt_service_unregister_event_handler_callback(bt_service_module_t module); -- 2.7.4