Fix removed event not occur issue while removing each service 10/233010/2
authorWootak Jung <wootak.jung@samsung.com>
Mon, 11 May 2020 08:12:14 +0000 (17:12 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Mon, 11 May 2020 08:17:29 +0000 (17:17 +0900)
InterfacesRemoved signal should be sent to "/com/%d" not "/".
Fix wrong interface name to DBus.ObjectManager from Dbus.Objectmanager

Change-Id: I14b1184b66229160c57908c4a8b7ccf2b904a5d0
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-server.c

index 3fc25d1..0df6ebd 100644 (file)
@@ -402,6 +402,24 @@ static GSList *_bt_get_service_list_from_server(int instance)
        return NULL;
 }
 
+static char *__bt_get_server_app_path_from_server(int instance)
+{
+       GSList *l;
+       INFO("Number of GATT Server apps [%d]", g_slist_length(gatt_server_apps));
+       INFO("Find App with slot [%d]", instance);
+
+       for (l = gatt_server_apps; l; l = g_slist_next(l)) {
+               struct gatt_server_app *app = (struct gatt_server_app *)l->data;
+
+               if (app->slot == instance) {
+                       INFO("App slot [%d] Found, App path [%s]",
+                                       app->slot, app->app_path);
+                       return app->app_path;
+               }
+       }
+       return NULL;
+}
+
 static void _bt_remote_service_from_gatt_server(int instance, int service_handle)
 {
        GSList *l;
@@ -1501,7 +1519,7 @@ done:
        g_dbus_method_invocation_return_value(invocation, NULL);
 }
 
-static gboolean __bt_hal_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
+static gboolean __bt_hal_gatt_emit_interface_removed(const char *app_path, gchar *object_path, gchar *interface)
 {
        gboolean ret;
        GError *error = NULL;
@@ -1511,8 +1529,8 @@ static gboolean __bt_hal_gatt_emit_interface_removed(gchar *object_path, gchar *
        g_variant_builder_init(array_builder, G_VARIANT_TYPE("as"));
        g_variant_builder_add(array_builder, "s", interface);
 
-       ret = g_dbus_connection_emit_signal(g_conn, NULL, "/",
-                       "org.freedesktop.Dbus.Objectmanager",
+       ret = g_dbus_connection_emit_signal(g_conn, NULL, app_path,
+                       "org.freedesktop.DBus.ObjectManager",
                        "InterfacesRemoved",
                        g_variant_new("(oas)",
                                object_path, array_builder),
@@ -2163,7 +2181,7 @@ static int __bt_hal_add_service_to_dbus(char *app_path, int slot, btgatt_srvc_id
                        GATT_SERV_INTERFACE, inner_builder);
 
        ret = g_dbus_connection_emit_signal(g_conn, NULL, "/",
-                       "org.freedesktop.Dbus.ObjectManager",
+                       "org.freedesktop.Dbus.ObjectManager", // TODO: need to check Dbus is working or not
                        "InterfacesAdded",
                        g_variant_new("(oa{sa{sv}})",
                                path, builder),
@@ -2335,10 +2353,8 @@ static void _bt_hal_update_gatt_server_path(int slot, char *app_path)
        app->slot = slot;
        gatt_server_apps = g_slist_append(gatt_server_apps, app);
        INFO("GATT Server: Path [%s] Slot [%d]-> Updated", app_path, slot);
-
 }
 
-
 static bt_status_t gatt_server_add_service(int server_if, btgatt_srvc_id_t *srvc_id,
                int num_handles)
 {
@@ -2900,6 +2916,7 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
        GSList *l1 = NULL;
        int err = BT_STATUS_SUCCESS;
        int ret = BT_STATUS_SUCCESS;
+       char *app_path = NULL;
        INFO("Slot [%d] service handle [%d]", server_if, service_handle);
 
        /* Fetch service data for the GATT server */
@@ -2910,6 +2927,13 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
                return BT_STATUS_FAIL;
        }
 
+       app_path = __bt_get_server_app_path_from_server(server_if);
+       if (app_path == NULL) {
+               ERR("Could not find service info svc handle [%d] server slot [%d]",
+                               service_handle, server_if);
+               return BT_STATUS_FAIL;
+       }
+
        if (serv_info->is_svc_registered == FALSE) {
                ERR("service Not registered path [%s] handle [%d]",
                        serv_info->serv_path, service_handle);
@@ -2931,6 +2955,7 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
                                        desc_info->desc_id);
                        if (ret) {
                                __bt_hal_gatt_emit_interface_removed(
+                                               app_path,
                                                desc_info->desc_path,
                                                GATT_DESC_INTERFACE);
                        } else {
@@ -2948,7 +2973,7 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
                ret = g_dbus_connection_unregister_object(g_conn,
                                char_info->char_id);
                if (ret) {
-                       __bt_hal_gatt_emit_interface_removed(char_info->char_path,
+                       __bt_hal_gatt_emit_interface_removed(app_path, char_info->char_path,
                                        GATT_CHAR_INTERFACE);
                } else {
                        INFO("Err");
@@ -2965,7 +2990,7 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
 
        ret = g_dbus_connection_unregister_object(g_conn, serv_info->serv_id);
        if (ret) {
-               __bt_hal_gatt_emit_interface_removed(serv_info->serv_path,
+               __bt_hal_gatt_emit_interface_removed(app_path, serv_info->serv_path,
                                GATT_SERV_INTERFACE);
        } else {
                INFO("Failed!!");