From: Deokhyun Kim Date: Fri, 19 Oct 2018 05:59:42 +0000 (+0900) Subject: Invoke callback function after all internal work is done X-Git-Tag: accepted/tizen/unified/20181107.081858~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git;a=commitdiff_plain;h=438df06a0ca0132254c5c0d5c073ffcf6fc3a37d Invoke callback function after all internal work is done - Prevent to access freed service after GATT is destroyed in callback function Change-Id: I8aa33c48cdcf246578552a58aaa2cad7a94a589c Signed-off-by: Deokhyun Kim --- diff --git a/bt-api/bt-gatt-service.c b/bt-api/bt-gatt-service.c index 724780e..2f18238 100644 --- a/bt-api/bt-gatt-service.c +++ b/bt-api/bt-gatt-service.c @@ -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, ¬ify_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, ¬ify_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, ¬ify_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, ¬ify_change, + user_info->cb, user_info->user_data); } } g_object_unref(invocation);