kdbus: Fixup signal subscription 38/317638/2 accepted/tizen_unified_dev accepted/tizen/unified/20240913.042637 accepted/tizen/unified/dev/20240919.040422 accepted/tizen/unified/toolchain/20241004.101647 accepted/tizen/unified/x/20240913.062839
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 12 Sep 2024 12:31:37 +0000 (14:31 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 12 Sep 2024 14:13:49 +0000 (16:13 +0200)
This commit fixes DBus signal subscription, which was originally
added in commit 069c264bb65a ("tizen: kdbus: Add kdbus") and not
fully fixed in bacfcf05cd09 ("tizen: kdbus: Integrate into Tizen build").

Change-Id: I04d98cc86669853f0b31219ae0342c900275bea9

gio/gdbusconnection.c

index a24ceb6..767ef01 100755 (executable)
@@ -4628,6 +4628,63 @@ is_signal_data_for_name_lost_or_acquired (SignalData *signal_data)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+add_signal_data_kdbus (GDBusConnection *connection,
+                       SignalData      *signal_data,
+                       const char      *sender_unique_name)
+{
+#ifdef G_OS_UNIX
+#ifdef KDBUS
+
+  if (!connection->kdbus_worker)
+     return;
+
+  gboolean special_rule = FALSE;
+  /* rule for special message */
+  if (!sender_unique_name || g_strcmp0 (sender_unique_name, "org.freedesktop.DBus") == 0)
+    {
+       if (sender_unique_name) /* So, this is org.freedesktop.DBus */
+         special_rule = TRUE;
+
+       if (!signal_data->object_path || g_strcmp0 (signal_data->object_path, "/org/freedesktop/DBus") == 0)
+         {
+           if (!signal_data->interface_name || g_strcmp0 (signal_data->interface_name, "org.freedesktop.DBus") == 0)
+             {
+               /* By https://dbus.freedesktop.org/doc/dbus-specification.html, org.freedesktop.DBus
+                * has three signal types: NameAcquired, NameLost, NameOwnerChanged (all covered below).
+                *
+                * 1. if sender is NULL and other parameters are matched with special rule, add BOTH special and standard,
+                *   - (NULL, NULL or DBUS, NULL or DBUS, NULL or Special Name)
+                *
+                *    if other parameters are NOT matched with special rule, add standard rule
+                *   - (NULL, X, X, "NotSpecial")
+                *
+                * 2. if sender is 'org.freedesktop.DBus' and other parameters are matched with special rule, add special rule
+                *   - (org.freedesktop.DBus, NULL or DBUS, NULL or DBUS, NULL or Special Name)
+                *
+                *    if other parameters are NOT matched with special rule, then ignore
+                *   - (org.freedesktop.DBus, X, X, "NotSpecial")
+                *
+                * for every other cases, add standard rule,
+                */
+               if (g_strcmp0 (signal_data->member, "NameAcquired") == 0)
+                 _g_kdbus_subscribe_name_acquired (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
+               else if (g_strcmp0 (signal_data->member, "NameLost") == 0)
+                 _g_kdbus_subscribe_name_lost (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
+               else if (!signal_data->member || g_strcmp0 (signal_data->member, "NameOwnerChanged") == 0)
+                 _g_kdbus_subscribe_name_owner_changed (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
+             }
+         }
+    }
+
+  /* standard rule */
+  if (!special_rule)
+    _g_kdbus_AddMatch (connection->kdbus_worker, signal_data->rule, NULL);
+
+#endif
+#endif
+}
+
 /* called in any thread, connection lock is held */
 static void
 add_signal_data (GDBusConnection *connection,
@@ -4647,55 +4704,14 @@ add_signal_data (GDBusConnection *connection,
    */
   if (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)
     {
-      if (!is_signal_data_for_name_lost_or_acquired (signal_data))
-        add_match_rule (connection, signal_data->rule);
-    }
-#ifdef G_OS_UNIX
-#ifdef KDBUS
-  else if (connection->kdbus_worker)
-    {
-      gboolean special_rule = FALSE;
-      /* rule for special message */
-      if (!sender_unique_name || g_strcmp0 (sender_unique_name, "org.freedesktop.DBus") == 0)
+      if (connection->worker)
         {
-          if (sender_unique_name)      /* So, this is org.freedesktop.DBus */
-            special_rule = TRUE;
-          if (!signal_data->object_path || g_strcmp0 (signal_data->object_path, "/org/freedesktop/DBus") == 0)
-            {
-              if (!signal_data->interface_name || g_strcmp0 (signal_data->interface_name, "org.freedesktop.DBus") == 0)
-                {
-                  /* By https://dbus.freedesktop.org/doc/dbus-specification.html, org.freedesktop.DBus
-                   * has three signal types: NameAcquired, NameLost, NameOwnerChanged (all covered below).
-                   *
-                   * 1. if sender is NULL and other parameters are matched with special rule, add BOTH special and standard,
-                   *   - (NULL, NULL or DBUS, NULL or DBUS, NULL or Special Name)
-                   *
-                   *    if other parameters are NOT matched with special rule, add standard rule
-                   *   - (NULL, X, X, "NotSpecial")
-                   *
-                   * 2. if sender is 'org.freedesktop.DBus' and other parameters are matched with special rule, add special rule
-                   *   - (org.freedesktop.DBus, NULL or DBUS, NULL or DBUS, NULL or Special Name)
-                   *
-                   *    if other parameters are NOT matched with special rule, then ignore
-                   *   - (org.freedesktop.DBus, X, X, "NotSpecial")
-                   *
-                   * for every other cases, add standard rule,
-                   */
-                  if (g_strcmp0 (signal_data->member, "NameAcquired") == 0)
-                    _g_kdbus_subscribe_name_acquired (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
-                  else if (g_strcmp0 (signal_data->member, "NameLost") == 0)
-                    _g_kdbus_subscribe_name_lost (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
-                  else if (!signal_data->member || g_strcmp0 (signal_data->member, "NameOwnerChanged") == 0)
-                    _g_kdbus_subscribe_name_owner_changed (connection->kdbus_worker, signal_data->rule, signal_data->arg0, NULL);
-                }
-            }
+          if (!is_signal_data_for_name_lost_or_acquired (signal_data))
+            add_match_rule (connection, signal_data->rule);
         }
-        /* standard rule */
-        if (!special_rule)
-          _g_kdbus_AddMatch (connection->kdbus_worker, signal_data->rule, NULL);
+      else
+        add_signal_data_kdbus(connection, signal_data, sender_unique_name);
     }
-#endif
-#endif
 
   signal_data_array = g_hash_table_lookup (connection->map_sender_unique_name_to_signal_data_array,
                                            sender_unique_name);