dbus/glib dbus-glib.h,1.10,1.11 dbus-gmain.c,1.23,1.24 dbus-gproxy.c,1.2,1.3

Havoc Pennington hp@pdx.freedesktop.org
Thu, 02 Oct 2003 20:55:37 -0700


Update of /cvs/dbus/dbus/glib
In directory pdx:/tmp/cvs-serv29624/glib

Modified Files:
	dbus-glib.h dbus-gmain.c dbus-gproxy.c 
Log Message:
2003-10-02  Havoc Pennington  <hp@pobox.com>

	* glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): rename from
	dbus_gproxy_oneway_call

	* glib/dbus-gmain.c (dbus_connection_setup_with_g_main) 
	(dbus_server_setup_with_g_main): fix to allow calling them more
	than once on the same args
	(dbus_bus_get_with_g_main): new function



Index: dbus-glib.h
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-glib.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dbus-glib.h	30 Sep 2003 02:32:57 -0000	1.10
+++ dbus-glib.h	3 Oct 2003 03:55:35 -0000	1.11
@@ -51,11 +51,13 @@
 void dbus_set_g_error (GError   **gerror,
                        DBusError *derror);
 
-void dbus_g_thread_init                (void);
-void dbus_connection_setup_with_g_main (DBusConnection *connection,
-					GMainContext   *context);
-void dbus_server_setup_with_g_main     (DBusServer     *server,
-					GMainContext   *context);
+void            dbus_g_thread_init                (void);
+void            dbus_connection_setup_with_g_main (DBusConnection  *connection,
+                                                   GMainContext    *context);
+void            dbus_server_setup_with_g_main     (DBusServer      *server,
+                                                   GMainContext    *context);
+DBusConnection* dbus_bus_get_with_g_main          (DBusBusType      type,
+                                                   GError         **error);
 
 typedef struct DBusGObjectInfo DBusGObjectInfo;
 typedef struct DBusGMethodInfo DBusGMethodInfo;
@@ -137,7 +139,7 @@
                                                     GError                  **error,
                                                     int                       first_arg_type,
                                                     ...);
-void             dbus_gproxy_oneway_call           (DBusGProxy               *proxy,
+void             dbus_gproxy_call_no_reply         (DBusGProxy               *proxy,
                                                     const char               *method,
                                                     int                       first_arg_type,
                                                     ...);

Index: dbus-gmain.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gmain.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- dbus-gmain.c	30 Sep 2003 02:32:57 -0000	1.23
+++ dbus-gmain.c	3 Oct 2003 03:55:35 -0000	1.24
@@ -443,6 +443,11 @@
  * Pass in #NULL for the #GMainContext unless you're
  * doing something specialized.
  *
+ * If called twice for the same context, does nothing the second
+ * time. If called once with context A and once with context B,
+ * context B replaces context A as the context monitoring the
+ * connection.
+ *
  * @param connection the connection
  * @param context the #GMainContext or #NULL for default context
  */
@@ -451,7 +456,29 @@
 				   GMainContext   *context)
 {
   GSource *source;
+  
+  /* FIXME we never free the slot, so its refcount just keeps growing,
+   * which is kind of broken.
+   */
+  dbus_connection_allocate_data_slot (&connection_slot);
+  if (connection_slot < 0)
+    goto nomem;
 
+  /* So we can test for equality below */
+  if (context == NULL)
+    context = g_main_context_default ();
+  
+  source = dbus_connection_get_data (connection, connection_slot);
+  if (source != NULL)
+    {
+      if (source->context == context)
+        return; /* nothing to do */
+
+      /* Remove the previous source and move to a new context */
+      dbus_connection_set_data (connection, connection_slot, NULL, NULL);
+      source = NULL;
+    }
+  
   source = create_source (connection, &dbus_connection_funcs, context);
 
   if (!dbus_connection_set_watch_functions (connection,
@@ -474,13 +501,6 @@
       
   g_source_attach (source, context);
 
-  /* FIXME we never free the slot, so its refcount just keeps growing,
-   * which is kind of broken.
-   */
-  dbus_connection_allocate_data_slot (&connection_slot);
-  if (connection_slot < 0)
-    goto nomem;
-
   if (!dbus_connection_set_data (connection, connection_slot, source,
                                  (DBusFreeFunction)free_source))
     goto nomem;
@@ -496,6 +516,11 @@
  * to integrate the server with the GLib main loop.
  * In most cases the context argument should be #NULL.
  *
+ * If called twice for the same context, does nothing the second
+ * time. If called once with context A and once with context B,
+ * context B replaces context A as the context monitoring the
+ * connection.
+ *
  * @param server the server
  * @param context the #GMainContext or #NULL for default
  */
@@ -505,6 +530,25 @@
 {
   GSource *source;
 
+  dbus_server_allocate_data_slot (&server_slot);
+  if (server_slot < 0)
+    goto nomem;
+
+  /* So we can test for equality below */
+  if (context == NULL)
+    context = g_main_context_default ();
+  
+  source = dbus_server_get_data (server, server_slot);
+  if (source != NULL)
+    {
+      if (source->context == context)
+        return; /* nothing to do */
+
+      /* Remove the previous source and move to a new context */
+      dbus_server_set_data (server, server_slot, NULL, NULL);
+      source = NULL;
+    }
+  
   source = create_source (server, &dbus_server_funcs, context);
 
   dbus_server_set_watch_functions (server,
@@ -521,13 +565,6 @@
   
   g_source_attach (source, context);
 
-  /* FIXME we never free the slot, so its refcount just keeps growing,
-   * which is kind of broken.
-   */
-  dbus_server_allocate_data_slot (&server_slot);
-  if (server_slot < 0)
-    goto nomem;
-
   if (!dbus_server_set_data (server, server_slot, source,
                              (DBusFreeFunction)free_source))
     goto nomem;
@@ -539,6 +576,40 @@
 }
 
 /**
+ * Calls dbus_bus_get() then calls dbus_connection_setup_with_g_main()
+ * on the result and returns the bus connection.
+ *
+ * @param type bus type
+ * @param error address where an error can be returned.
+ * @returns a DBusConnection
+ */
+DBusConnection*
+dbus_bus_get_with_g_main (DBusBusType     type,
+                          GError        **error)
+{
+  DBusConnection *connection;
+  DBusError derror;
+
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+  
+  dbus_error_init (&derror);
+
+  connection = dbus_bus_get (type, &derror);
+  if (connection == NULL)
+    {
+      dbus_set_g_error (error, &derror);
+      dbus_error_free (&derror);
+    }
+  else
+    {
+      /* does nothing if it's already been done */
+      dbus_connection_setup_with_g_main (connection, NULL);
+    }
+
+  return connection;
+}
+
+/**
  * The implementation of DBUS_GERROR error domain. See documentation
  * for GError in GLib reference manual.
  *

Index: dbus-gproxy.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gproxy.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-gproxy.c	30 Sep 2003 02:32:57 -0000	1.2
+++ dbus-gproxy.c	3 Oct 2003 03:55:35 -0000	1.3
@@ -1089,10 +1089,10 @@
  * @param first_arg_type type of the first argument
  */
 void
-dbus_gproxy_oneway_call (DBusGProxy               *proxy,
-                         const char               *method,
-                         int                       first_arg_type,
-                         ...)
+dbus_gproxy_call_no_reply (DBusGProxy               *proxy,
+                           const char               *method,
+                           int                       first_arg_type,
+                           ...)
 {
   DBusMessage *message;
   va_list args;