Adding Glib GMainContext support to DBusGlib Bindings

Marcus Nascimento marcus.cps at gmail.com
Fri Mar 11 05:24:21 PST 2011


Hi,

I've been having some trouble running dbus glib (server or client) on a
GMainContext other than the default one.
So I made a few changes to the code and it seems to be working well.
This is based on the 0.76-4 version.
I believe that would be interesting to make this changes available to other
users.

Can anyone check whether the following diff output fits?
Thanks.

--- ./dbus/dbus-glib.h 2008-05-14 07:21:15.000000000 -0300
+++ ./dbusPatched/dbus-glib.h 2011-03-11 10:21:37.246480524 -0300
@@ -101,10 +101,16 @@

 void             dbus_g_thread_init (void);

-DBusGConnection* dbus_g_connection_open (const gchar  *address,
-                                         GError      **error);
-DBusGConnection* dbus_g_bus_get         (DBusBusType   type,
-                                         GError      **error);
+DBusGConnection* dbus_g_connection_open_with_context (const gchar
*address,
+      GMainContext  *context,
+      GError        **error);
+DBusGConnection* dbus_g_connection_open     (const gchar   *address,
+      GError        **error);
+DBusGConnection* dbus_g_bus_get_with_context     (DBusBusType   type,
+      GMainContext  *context,
+      GError        **error);
+DBusGConnection* dbus_g_bus_get     (DBusBusType   type,
+      GError        **error);

 typedef struct _DBusGObjectInfo DBusGObjectInfo;
 typedef struct _DBusGMethodInfo DBusGMethodInfo;


--- ./dbus/dbus-gmain.c 2008-05-14 07:21:15.000000000 -0300
+++ ./dbusPatched/dbus-gmain.c 2011-03-11 10:19:13.457478007 -0300
@@ -689,6 +689,7 @@
 /**
  * dbus_g_connection_open:
  * @address: address of the connection to open
+ * @context: the #GMainContext or #NULL for default context
  * @error: address where an error can be returned.
  *
  * Returns a connection to the given address.
@@ -699,8 +700,9 @@
  * Returns: a DBusConnection
  */
 DBusGConnection*
-dbus_g_connection_open (const gchar  *address,
-                        GError      **error)
+dbus_g_connection_open_with_context (const gchar    *address,
+     GMainContext   *context,
+     GError        **error)
 {
   DBusConnection *connection;
   DBusError derror;
@@ -720,14 +722,33 @@
     }

   /* does nothing if it's already been done */
-  dbus_connection_setup_with_g_main (connection, NULL);
+  dbus_connection_setup_with_g_main (connection, context);

   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
 }

 /**
+ * dbus_g_connection_open:
+ * @address: address of the connection to open
+ * @error: address where an error can be returned.
+ *
+ * Returns a connection to the given address.
+ *
+ * Wrapper to a more general dbus_g_connection_open.
+ *
+ * Returns: a DBusConnection
+ */
+DBusGConnection*
+dbus_g_connection_open (const gchar  *address,
+                        GError      **error)
+{
+  return dbus_g_connection_open_with_context (address, NULL, error);
+}
+
+/**
  * dbus_g_bus_get:
  * @type: bus type
+ * @context: the #GMainContext or #NULL for default context
  * @error: address where an error can be returned.
  *
  * Returns a connection to the given bus. The connection is a global
variable
@@ -739,8 +760,9 @@
  * Returns: a DBusConnection
  */
 DBusGConnection*
-dbus_g_bus_get (DBusBusType     type,
-                GError        **error)
+dbus_g_bus_get_with_context (DBusBusType     type,
+     GMainContext   *context,
+     GError        **error)
 {
   DBusConnection *connection;
   DBusError derror;
@@ -760,11 +782,30 @@
     }

   /* does nothing if it's already been done */
-  dbus_connection_setup_with_g_main (connection, NULL);
+  dbus_connection_setup_with_g_main (connection, context);

   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
 }

+/**
+ * dbus_g_bus_get:
+ * @type: bus type
+ * @error: address where an error can be returned.
+ *
+ * Returns a connection to the given bus. The connection is a global
variable
+ * shared with other callers of this function.
+ *
+ * Wrapper to a more general dbus_g_bus_get.
+ *
+ * Returns: a DBusConnection
+ */
+DBusGConnection*
+dbus_g_bus_get (DBusBusType     type,
+                GError        **error)
+{
+  return dbus_g_bus_get_with_context (type, NULL, error);
+}
+
 /** @} */ /* end of public API */

 #ifdef DBUS_BUILD_TESTS


-- 
Marcus Nascimento
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20110311/3a4582b9/attachment.htm>


More information about the dbus mailing list