[glib] Add G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE



commit 71088701af6ff0658313069219565923d5a03280
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Nov 5 22:07:07 2010 -0400

    Add G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE
    
    If specified, the signal subscription is setup client-side but the match
    rule is not sent to the server.  This allows the caller to manually
    register more detailed match rules.

 gio/gdbusconnection.c |   22 ++++++++++++++++++++--
 gio/gioenums.h        |    6 +++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index ef70031..7c6a2d0 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -2977,11 +2977,14 @@ args_to_rule (const gchar *sender,
               const gchar *interface_name,
               const gchar *member,
               const gchar *object_path,
-              const gchar *arg0)
+              const gchar *arg0,
+              gboolean     negate)
 {
   GString *rule;
 
   rule = g_string_new ("type='signal'");
+  if (negate)
+    g_string_prepend_c (rule, '-');
   if (sender != NULL)
     g_string_append_printf (rule, ",sender='%s'", sender);
   if (interface_name != NULL)
@@ -3010,6 +3013,9 @@ add_match_rule (GDBusConnection *connection,
   GError *error;
   GDBusMessage *message;
 
+  if (match_rule[0] == '-')
+    return;
+
   message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
                                             "/org/freedesktop/DBus", /* path */
                                             "org.freedesktop.DBus", /* interface */
@@ -3038,6 +3044,9 @@ remove_match_rule (GDBusConnection *connection,
   GError *error;
   GDBusMessage *message;
 
+  if (match_rule[0] == '-')
+    return;
+
   message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
                                             "/org/freedesktop/DBus", /* path */
                                             "org.freedesktop.DBus", /* interface */
@@ -3141,7 +3150,16 @@ g_dbus_connection_signal_subscribe (GDBusConnection     *connection,
 
   CONNECTION_LOCK (connection);
 
-  rule = args_to_rule (sender, interface_name, member, object_path, arg0);
+  /* If G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE was specified, we will end up
+   * with a '-' character to prefix the rule (which will otherwise be
+   * normal).
+   *
+   * This allows us to hash the rule and do our lifecycle tracking in
+   * the usual way, but the '-' prevents the match rule from ever
+   * actually being send to the bus (either for add or remove).
+   */
+  rule = args_to_rule (sender, interface_name, member, object_path, arg0,
+                       (flags & G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE) != 0);
 
   if (sender != NULL && (g_dbus_is_unique_name (sender) || g_strcmp0 (sender, "org.freedesktop.DBus") == 0))
     sender_unique_name = sender;
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 121f54c..d534eed 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -1157,6 +1157,9 @@ typedef enum
 /**
  * GDBusSignalFlags:
  * @G_DBUS_SIGNAL_FLAGS_NONE: No flags set.
+ * @G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE: Don't actually send the AddMatch
+ * DBus call for this signal subscription.  This gives you more control
+ * over which match rules you add (but you must add them manually).
  *
  * Flags used when subscribing to signals via g_dbus_connection_signal_subscribe().
  *
@@ -1164,7 +1167,8 @@ typedef enum
  */
 typedef enum /*< flags >*/
 {
-  G_DBUS_SIGNAL_FLAGS_NONE = 0
+  G_DBUS_SIGNAL_FLAGS_NONE = 0,
+  G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE = (1<<0)
 } GDBusSignalFlags;
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]