Invoke callback function after all internal work is done 26/191626/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Fri, 19 Oct 2018 05:59:42 +0000 (14:59 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Fri, 19 Oct 2018 05:59:42 +0000 (14:59 +0900)
 - Prevent to access freed service after GATT is destroyed in callback function

Change-Id: I8aa33c48cdcf246578552a58aaa2cad7a94a589c
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-api/bt-gatt-service.c

index 724780e..2f18238 100644 (file)
@@ -977,10 +977,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                req_info->context = invocation;
                gatt_requests = g_slist_append(gatt_requests, req_info);
 
-               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
-                                       BLUETOOTH_ERROR_NONE, &read_req,
-                                       user_info->cb, user_info->user_data);
-
 #if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
                param = g_variant_new("(sssyq)",
                                read_req.att_handle,
@@ -995,6 +991,10 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
 #endif
 #endif
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
+                                       BLUETOOTH_ERROR_NONE, &read_req,
+                                       user_info->cb, user_info->user_data);
                return;
        } else if (g_strcmp0(method_name, "WriteValue") == 0) {
                GVariant *var = NULL;
@@ -1072,11 +1072,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                        g_object_unref(invocation);
                }
 
-               _bt_common_event_cb(
-                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
-                       BLUETOOTH_ERROR_NONE, &value_change,
-                       user_info->cb, user_info->user_data);
-
 #if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
                if (len > 0) {
                        gchar *svc_path;
@@ -1099,6 +1094,11 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                }
 #endif
 
+               _bt_common_event_cb(
+                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                       BLUETOOTH_ERROR_NONE, &value_change,
+                       user_info->cb, user_info->user_data);
+
                g_free(value_change.att_value);
                g_variant_unref(var);
                return;
@@ -1117,10 +1117,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.service_handle = svc_info->serv_path;
                                notify_change.att_handle = (char *)object_path;
                                notify_change.att_notify = TRUE;
-                               _bt_common_event_cb(
-                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
-                                       BLUETOOTH_ERROR_NONE, &notify_change,
-                                       user_info->cb, user_info->user_data);
 #if TIZEN_FEATURE_BT_OTP
                                param = g_variant_new("(ssb)",
                                notify_change.att_handle,
@@ -1128,6 +1124,10 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.att_notify);
                                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
 #endif
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
                        }
                }
                g_object_unref(invocation);
@@ -1147,10 +1147,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.service_handle = svc_info->serv_path;
                                notify_change.att_handle = (char *)object_path;
                                notify_change.att_notify = FALSE;
-                               _bt_common_event_cb(
-                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
-                                       BLUETOOTH_ERROR_NONE, &notify_change,
-                                       user_info->cb, user_info->user_data);
 #if TIZEN_FEATURE_BT_OTP
                                param = g_variant_new("(ssb)",
                                notify_change.att_handle,
@@ -1158,6 +1154,10 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.att_notify);
                                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
 #endif
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
                        }
                }
                g_object_unref(invocation);