[BluezHAL]Added generic API for event_handler_cb 39/123239/1
authorAtul Rai <a.rai@samsung.com>
Wed, 29 Mar 2017 06:53:31 +0000 (12:23 +0530)
committerAtul Rai <a.rai@samsung.com>
Wed, 29 Mar 2017 14:03:15 +0000 (19:33 +0530)
This patch removes individual APIs for registering event handler
callbacks for different profiles/modules and adds 1 generic event
receiver API to register event_handler_cb for different modules.

Change-Id: I91ae496f7f5e50709c5c19932c1369445bb08ba8
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/bluez_hal/src/bt-hal-a2dp-sink.c
bt-oal/bluez_hal/src/bt-hal-av.c
bt-oal/bluez_hal/src/bt-hal-avrcp-ctrl.c
bt-oal/bluez_hal/src/bt-hal-avrcp-tg.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.h
bt-oal/bluez_hal/src/bt-hal-hf.c
bt-oal/bluez_hal/src/bt-hal-hidhost.c

index d2427b8..d73c8ba 100644 (file)
@@ -97,7 +97,7 @@ static bt_status_t init(btav_callbacks_t* callbacks)
        bt_hal_a2dp_sink_cbacks = callbacks;
        DBG("Register A2DP Sink events callback function");
        _bt_hal_register_a2dp_sink_dbus_handler_cb(__bt_hal_handle_a2dp_sink_events);
-       _bt_hal_register_a2dp_sink_event_handler_cb(__bt_hal_handle_a2dp_sink_events);
+       _bt_hal_register_event_handler_cb(HAL_A2DP_SNK, __bt_hal_handle_a2dp_sink_events);
        return BT_STATUS_SUCCESS;
 }
 
@@ -109,7 +109,7 @@ static void cleanup(void)
                return;
 
        bt_hal_a2dp_sink_cbacks = NULL;
-       _bt_hal_unregister_a2dp_sink_event_handler_cb();
+       _bt_hal_unregister_event_handler_cb(HAL_A2DP_SNK);
 }
 
 static btav_interface_t a2dp_sink_if = {
index fad7755..1dddd9e 100644 (file)
@@ -98,7 +98,7 @@ static bt_status_t init(btav_callbacks_t* callbacks)
        bt_hal_av_cbacks = callbacks;
        DBG("Register A2DP Src events callback function");
        _bt_hal_register_av_dbus_handler_cb(__bt_hal_handle_av_events);
-       _bt_hal_register_av_event_handler_cb(__bt_hal_handle_av_events);
+       _bt_hal_register_event_handler_cb(HAL_A2DP_SRC, __bt_hal_handle_av_events);
        return BT_STATUS_SUCCESS;
 }
 
@@ -109,6 +109,7 @@ static void cleanup(void)
        if (!interface_ready())
                return;
 
+       _bt_hal_unregister_event_handler_cb(HAL_A2DP_SRC);
        bt_hal_av_cbacks = NULL;
 }
 
index b6a70f0..1455e54 100644 (file)
@@ -232,7 +232,7 @@ static bt_status_t init(btrc_ctrl_callbacks_t* callbacks)
        bt_hal_avrcp_ctrl_cbacks = callbacks;
        DBG("Register AVRCP Ctroller events callback function");
        _bt_hal_register_avrcp_ctrl_dbus_handler_cb(__bt_hal_handle_avrcp_ctrl_event);
-       _bt_hal_register_avrcp_ctrl_event_handler_cb(__bt_hal_handle_avrcp_ctrl_event);
+       _bt_hal_register_event_handler_cb(HAL_AVRCP_CTRL, __bt_hal_handle_avrcp_ctrl_event);
        return BT_STATUS_SUCCESS;
 }
 
@@ -243,6 +243,7 @@ static void cleanup(void)
        if (!interface_ready())
                return;
 
+       _bt_hal_unregister_event_handler_cb(HAL_AVRCP_CTRL);
        bt_hal_avrcp_ctrl_cbacks = NULL;
 }
 
index 225205d..7953d65 100644 (file)
@@ -322,7 +322,7 @@ static bt_status_t init(btrc_callbacks_t *callbacks)
        /* Register AVRCP event callback */
        _bt_hal_register_avrcp_tg_dbus_handler_cb(
                        __bt_hal_handle_avrcp_tg_events);
-       _bt_hal_register_avrcp_tg_event_handler_cb(
+       _bt_hal_register_event_handler_cb(HAL_AVRCP_TG,
                        __bt_hal_handle_avrcp_tg_events);
 
        bt_hal_avrcp_tg_cbacks = callbacks;
@@ -342,7 +342,7 @@ static void cleanup(void)
 
        /* Un-register AVRCP event callback */
        _bt_hal_unregister_avrcp_tg_dbus_handler_cb();
-       _bt_hal_unregister_avrcp_tg_event_handler_cb();
+       _bt_hal_unregister_event_handler_cb(HAL_AVRCP_TG);
 
        bt_hal_avrcp_tg_cbacks = NULL;
 }
index fc84d56..4fd7711 100644 (file)
@@ -56,9 +56,9 @@ static handle_stack_msg a2dp_sink_event_cb = NULL;
 static handle_stack_msg hf_event_cb = NULL;
 static handle_stack_msg avrcp_ctrl_event_cb = NULL;
 static handle_stack_msg avrcp_tg_event_cb = NULL;
+static handle_stack_msg gatt_event_cb = NULL;
 static guint event_id;
 
-
 typedef struct {
        gchar* sender_name;
        gchar* object_path;
@@ -1685,16 +1685,6 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
 }
 
 /* AVRCP Controller Role(Remote:AVRCP Target) Events */
-void _bt_hal_register_avrcp_ctrl_event_handler_cb(handle_stack_msg cb)
-{
-       avrcp_ctrl_event_cb = cb;
-}
-
-void _bt_hal_unregister_avrcp_ctrl_event_handler_cb()
-{
-       avrcp_ctrl_event_cb = NULL;
-}
-
 static void __bt_hal_send_avrcp_ctrl_connection_state_event(gboolean connected, const char *address)
 {
        DBG("+");
@@ -1954,27 +1944,7 @@ static void __bt_hal_handle_avrcp_ctrl_events(GVariant *msg, const char *member,
        g_variant_unref(value);
 }
 
-void _bt_hal_register_hid_event_handler_cb(handle_stack_msg cb)
-{
-       hid_event_cb = cb;
-}
-
-void _bt_hal_unregister_hid_event_handler_cb()
-{
-       hid_event_cb = NULL;
-}
-
 /* A2DP Src Role(Remote:Sink) Events */
-void _bt_hal_register_av_event_handler_cb(handle_stack_msg cb)
-{
-       av_event_cb = cb;
-}
-
-void _bt_hal_unregister_av_event_handler_cb()
-{
-       av_event_cb = NULL;
-}
-
 static void __bt_hal_send_av_connection_state_event(gboolean connected, const char *address)
 {
        DBG("+");
@@ -1998,16 +1968,6 @@ static void __bt_hal_send_av_connection_state_event(gboolean connected, const ch
 }
 
 /* A2DP Sink Role(Remote:Source) Events */
-void _bt_hal_register_a2dp_sink_event_handler_cb(handle_stack_msg cb)
-{
-       a2dp_sink_event_cb = cb;
-}
-
-void _bt_hal_unregister_a2dp_sink_event_handler_cb(void)
-{
-       a2dp_sink_event_cb = NULL;
-}
-
 static void __bt_hal_send_a2dp_sink_connection_state_event(gboolean connected, const char *address)
 {
        DBG("+");
@@ -2031,16 +1991,6 @@ static void __bt_hal_send_a2dp_sink_connection_state_event(gboolean connected, c
 }
 
 /* HF(AG Role) Events */
-void _bt_hal_register_hf_event_handler_cb(handle_stack_msg cb)
-{
-       hf_event_cb = cb;
-}
-
-void _bt_hal_unregister_hf_event_handler_cb()
-{
-       hf_event_cb = NULL;
-}
-
 static void __bt_hal_send_hf_audio_connection_state_event(gboolean connected,
                                                const char *address)
 {
@@ -2064,13 +2014,60 @@ static void __bt_hal_send_hf_audio_connection_state_event(gboolean connected,
                hf_event_cb(HAL_EV_HANDSFREE_AUDIO_STATE, &ev, sizeof(ev));
 }
 
-/* AVRCP target Role(Remote:AVRCP Controller) Events */
-void _bt_hal_register_avrcp_tg_event_handler_cb(handle_stack_msg cb)
+void _bt_hal_register_event_handler_cb(bt_hal_module_e module, handle_stack_msg cb)
 {
-       avrcp_tg_event_cb = cb;
+       switch (module) {
+       case HAL_HIDHOST:
+               hid_event_cb = cb;
+               break;
+       case HAL_A2DP_SRC:
+               av_event_cb = cb;
+               break;
+       case HAL_A2DP_SNK:
+               a2dp_sink_event_cb = cb;
+               break;
+       case HAL_HF_AG:
+               hf_event_cb = cb;
+               break;
+       case HAL_AVRCP_TG:
+               avrcp_tg_event_cb = cb;
+               break;
+       case HAL_AVRCP_CTRL:
+               avrcp_ctrl_event_cb = cb;
+               break;
+       case HAL_GATT:
+               gatt_event_cb = cb;
+               break;
+       default:
+               ERR("Unknown module: %d", module);
+       }
 }
 
-void _bt_hal_unregister_avrcp_tg_event_handler_cb()
+void _bt_hal_unregister_event_handler_cb(bt_hal_module_e module)
 {
-       avrcp_tg_event_cb = NULL;
+       switch (module) {
+       case HAL_HIDHOST:
+               hid_event_cb = NULL;
+               break;
+       case HAL_A2DP_SRC:
+               av_event_cb = NULL;
+               break;
+       case HAL_A2DP_SNK:
+               a2dp_sink_event_cb = NULL;
+               break;
+       case HAL_HF_AG:
+               hf_event_cb = NULL;
+               break;
+       case HAL_AVRCP_TG:
+               avrcp_tg_event_cb = NULL;
+               break;
+       case HAL_AVRCP_CTRL:
+               avrcp_ctrl_event_cb = NULL;
+               break;
+       case HAL_GATT:
+               gatt_event_cb = NULL;
+               break;
+       default:
+               ERR("Unknown module: %d", module);
+       }
 }
index 203ef8f..713f02e 100644 (file)
@@ -40,38 +40,24 @@ typedef void (*handle_stack_msg) (int message, void *buf, uint16_t len);
 
 int _bt_hal_initialize_event_receiver(handle_stack_msg cb);
 
-void _bt_hal_register_hid_event_handler_cb(handle_stack_msg cb);
+typedef enum {
+       HAL_HIDHOST,
+       HAL_A2DP_SRC,
+       HAL_A2DP_SNK,
+       HAL_HF_AG,
+       HAL_AVRCP_TG,
+       HAL_AVRCP_CTRL,
+       HAL_GATT,
+} bt_hal_module_e;
 
-void _bt_hal_unregister_hid_event_handler_cb();
+void _bt_hal_register_event_handler_cb(bt_hal_module_e module, handle_stack_msg cb);
 
-/* A2DP(SRC Role) Events*/
-void _bt_hal_register_av_event_handler_cb(handle_stack_msg cb);
-
-void _bt_hal_unregister_av_event_handler_cb();
-
-/* A2DP(SINK Role) Events */
-void _bt_hal_register_a2dp_sink_event_handler_cb(handle_stack_msg cb);
-
-void _bt_hal_unregister_a2dp_sink_event_handler_cb(void);
-
-/* HF(AG Role) Events*/
-void _bt_hal_register_hf_event_handler_cb(handle_stack_msg cb);
-
-void _bt_hal_unregister_hf_event_handler_cb();
-
-/* AVRCP Controller Role Events*/
-void _bt_hal_register_avrcp_ctrl_event_handler_cb(handle_stack_msg cb);
-
-void _bt_hal_unregister_avrcp_ctrl_event_handler_cb();
+void _bt_hal_unregister_event_handler_cb(bt_hal_module_e module);
 
 handle_stack_msg _bt_hal_get_stack_message_handler(void);
 
 int __bt_insert_hal_properties(void *buf, uint8_t type, uint16_t len, const void *val);
 
-/* AVRCP Target Role Events */
-void _bt_hal_register_avrcp_tg_event_handler_cb(handle_stack_msg cb);
-void _bt_hal_unregister_avrcp_tg_event_handler_cb(void);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 7a2f3e9..8c931f8 100644 (file)
@@ -183,7 +183,7 @@ static bt_status_t init(bthf_callbacks_t* callbacks, int max_hf_clients)
        bt_hal_hf_cbacks = callbacks;
        DBG("Register HF AG Role callback function");
        _bt_hal_register_hf_dbus_handler_cb(__bt_hal_handle_hf_events);
-       _bt_hal_register_hf_event_handler_cb(__bt_hal_handle_hf_events);
+       _bt_hal_register_event_handler_cb(HAL_HF_AG, __bt_hal_handle_hf_events);
        return BT_STATUS_SUCCESS;
 }
 
@@ -194,6 +194,7 @@ static void cleanup(void)
        if (!interface_ready())
                return;
 
+       _bt_hal_unregister_event_handler_cb(HAL_HF_AG);
        bt_hal_hf_cbacks = NULL;
 }
 
index 3bba559..2c9c84e 100644 (file)
@@ -232,7 +232,7 @@ static bt_status_t init(bthh_callbacks_t *callbacks)
        bt_hal_hid_cbacks = callbacks;
        DBG("Register HID events callback function");
        _bt_hal_register_hid_dbus_handler_cb(__bt_hal_handle_hid_events);
-       _bt_hal_register_hid_event_handler_cb(__bt_hal_handle_hid_events);
+       _bt_hal_register_event_handler_cb(HAL_HIDHOST, __bt_hal_handle_hid_events);
 
        return BT_STATUS_SUCCESS;
 }
@@ -245,7 +245,7 @@ static void cleanup(void)
                return;
 
        _bt_hal_unregister_hid_dbus_handler_cb();
-       _bt_hal_unregister_hid_event_handler_cb();
+       _bt_hal_unregister_event_handler_cb(HAL_HIDHOST);
 
        bt_hal_hid_cbacks = NULL;
 }