summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-10-03 03:55:35 +0000
committerHavoc Pennington <hp@redhat.com>2003-10-03 03:55:35 +0000
commit79d03f94fec278d270a33792aeffb33ba239bb01 (patch)
tree25fd2784595cd02b6cd042f2b53df260d095b62a
parentdbffb387903d9741f1b937d61ff9f7aeba131b6e (diff)
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
-rw-r--r--ChangeLog10
-rw-r--r--glib/dbus-glib.h14
-rw-r--r--glib/dbus-gmain.c99
-rw-r--r--glib/dbus-gproxy.c8
4 files changed, 107 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index d7b2d1aa..d062f3f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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
+
2003-10-02 Havoc Pennington <hp@redhat.com>
* doc/dbus-tutorial.xml: write some stuff
diff --git a/glib/dbus-glib.h b/glib/dbus-glib.h
index 46f4555d..10539545 100644
--- a/glib/dbus-glib.h
+++ b/glib/dbus-glib.h
@@ -51,11 +51,13 @@ typedef enum
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 @@ gboolean dbus_gproxy_end_call (DBusGProxy *pr
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,
...);
diff --git a/glib/dbus-gmain.c b/glib/dbus-gmain.c
index 68ba22d7..7c845d5b 100644
--- a/glib/dbus-gmain.c
+++ b/glib/dbus-gmain.c
@@ -443,6 +443,11 @@ create_source (void *connection_or_server,
* 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 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
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 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
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 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
* 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 @@ dbus_server_setup_with_g_main (DBusServer *server,
{
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 @@ dbus_server_setup_with_g_main (DBusServer *server,
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 @@ dbus_server_setup_with_g_main (DBusServer *server,
}
/**
+ * 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.
*
diff --git a/glib/dbus-gproxy.c b/glib/dbus-gproxy.c
index 99900e4c..13b4248c 100644
--- a/glib/dbus-gproxy.c
+++ b/glib/dbus-gproxy.c
@@ -1089,10 +1089,10 @@ dbus_gproxy_end_call (DBusGProxy *proxy,
* @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;