gatt-client : Notify service added event after chrcs. ready 09/126009/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Wed, 19 Apr 2017 07:27:31 +0000 (16:27 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Thu, 20 Apr 2017 00:47:56 +0000 (09:47 +0900)
[Model] COMMON
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] Sometimes application couldn't get characteristic when it
 receives service added event and tries to get characteristic.
[Cause & Measure] chrcs_ready is set after extended properties
 descriptor is discovered. But service added event is sent before. This
 patch sends service added event after chrcs_ready is set.
[Checking Method] Get characteristic when GattServiceAdded signal is
 received.

[Team] Basic connection
[Developer] Seungyoun Ju
[Solution company] Samsung
[Change Type] Specification change

Change-Id: If42135fa637a17c98bb3b3b1d7042375ad55f455

src/gatt-client.c

index 87e363c..4530426 100644 (file)
@@ -77,9 +77,6 @@ struct service {
        bool chrcs_ready;
        struct queue *pending_ext_props;
        guint idle_id;
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       guint idle_id2;
-#endif
 };
 
 struct characteristic {
@@ -1783,17 +1780,44 @@ static void unregister_service(void *data)
        if (service->idle_id)
                g_source_remove(service->idle_id);
 
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       if (service->idle_id2)
-               g_source_remove(service->idle_id2);
-#endif
-
        queue_remove_all(service->chrcs, NULL, NULL, unregister_characteristic);
 
        g_dbus_unregister_interface(btd_get_dbus_connection(), service->path,
                                                        GATT_SERVICE_IFACE);
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+static void notify_service_added(struct service *service)
+{
+       char *svc_path;
+
+       if (service == NULL) {
+               error("service is NULL");
+               return;
+       }
+
+       if (service->path == NULL) {
+               error("service->path is NULL");
+               return;
+       }
+       if (!service->chrcs_ready) {
+               error("service is not ready");
+               return;
+       }
+
+       svc_path = g_strdup(service->path);
+
+       g_dbus_emit_signal(btd_get_dbus_connection(), service->path,
+               GATT_SERVICE_IFACE, "GattServiceAdded",
+               DBUS_TYPE_STRING, &svc_path,
+               DBUS_TYPE_INVALID);
+
+       g_free(svc_path);
+
+       return;
+}
+#endif
+
 static void notify_chrcs(struct service *service)
 {
 
@@ -1806,6 +1830,12 @@ static void notify_chrcs(struct service *service)
        g_dbus_emit_property_changed(btd_get_dbus_connection(), service->path,
                                                        GATT_SERVICE_IFACE,
                                                        "Characteristics");
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (service->primary == true) {
+               DBG("Notify Service Added");
+               notify_service_added(service);
+       }
+#endif
 }
 
 struct export_data {
@@ -1953,28 +1983,6 @@ static gboolean set_chrcs_ready(gpointer user_data)
        return FALSE;
 }
 
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-static gboolean notify_service_added_complete(gpointer user_data)
-{
-       struct service *service = user_data;
-       char *svc_path;
-
-       if (service == NULL || service->path == NULL)
-               return FALSE;
-
-       svc_path = g_strdup(service->path);
-
-       g_dbus_emit_signal(btd_get_dbus_connection(), service->path,
-               GATT_SERVICE_IFACE, "GattServiceAdded",
-               DBUS_TYPE_STRING, &svc_path,
-               DBUS_TYPE_INVALID);
-
-       g_free(svc_path);
-
-       return FALSE;
-}
-#endif
-
 static void export_service(struct gatt_db_attribute *attr, void *user_data)
 {
        struct btd_gatt_client *client = user_data;
@@ -2002,11 +2010,6 @@ static void export_service(struct gatt_db_attribute *attr, void *user_data)
         */
        if (!service->chrcs_ready && queue_isempty(service->pending_ext_props))
                service->idle_id = g_idle_add(set_chrcs_ready, service);
-
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       if (service->primary == true)
-               service->idle_id2 = g_idle_add(notify_service_added_complete, service);
-#endif
 }
 
 static void create_services(struct btd_gatt_client *client)