[Adapt:FRWK] Add API to register custom event handler 08/117408/1
authorAtul Rai <a.rai@samsung.com>
Fri, 3 Mar 2017 06:06:59 +0000 (11:36 +0530)
committerAtul Rai <a.rai@samsung.com>
Mon, 6 Mar 2017 04:24:53 +0000 (09:54 +0530)
Change-Id: I7b55755807e0716ccab26116f0a20911d8214a3e
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-api/bt-event-handler.c
bt-api/include/bt-event-handler.h

index 95bce78..2551c61 100644 (file)
@@ -241,7 +241,7 @@ static int __bt_call_list_add(bt_hf_call_list_s *list, char * number,
        return BLUETOOTH_ERROR_NONE;
 }
 
-static bluetooth_device_info_t *__bt_get_device_info_in_message(GVariant *parameters, int *ret)
+bluetooth_device_info_t *_bt_get_device_info_in_message(GVariant *parameters, int *ret)
 {
        bluetooth_device_info_t *dev_info;
        const char *address = NULL;
@@ -586,7 +586,7 @@ void __bt_adapter_event_filter(GDBusConnection *connection,
                int event;
                bluetooth_device_info_t *device_info;
 
-               device_info = __bt_get_device_info_in_message(parameters,
+               device_info = _bt_get_device_info_in_message(parameters,
                                                                &result);
                ret_if(device_info == NULL);
 
@@ -603,7 +603,7 @@ void __bt_adapter_event_filter(GDBusConnection *connection,
        } else if (strcasecmp(signal_name, BT_BOND_CREATED) == 0) {
                bluetooth_device_info_t *device_info;
 
-               device_info = __bt_get_device_info_in_message(parameters,
+               device_info = _bt_get_device_info_in_message(parameters,
                                                                &result);
                ret_if(device_info == NULL);
 
@@ -628,7 +628,7 @@ void __bt_adapter_event_filter(GDBusConnection *connection,
                bluetooth_device_info_t *device_info;
                bt_sdp_info_t sdp_info;
 
-               device_info = __bt_get_device_info_in_message(parameters,
+               device_info = _bt_get_device_info_in_message(parameters,
                                                                &result);
                ret_if(device_info == NULL);
 
@@ -2832,13 +2832,16 @@ static void __bt_event_data_free(void *data)
        g_free(cb_data);
 }
 
-int _bt_register_event(int event_type, void *event_cb, void *user_data)
+int _bt_register_event_custom(int event_type, const char *path, const char *interface,
+               GDBusSignalCallback event_func, void *event_cb, void *user_data)
 {
        GDBusConnection *connection_type;
-       GDBusSignalCallback event_func;
        bt_event_info_t *cb_data;
-       const char *path;
-       const char *interface = BT_EVENT_SERVICE;
+
+       retv_if(NULL == path, BLUETOOTH_ERROR_INVALID_PARAM);
+       retv_if(NULL == interface, BLUETOOTH_ERROR_INVALID_PARAM);
+       retv_if(NULL == event_func, BLUETOOTH_ERROR_INVALID_PARAM);
+       retv_if(NULL == event_cb, BLUETOOTH_ERROR_INVALID_PARAM);
 
        if (is_initialized == FALSE)
                _bt_init_event_handler();
@@ -2848,6 +2851,36 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
        }
 
+       connection_type = _bt_gdbus_get_system_gconn();
+       if (connection_type == NULL)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       cb_data = g_new0(bt_event_info_t, 1);
+
+       cb_data->event_type = event_type;
+       cb_data->cb = event_cb;
+       cb_data->user_data = user_data;
+
+       cb_data->id = g_dbus_connection_signal_subscribe(connection_type,
+                               NULL, interface, NULL, path, NULL, 0,
+                               event_func, cb_data, NULL);
+
+       event_list = g_slist_append(event_list, cb_data);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_register_event(int event_type, void *event_cb, void *user_data)
+{
+       GDBusSignalCallback event_func;
+       const char *path;
+       const char *interface = BT_EVENT_SERVICE;
+
+       if (__bt_event_is_registered(event_type) == TRUE) {
+               BT_ERR("The event is already registed");
+               return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+       }
+
        switch (event_type) {
        case BT_ADAPTER_EVENT:
                event_func = __bt_adapter_event_filter;
@@ -2935,23 +2968,8 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       connection_type = _bt_gdbus_get_system_gconn();
-       if (connection_type == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
-
-       cb_data = g_new0(bt_event_info_t, 1);
-
-       cb_data->event_type = event_type;
-       cb_data->cb = event_cb;
-       cb_data->user_data = user_data;
-
-       cb_data->id = g_dbus_connection_signal_subscribe(connection_type,
-                               NULL, interface, NULL, path, NULL, 0,
-                               event_func, cb_data, NULL);
-
-       event_list = g_slist_append(event_list, cb_data);
-
-       return BLUETOOTH_ERROR_NONE;
+       return _bt_register_event_custom(event_type, path,
+                       interface, event_func, event_cb, user_data);
 }
 
 int _bt_unregister_event(int event_type)
index 72c178f..c53b176 100755 (executable)
@@ -42,6 +42,9 @@ int _bt_init_event_handler(void);
 
 int _bt_deinit_event_handler(void);
 
+int _bt_register_event_custom(int event_type, const char *path, const char *interface,
+               GDBusSignalCallback event_func, void *event_cb, void *user_data);
+
 int _bt_register_event(int event_type, void *event_cb, void *user_data);
 
 int _bt_unregister_event(int event_type);
@@ -68,6 +71,8 @@ int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr);
 
 int new_hid_connection(const char *path, int fd, bluetooth_device_address_t *addr);
 
+bluetooth_device_info_t *_bt_get_device_info_in_message(GVariant *parameters, int *ret);
+
 #ifdef __cplusplus
 }
 #endif