Send a gatt event to sender
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / gatt / bt-service-gatt.c
index e6460af..59c5867 100644 (file)
@@ -212,7 +212,6 @@ typedef struct {
 } bt_gatt_included_service_info_t;
 
 static GSList *list_gatt_info = NULL;
-
 #endif
 
 /* App Information structure */
@@ -892,6 +891,24 @@ int _bt_register_server_instance(const char *sender, int adv_handle)
 }
 
 /* Event handlers */
+static void __bt_gatt_get_pending_request_info(int service_function,
+               char **sender)
+{
+       GSList *l;
+       invocation_info_t *req_info = NULL;
+
+       for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+               req_info = l->data;
+               if (req_info == NULL)
+                       continue;
+
+               if (req_info->service_function == service_function) {
+                       *sender = req_info->sender;
+                       break;
+               }
+       }
+}
+
 static void __bt_gatt_handle_pending_request_info(int result,
                int service_function, void *data, unsigned int size)
 {
@@ -3629,7 +3646,9 @@ Note: Even in case of failure, address, handles and result code should be return
                                data);
 
                /* Send Event */
-               _bt_send_event(BT_GATT_CLIENT_EVENT,
+               char *sender = NULL;
+               __bt_gatt_get_pending_request_info(BT_GATT_READ_CHARACTERISTIC, &sender);
+               _bt_send_event_to_dest(sender, BT_GATT_CLIENT_EVENT,
                                BLUETOOTH_EVENT_GATT_READ_CHAR,
                                param);
        }
@@ -3674,7 +3693,7 @@ static void __bt_handle_client_descriptor_read_data(
        conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
                        event_data->uuid_status.conn_status.conn_id);
 
-       BT_INFO("Descriptor Read result from addr [%s] status [%d]",
+       BT_DBG("Descriptor Read result from addr [%s] status [%d]",
                        conn_info->addr, event_data->uuid_status.conn_status.status);
 
        /* Fill descriptor informations in buffer */
@@ -3699,7 +3718,6 @@ static void __bt_handle_client_descriptor_read_data(
        if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
                result = BLUETOOTH_ERROR_INTERNAL;
        else {
-               BT_INFO("desc data len:%d", event_data->data_len);
                if (event_data->data_len > 0) {
                        /* DEBUG */
                        for (i = 0; i < event_data->data_len; i++)
@@ -3764,11 +3782,13 @@ static void __bt_handle_client_descriptor_read_data(
                                data);
 
                /* Send Event */
-               _bt_send_event(BT_GATT_CLIENT_EVENT,
+               char *sender = NULL;
+               __bt_gatt_get_pending_request_info(BT_GATT_READ_DESCRIPTOR_VALUE, &sender);
+               _bt_send_event_to_dest(sender, BT_GATT_CLIENT_EVENT,
                                        BLUETOOTH_EVENT_GATT_READ_DESC,
                                        param);
        }
-       BT_INFO("Send DBUS rpely for GATT Read Descriptor");
+
        /* Send DBUS return */
        __bt_gatt_handle_pending_request_info(result,
                        BT_GATT_READ_DESCRIPTOR_VALUE,
@@ -3855,7 +3875,9 @@ static void __bt_handle_client_characteristic_write_data(
                        event_data->char_id.inst_id);
 
        /* Send Event */
-       _bt_send_event(BT_GATT_CLIENT_EVENT,
+       char *sender = NULL;
+       __bt_gatt_get_pending_request_info(BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE, &sender);
+       _bt_send_event_to_dest(sender, BT_GATT_CLIENT_EVENT,
                        BLUETOOTH_EVENT_GATT_WRITE_CHAR,
                        param);
 
@@ -3864,6 +3886,7 @@ static void __bt_handle_client_characteristic_write_data(
                g_free(svc_uuid);
        if (char_uuid)
                g_free(char_uuid);
+
 done:
        /* Send DBUS return */
        __bt_gatt_handle_pending_request_info(result,
@@ -3901,7 +3924,7 @@ static void __bt_handle_client_descriptor_write_data(
                return;
        }
 
-       BT_INFO("Descriptor Write callback from addr [%s] status [%d]",
+       BT_DBG("Descriptor Write callback from addr [%s] status [%d]",
                        conn_info->addr, event_data->conn_status.status);
 
        /* Fill descriptor informations in buffer */
@@ -3968,7 +3991,9 @@ static void __bt_handle_client_descriptor_write_data(
                        event_data->descr_id.inst_id);
 
        /* Send Event */
-       _bt_send_event(BT_GATT_CLIENT_EVENT,
+       char *sender = NULL;
+       __bt_gatt_get_pending_request_info(BT_GATT_WRITE_DESCRIPTOR_VALUE, &sender);
+       _bt_send_event_to_dest(sender, BT_GATT_CLIENT_EVENT,
                        BLUETOOTH_EVENT_GATT_WRITE_DESC,
                        param);