[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-dbus
Subject:    Re: Detectin mainloop integration
From:       Sebastian =?ISO-8859-1?Q?Dr=F6ge?= <slomo () circular-chaos ! org>
Date:       2007-11-03 11:57:03
Message-ID: 1194091023.6178.6.camel () asgard
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Am Freitag, den 02.11.2007, 12:12 -0400 schrieb Havoc Pennington:
> Hi,
> 
> Sebastian Dröge wrote:
> > Do I need something special to get proper permissions? A git-clone on
> > ssh://git.freedesktop.org/git/dbus/dbus works fine.
> 
> You have to be in the dbus group. If you want to ask an admin to add you 
> that's fine with me, or tell us where to pull your final patch from. 
> (And I will try to figure out how to use git to do that... is there a 
> nice "commit this person's branch to the central repo" one-liner?)

Ok, attached are the latest patches...

For the dbus-glib.diff the changelog entry could look like:

Use dbus-glib-main instead of our own mainloop integration.


Seems that dbus-glib only uses the git logs instead of proper changelogs

["dbus-glib.diff" (dbus-glib.diff)]

diff --git a/configure.ac b/configure.ac
index f813a6f..8b3c2aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -647,7 +647,7 @@ DBUS_TEST_LIBS=
 AC_SUBST(DBUS_TEST_CFLAGS)
 AC_SUBST(DBUS_TEST_LIBS)
 
-PKG_CHECK_MODULES(DBUS, dbus-1 >= 0.93, have_dbus=yes, have_dbus=no)
+PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1.3 dbus-glib-main-1, have_dbus=yes, have_dbus=no)
 
 if test x$have_dbus = xno ; then
     AC_MSG_ERROR([DBus development libraries not found])
diff --git a/dbus/dbus-glib-lowlevel.h b/dbus/dbus-glib-lowlevel.h
index c996821..3a63ae2 100644
--- a/dbus/dbus-glib-lowlevel.h
+++ b/dbus/dbus-glib-lowlevel.h
@@ -39,10 +39,10 @@ GType dbus_connection_get_g_type   (void) G_GNUC_CONST;
 GType dbus_message_get_g_type      (void) G_GNUC_CONST;
 GType dbus_pending_call_get_g_type (void) G_GNUC_CONST;
 
-void            dbus_connection_setup_with_g_main (DBusConnection  *connection,
-                                                   GMainContext    *context);
-void            dbus_server_setup_with_g_main     (DBusServer      *server,
-                                                   GMainContext    *context);
+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_proxy_send (DBusGProxy    *proxy,
                         DBusMessage   *message,
diff --git a/dbus/dbus-glib.c b/dbus/dbus-glib.c
index e8c715e..d70f2ef 100644
--- a/dbus/dbus-glib.c
+++ b/dbus/dbus-glib.c
@@ -309,8 +309,6 @@ dbus_g_connection_get_connection (DBusGConnection *gconnection)
   return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
 }
 
-extern dbus_int32_t _dbus_gmain_connection_slot;
-
 /**
  * dbus_connection_get_g_connection:
  * @connection:  a #DBusConnection
@@ -326,7 +324,6 @@ DBusGConnection*
 dbus_connection_get_g_connection (DBusConnection *connection)
 {
   g_return_val_if_fail (connection, NULL);
-  g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL);
   
   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
 }
diff --git a/dbus/dbus-gmain.c b/dbus/dbus-gmain.c
index 3271b9b..75acb91 100644
--- a/dbus/dbus-gmain.c
+++ b/dbus/dbus-gmain.c
@@ -24,6 +24,7 @@
 
 #include <config.h>
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-main.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include "dbus-gtest.h"
 #include "dbus-gutils.h"
@@ -38,504 +39,6 @@
 #define N_(x) x
 
 /**
- * @defgroup DBusGLibInternals GLib bindings implementation details
- * @ingroup  DBusInternals
- * @brief Implementation details of GLib bindings
- *
- * @{
- */
-
-/**
- * DBusGMessageQueue:
- * A GSource subclass for dispatching DBusConnection messages.
- * We need this on top of the IO handlers, because sometimes
- * there are messages to dispatch queued up but no IO pending.
- */
-typedef struct
-{
-  GSource source; /**< the parent GSource */
-  DBusConnection *connection; /**< the connection to dispatch */
-} DBusGMessageQueue;
-
-static gboolean message_queue_prepare  (GSource     *source,
-                                        gint        *timeout);
-static gboolean message_queue_check    (GSource     *source);
-static gboolean message_queue_dispatch (GSource     *source,
-                                        GSourceFunc  callback,
-                                        gpointer     user_data);
-
-static const GSourceFuncs message_queue_funcs = {
-  message_queue_prepare,
-  message_queue_check,
-  message_queue_dispatch,
-  NULL
-};
-
-static gboolean
-message_queue_prepare (GSource *source,
-                       gint    *timeout)
-{
-  DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
-  
-  *timeout = -1;
-
-  return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS);  
-}
-
-static gboolean
-message_queue_check (GSource *source)
-{
-  return FALSE;
-}
-
-static gboolean
-message_queue_dispatch (GSource     *source,
-                        GSourceFunc  callback,
-                        gpointer     user_data)
-{
-  DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
-
-  dbus_connection_ref (connection);
-
-  /* Only dispatch once - we don't want to starve other GSource */
-  dbus_connection_dispatch (connection);
-  
-  dbus_connection_unref (connection);
-
-  return TRUE;
-}
-
-typedef struct
-{
-  GMainContext *context;      /**< the main context */
-  GSList *ios;                /**< all IOHandler */
-  GSList *timeouts;           /**< all TimeoutHandler */
-  DBusConnection *connection; /**< NULL if this is really for a server not a connection */
-  GSource *message_queue_source; /**< DBusGMessageQueue */
-} ConnectionSetup;
-
-
-typedef struct
-{
-  ConnectionSetup *cs;
-  GSource *source;
-  DBusWatch *watch;
-} IOHandler;
-
-typedef struct
-{
-  ConnectionSetup *cs;
-  GSource *source;
-  DBusTimeout *timeout;
-} TimeoutHandler;
-
-dbus_int32_t _dbus_gmain_connection_slot = -1;
-static dbus_int32_t server_slot = -1;
-
-static ConnectionSetup*
-connection_setup_new (GMainContext   *context,
-                      DBusConnection *connection)
-{
-  ConnectionSetup *cs;
-
-  cs = g_new0 (ConnectionSetup, 1);
-
-  g_assert (context != NULL);
-  
-  cs->context = context;
-  g_main_context_ref (cs->context);  
-
-  if (connection)
-    {
-      cs->connection = connection;
-
-      cs->message_queue_source = g_source_new ((GSourceFuncs *) &message_queue_funcs,
-                                               sizeof (DBusGMessageQueue));
-      ((DBusGMessageQueue*)cs->message_queue_source)->connection = connection;
-      g_source_attach (cs->message_queue_source, cs->context);
-    }
-  
-  return cs;
-}
-
-static void
-io_handler_source_finalized (gpointer data)
-{
-  IOHandler *handler;
-
-  handler = data;
-
-  if (handler->watch)
-    dbus_watch_set_data (handler->watch, NULL, NULL);
-  
-  g_free (handler);
-}
-
-static void
-io_handler_destroy_source (void *data)
-{
-  IOHandler *handler;
-
-  handler = data;
-
-  if (handler->source)
-    {
-      GSource *source = handler->source;
-      handler->source = NULL;
-      handler->cs->ios = g_slist_remove (handler->cs->ios, handler);
-      g_source_destroy (source);
-      g_source_unref (source);
-    }
-}
-
-static void
-io_handler_watch_freed (void *data)
-{
-  IOHandler *handler;
-
-  handler = data;
-
-  handler->watch = NULL;
-
-  io_handler_destroy_source (handler);
-}
-
-static gboolean
-io_handler_dispatch (GIOChannel   *source,
-                     GIOCondition  condition,
-                     gpointer      data)
-{
-  IOHandler *handler;
-  guint dbus_condition = 0;
-  DBusConnection *connection;
-
-  handler = data;
-
-  connection = handler->cs->connection;
-  
-  if (connection)
-    dbus_connection_ref (connection);
-  
-  if (condition & G_IO_IN)
-    dbus_condition |= DBUS_WATCH_READABLE;
-  if (condition & G_IO_OUT)
-    dbus_condition |= DBUS_WATCH_WRITABLE;
-  if (condition & G_IO_ERR)
-    dbus_condition |= DBUS_WATCH_ERROR;
-  if (condition & G_IO_HUP)
-    dbus_condition |= DBUS_WATCH_HANGUP;
-
-  /* Note that we don't touch the handler after this, because
-   * dbus may have disabled the watch and thus killed the
-   * handler.
-   */
-  dbus_watch_handle (handler->watch, dbus_condition);
-  handler = NULL;
-
-  if (connection)
-    dbus_connection_unref (connection);
-  
-  return TRUE;
-}
-
-static void
-connection_setup_add_watch (ConnectionSetup *cs,
-                            DBusWatch       *watch)
-{
-  guint flags;
-  GIOCondition condition;
-  GIOChannel *channel;
-  IOHandler *handler;
-  
-  if (!dbus_watch_get_enabled (watch))
-    return;
-  
-  g_assert (dbus_watch_get_data (watch) == NULL);
-  
-  flags = dbus_watch_get_flags (watch);
-
-  condition = G_IO_ERR | G_IO_HUP;
-  if (flags & DBUS_WATCH_READABLE)
-    condition |= G_IO_IN;
-  if (flags & DBUS_WATCH_WRITABLE)
-    condition |= G_IO_OUT;
-
-  handler = g_new0 (IOHandler, 1);
-  handler->cs = cs;
-  handler->watch = watch;
-  
-  channel = g_io_channel_unix_new (dbus_watch_get_fd (watch));
-  
-  handler->source = g_io_create_watch (channel, condition);
-  g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, handler,
-                         io_handler_source_finalized);
-  g_source_attach (handler->source, cs->context);
-
-  cs->ios = g_slist_prepend (cs->ios, handler);
-  
-  dbus_watch_set_data (watch, handler, io_handler_watch_freed);
-  g_io_channel_unref (channel);
-}
-
-static void
-connection_setup_remove_watch (ConnectionSetup *cs,
-                               DBusWatch       *watch)
-{
-  IOHandler *handler;
-
-  handler = dbus_watch_get_data (watch);
-
-  if (handler == NULL)
-    return;
-  
-  io_handler_destroy_source (handler);
-}
-
-static void
-timeout_handler_source_finalized (gpointer data)
-{
-  TimeoutHandler *handler;
-
-  handler = data;
-
-  if (handler->timeout)
-    dbus_timeout_set_data (handler->timeout, NULL, NULL);
-  
-  g_free (handler);
-}
-
-static void
-timeout_handler_destroy_source (void *data)
-{
-  TimeoutHandler *handler;
-
-  handler = data;
-
-  if (handler->source)
-    {
-      GSource *source = handler->source;
-      handler->source = NULL;
-      handler->cs->timeouts = g_slist_remove (handler->cs->timeouts, handler);
-      g_source_destroy (source);
-      g_source_unref (source);
-    }
-}
-
-static void
-timeout_handler_timeout_freed (void *data)
-{
-  TimeoutHandler *handler;
-
-  handler = data;
-
-  handler->timeout = NULL;
-
-  timeout_handler_destroy_source (handler);
-}
-
-static gboolean
-timeout_handler_dispatch (gpointer      data)
-{
-  TimeoutHandler *handler;
-
-  handler = data;
-
-  dbus_timeout_handle (handler->timeout);
-  
-  return TRUE;
-}
-
-static void
-connection_setup_add_timeout (ConnectionSetup *cs,
-                              DBusTimeout     *timeout)
-{
-  TimeoutHandler *handler;
-  
-  if (!dbus_timeout_get_enabled (timeout))
-    return;
-  
-  g_assert (dbus_timeout_get_data (timeout) == NULL);
-
-  handler = g_new0 (TimeoutHandler, 1);
-  handler->cs = cs;
-  handler->timeout = timeout;
-
-  handler->source = g_timeout_source_new (dbus_timeout_get_interval (timeout));
-  g_source_set_callback (handler->source, timeout_handler_dispatch, handler,
-                         timeout_handler_source_finalized);
-  g_source_attach (handler->source, handler->cs->context);
-
-  cs->timeouts = g_slist_prepend (cs->timeouts, handler);
-
-  dbus_timeout_set_data (timeout, handler, timeout_handler_timeout_freed);
-}
-
-static void
-connection_setup_remove_timeout (ConnectionSetup *cs,
-                                 DBusTimeout       *timeout)
-{
-  TimeoutHandler *handler;
-  
-  handler = dbus_timeout_get_data (timeout);
-
-  if (handler == NULL)
-    return;
-  
-  timeout_handler_destroy_source (handler);
-}
-
-static void
-connection_setup_free (ConnectionSetup *cs)
-{
-  while (cs->ios)
-    io_handler_destroy_source (cs->ios->data);
-
-  while (cs->timeouts)
-    timeout_handler_destroy_source (cs->timeouts->data);
-
-  if (cs->message_queue_source)
-    {
-      GSource *source;
-
-      source = cs->message_queue_source;
-      cs->message_queue_source = NULL;
-
-      g_source_destroy (source);
-      g_source_unref (source);
-    }
-  
-  g_main_context_unref (cs->context);
-  g_free (cs);
-}
-
-static dbus_bool_t
-add_watch (DBusWatch *watch,
-	   gpointer   data)
-{
-  ConnectionSetup *cs;
-
-  cs = data;
-
-  connection_setup_add_watch (cs, watch);
-  
-  return TRUE;
-}
-
-static void
-remove_watch (DBusWatch *watch,
-	      gpointer   data)
-{
-  ConnectionSetup *cs;
-
-  cs = data;
-
-  connection_setup_remove_watch (cs, watch);
-}
-
-static void
-watch_toggled (DBusWatch *watch,
-               void      *data)
-{
-  /* Because we just exit on OOM, enable/disable is
-   * no different from add/remove
-   */
-  if (dbus_watch_get_enabled (watch))
-    add_watch (watch, data);
-  else
-    remove_watch (watch, data);
-}
-
-static dbus_bool_t
-add_timeout (DBusTimeout *timeout,
-	     void        *data)
-{
-  ConnectionSetup *cs;
-
-  cs = data;
-  
-  if (!dbus_timeout_get_enabled (timeout))
-    return TRUE;
-
-  connection_setup_add_timeout (cs, timeout);
-
-  return TRUE;
-}
-
-static void
-remove_timeout (DBusTimeout *timeout,
-		void        *data)
-{
-  ConnectionSetup *cs;
-
-  cs = data;
-
-  connection_setup_remove_timeout (cs, timeout);
-}
-
-static void
-timeout_toggled (DBusTimeout *timeout,
-                 void        *data)
-{
-  /* Because we just exit on OOM, enable/disable is
-   * no different from add/remove
-   */
-  if (dbus_timeout_get_enabled (timeout))
-    add_timeout (timeout, data);
-  else
-    remove_timeout (timeout, data);
-}
-
-static void
-wakeup_main (void *data)
-{
-  ConnectionSetup *cs = data;
-
-  g_main_context_wakeup (cs->context);
-}
-
-
-/* Move to a new context */
-static ConnectionSetup*
-connection_setup_new_from_old (GMainContext    *context,
-                               ConnectionSetup *old)
-{
-  GSList *tmp;
-  ConnectionSetup *cs;
-
-  g_assert (old->context != context);
-  
-  cs = connection_setup_new (context, old->connection);
-  
-  tmp = old->ios;
-  while (tmp != NULL)
-    {
-      IOHandler *handler = tmp->data;
-
-      connection_setup_add_watch (cs, handler->watch);
-      
-      tmp = tmp->next;
-    }
-
-  tmp = old->timeouts;
-  while (tmp != NULL)
-    {
-      TimeoutHandler *handler = tmp->data;
-
-      connection_setup_add_timeout (cs, handler->timeout);
-      
-      tmp = tmp->next;
-    }
-
-  return cs;
-}
-
-/** @} */ /* End of GLib bindings internals */
-
-/** @addtogroup DBusGLib
- * @{
- */
-
-/**
  * dbus_connection_setup_with_g_main:
  * @connection: the connection
  * @context: the #GMainContext or #NULL for default context
@@ -546,71 +49,13 @@ connection_setup_new_from_old (GMainContext    *context,
  * 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.
+ * time.
  */
 void
 dbus_connection_setup_with_g_main (DBusConnection *connection,
 				   GMainContext   *context)
 {
-  ConnectionSetup *old_setup;
-  ConnectionSetup *cs;
-  
-  /* FIXME we never free the slot, so its refcount just keeps growing,
-   * which is kind of broken.
-   */
-  dbus_connection_allocate_data_slot (&_dbus_gmain_connection_slot);
-  if (_dbus_gmain_connection_slot < 0)
-    goto nomem;
-
-  if (context == NULL)
-    context = g_main_context_default ();
-
-  cs = NULL;
-  
-  old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_slot);
-  if (old_setup != NULL)
-    {
-      if (old_setup->context == context)
-        return; /* nothing to do */
-
-      cs = connection_setup_new_from_old (context, old_setup);
-      
-      /* Nuke the old setup */
-      dbus_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL);
-      old_setup = NULL;
-    }
-
-  if (cs == NULL)
-    cs = connection_setup_new (context, connection);
-
-  if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs,
-                                 (DBusFreeFunction)connection_setup_free))
-    goto nomem;
-  
-  if (!dbus_connection_set_watch_functions (connection,
-                                            add_watch,
-                                            remove_watch,
-                                            watch_toggled,
-                                            cs, NULL))
-    goto nomem;
-
-  if (!dbus_connection_set_timeout_functions (connection,
-                                              add_timeout,
-                                              remove_timeout,
-                                              timeout_toggled,
-                                              cs, NULL))
-    goto nomem;
-    
-  dbus_connection_set_wakeup_main_function (connection,
-					    wakeup_main,
-					    cs, NULL);
-      
-  return;
-
- nomem:
-  g_error ("Not enough memory to set up DBusConnection for use with GLib");
+  dbus_g_main_integrate_connection (connection, context);
 }
 
 /**
@@ -623,67 +68,13 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
  * 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.
+ * time.
  */
 void
 dbus_server_setup_with_g_main (DBusServer   *server,
                                GMainContext *context)
 {
-  ConnectionSetup *old_setup;
-  ConnectionSetup *cs;
-  
-  /* 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 (context == NULL)
-    context = g_main_context_default ();
-
-  cs = NULL;
-  
-  old_setup = dbus_server_get_data (server, server_slot);
-  if (old_setup != NULL)
-    {
-      if (old_setup->context == context)
-        return; /* nothing to do */
-
-      cs = connection_setup_new_from_old (context, old_setup);
-      
-      /* Nuke the old setup */
-      dbus_server_set_data (server, server_slot, NULL, NULL);
-      old_setup = NULL;
-    }
-
-  if (cs == NULL)
-    cs = connection_setup_new (context, NULL);
-
-  if (!dbus_server_set_data (server, server_slot, cs,
-                             (DBusFreeFunction)connection_setup_free))
-    goto nomem;
-  
-  if (!dbus_server_set_watch_functions (server,
-                                        add_watch,
-                                        remove_watch,
-                                        watch_toggled,
-                                        cs, NULL))
-    goto nomem;
-
-  if (!dbus_server_set_timeout_functions (server,
-                                          add_timeout,
-                                          remove_timeout,
-                                          timeout_toggled,
-                                          cs, NULL))
-    goto nomem;
-      
-  return;
-
- nomem:
-  g_error ("Not enough memory to set up DBusServer for use with GLib");
+  dbus_g_main_integrate_server (server, context);
 }
 
 /**
@@ -720,7 +111,8 @@ dbus_g_connection_open (const gchar  *address,
     }
 
   /* does nothing if it's already been done */
-  dbus_connection_setup_with_g_main (connection, NULL);
+  /* FIXME: where should the corresponding unintegrate be called? */
+  dbus_g_main_integrate_connection (connection, NULL);
 
   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
 }
@@ -760,7 +152,8 @@ dbus_g_bus_get (DBusBusType     type,
     }
 
   /* does nothing if it's already been done */
-  dbus_connection_setup_with_g_main (connection, NULL);
+  /* FIXME: where should the corresponding unintegrate be called? */
+  dbus_g_main_integrate_connection (connection, NULL);
 
   return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
 }

["dbus-glib-main.diff" (dbus-glib-main.diff)]

diff --git a/ChangeLog b/ChangeLog
index 0dc40d8..4fef603 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-11-02  Sebastian Dröge  <slomo@circular-chaos.org>
+
+	* configure.in, dbus-glib-main-1.pc.in, 
+	glib/dbus-glib-main.c, glib/dbus-glib-main.h, 
+	glib/Makefile.am, Makefile.am: Add a GLib mainloop integration
+	library based on the one from dbus-glib.
+
 2007-10-31  Havoc Pennington  <hp@redhat.com>
 
 	* bus/selinux.c (log_audit_callback): rewrite to use
diff --git a/Makefile.am b/Makefile.am
index f1101ed..874c282 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,15 +1,25 @@
 SUBDIRS=dbus bus doc tools test
-DIST_SUBDIRS=dbus bus doc tools test
+DIST_SUBDIRS=dbus glib bus doc tools test
 
 pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = dbus-1.pc 
+
+if HAVE_GLIB
+GLIB_PC_FILES = dbus-glib-main-1.pc
+SUBDIRS += glib
+else
+GLIB_PC_FILES = 
+endif
+
+pkgconfig_DATA = dbus-1.pc $(GLIB_PC_FILES)
 
 DISTCLEANFILES = 		\
-	dbus-1.pc
+	dbus-1.pc \
+	dbus-glib-main-1.pc
 
 EXTRA_DIST =			\
 	HACKING			\
 	dbus-1.pc.in		\
+	dbus-glib-main-1.pc.in	\
 	cleanup-man-pages.sh
 
 all-local: Doxyfile
diff --git a/configure.in b/configure.in
index fccb137..336b8aa 100644
--- a/configure.in
+++ b/configure.in
@@ -54,6 +54,19 @@ AC_SUBST(DBUS_MINOR_VERSION)
 AC_SUBST(DBUS_MICRO_VERSION)
 AC_SUBST(DBUS_VERSION)
 
+## increment if the interface has additions, changes, removals.
+DBUS_G_MAIN_LT_CURRENT=0
+## increment any time the source changes; set to
+##  0 if you increment CURRENT
+DBUS_G_MAIN_LT_REVISION=0
+## increment if any interfaces have been added; set to 0
+## if any interfaces have been changed or removed. removal has
+## precedence over adding, so set to 0 if both happened.
+DBUS_G_MAIN_LT_AGE=0
+AC_SUBST(DBUS_G_MAIN_LT_CURRENT)
+AC_SUBST(DBUS_G_MAIN_LT_REVISION)
+AC_SUBST(DBUS_G_MAIN_LT_AGE)
+
 AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_CXX
@@ -76,6 +89,7 @@ AC_ARG_ENABLE(dnotify, AS_HELP_STRING([--enable-dnotify],[build \
with dnotify sup  AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with \
kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto)  \
AC_ARG_ENABLE(console-owner-file, \
AS_HELP_STRING([--enable-console-owner-file],[enable console owner \
file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)  \
AC_ARG_ENABLE(userdb-cache, AS_HELP_STRING([--enable-userdb-cache],[build with \
userdb-cache support]),enable_userdb_cache=$enableval,enable_userdb_cache=yes) \
+AC_ARG_ENABLE(glib, AS_HELP_STRING([--enable-glib],[enable GLib main loop \
integration library]),enable_glib=$enableval,enable_glib=auto)  
 AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use]))
 AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of \
init scripts to install])) @@ -1016,6 +1030,22 @@ fi
 AC_SUBST(DBUS_X_CFLAGS)
 AC_SUBST(DBUS_X_LIBS)
 
+### check for glib
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6.0, have_glib=yes,have_glib=no)
+if test x$enable_glib = xyes; then
+	if test x$have_glib = xno; then
+		AC_MSG_ERROR([GLib explicitly required, and GLib development libraries not found])
+	fi
+fi
+
+if test x$enable_glib = xno; then
+	have_glib=no
+fi
+
+AM_CONDITIONAL(HAVE_GLIB, test x$have_glib = xyes)
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
 ### Doxygen Documentation
 
 AC_PATH_PROG(DOXYGEN, doxygen, no)
@@ -1267,12 +1297,14 @@ bus/rc.messagebus
 bus/dbus-daemon.1
 Makefile
 dbus/Makefile
+glib/Makefile
 bus/Makefile
 tools/Makefile
 test/Makefile
 test/name-test/Makefile
 doc/Makefile
 dbus-1.pc
+dbus-glib-main-1.pc
 test/data/valid-config-files/debug-allow-all.conf
 test/data/valid-config-files/debug-allow-all-sha1.conf
 test/data/valid-config-files-system/debug-allow-all-pass.conf
@@ -1295,52 +1327,53 @@ echo "
                     D-Bus $VERSION
                   ==============
 
-	prefix:                   ${prefix}
-	exec_prefix:              ${exec_prefix}
-        libdir:                   ${EXPANDED_LIBDIR}
-        libexecdir:               ${EXPANDED_LIBEXECDIR}
-        bindir:                   ${EXPANDED_BINDIR}
-        sysconfdir:               ${EXPANDED_SYSCONFDIR}
-        localstatedir:            ${EXPANDED_LOCALSTATEDIR}
-	datadir:                  ${EXPANDED_DATADIR}
-	source code location:	  ${srcdir}
-	compiler:		  ${CC}
-	cflags:		          ${CFLAGS}
-	cppflags:		  ${CPPFLAGS}
-	cxxflags:		  ${CXXFLAGS}
-	64-bit int:		  ${DBUS_INT64_TYPE}
-	32-bit int:		  ${DBUS_INT32_TYPE}
-	16-bit int:		  ${DBUS_INT16_TYPE}
-        Doxygen:                  ${DOXYGEN}
-        xmlto:                    ${XMLTO}"
+	prefix:                     ${prefix}
+	exec_prefix:                ${exec_prefix}
+        libdir:                     ${EXPANDED_LIBDIR}
+        libexecdir:                 ${EXPANDED_LIBEXECDIR}
+        bindir:                     ${EXPANDED_BINDIR}
+        sysconfdir:                 ${EXPANDED_SYSCONFDIR}
+        localstatedir:              ${EXPANDED_LOCALSTATEDIR}
+	datadir:                    ${EXPANDED_DATADIR}
+	source code location:	    ${srcdir}
+	compiler:		    ${CC}
+	cflags:		            ${CFLAGS}
+	cppflags:		    ${CPPFLAGS}
+	cxxflags:		    ${CXXFLAGS}
+	64-bit int:		    ${DBUS_INT64_TYPE}
+	32-bit int:		    ${DBUS_INT32_TYPE}
+	16-bit int:		    ${DBUS_INT16_TYPE}
+        Doxygen:                    ${DOXYGEN}
+        xmlto:                      ${XMLTO}"
 
 echo "
-        Maintainer mode:          ${USE_MAINTAINER_MODE}
-        gcc coverage profiling:   ${enable_gcov}
-        Building unit tests:      ${enable_tests}
-        Building verbose mode:    ${enable_verbose_mode}
-        Building assertions:      ${enable_asserts}
-        Building checks:          ${enable_checks}
-        Building SELinux support: ${have_selinux}
-        Building dnotify support: ${have_dnotify}
-        Building X11 code:        ${enable_x11}
-        Building Doxygen docs:    ${enable_doxygen_docs}
-        Building XML docs:        ${enable_xml_docs}
-        Building cache support:   ${enable_userdb_cache}
-        Gettext libs (empty OK):  ${INTLLIBS}
-        Using XML parser:         ${with_xml}
-        Init scripts style:       ${with_init_scripts}
-        Abstract socket names:    ${ac_cv_have_abstract_sockets}
-        System bus socket:        ${DBUS_SYSTEM_SOCKET}
-        System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}
-        System bus PID file:      ${DBUS_SYSTEM_PID_FILE}
-        Session bus socket dir:   ${DBUS_SESSION_SOCKET_DIR}
-        Console auth dir:         ${DBUS_CONSOLE_AUTH_DIR}
-        Console owner file:       ${have_console_owner_file}
-        Console owner file path:  ${DBUS_CONSOLE_OWNER_FILE}
-	System bus user:          ${DBUS_USER}
-	Session bus services dir: ${EXPANDED_DATADIR}/dbus-1/services
-        'make check' socket dir:  ${TEST_SOCKET_DIR}
+        Maintainer mode:            ${USE_MAINTAINER_MODE}
+        gcc coverage profiling:     ${enable_gcov}
+        Building unit tests:        ${enable_tests}
+        Building verbose mode:      ${enable_verbose_mode}
+        Building assertions:        ${enable_asserts}
+        Building checks:            ${enable_checks}
+        Building SELinux support:   ${have_selinux}
+        Building dnotify support:   ${have_dnotify}
+        Building X11 code:          ${enable_x11}
+	Building GLib integration:  ${have_glib}
+        Building Doxygen docs:      ${enable_doxygen_docs}
+        Building XML docs:          ${enable_xml_docs}
+        Building cache support:     ${enable_userdb_cache}
+        Gettext libs (empty OK):    ${INTLLIBS}
+        Using XML parser:           ${with_xml}
+        Init scripts style:         ${with_init_scripts}
+        Abstract socket names:      ${ac_cv_have_abstract_sockets}
+        System bus socket:          ${DBUS_SYSTEM_SOCKET}
+        System bus address:         ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}
+        System bus PID file:        ${DBUS_SYSTEM_PID_FILE}
+        Session bus socket dir:     ${DBUS_SESSION_SOCKET_DIR}
+        Console auth dir:           ${DBUS_CONSOLE_AUTH_DIR}
+        Console owner file:         ${have_console_owner_file}
+        Console owner file path:    ${DBUS_CONSOLE_OWNER_FILE}
+	System bus user:            ${DBUS_USER}
+	Session bus services dir:   ${EXPANDED_DATADIR}/dbus-1/services
+        'make check' socket dir:    ${TEST_SOCKET_DIR}
 "
 
 if test x$enable_tests = xyes; then
diff --git a/dbus-glib-main-1.pc.in b/dbus-glib-main-1.pc.in
new file mode 100644
index 0000000..09f4453
--- /dev/null
+++ b/dbus-glib-main-1.pc.in
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: dbus-glib-main
+Description: GLib mainloop integration for the free desktop message bus
+Version: @VERSION@
+Requires: dbus-1 glib-2.0
+Libs: -L${libdir} -ldbus-glib-main-1
+Cflags: -I${includedir}/dbus-1.0
+
+
diff --git a/glib/Makefile.am b/glib/Makefile.am
new file mode 100644
index 0000000..2d6f1e0
--- /dev/null
+++ b/glib/Makefile.am
@@ -0,0 +1,24 @@
+INCLUDES = \
+	-I$(top_builddir) \
+	-I$(top_srcdir) \
+	$(DBUS_CLIENT_CFLAGS) \
+	$(GLIB_CFLAGS)
+
+libdbus_glib_main_1_la_SOURCES = 		\
+	dbus-glib-main.c			\
+	dbus-glib-main.h
+
+libdbus_glib_main_HEADERS =			\
+        dbus-glib-main.h
+
+lib_LTLIBRARIES=libdbus-glib-main-1.la
+
+libdbus_glib_maindir = $(includedir)/dbus-1.0/dbus
+
+libdbus_glib_main_1_la_LIBADD= \
+	$(top_builddir)/dbus/libdbus-1.la \
+	$(GLIB_LIBS)
+
+# only export symbols that start with dbus_g_main
+libdbus_glib_main_1_la_LDFLAGS= -export-symbols-regex "^dbus_g_main.*" -version-info \
$(DBUS_G_MAIN_LT_CURRENT):$(DBUS_G_MAIN_LT_REVISION):$(DBUS_G_MAIN_LT_AGE) \
-no-undefined +
diff --git a/glib/dbus-glib-main.c b/glib/dbus-glib-main.c
new file mode 100644
index 0000000..a01ce1a
--- /dev/null
+++ b/glib/dbus-glib-main.c
@@ -0,0 +1,742 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-glib-main.c GLib main context integration
+ *
+ * Copyright (C) 2002, 2003 CodeFactory AB
+ * Copyright (C) 2005 Red Hat, Inc.
+ * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <config.h>
+
+#include "dbus-glib-main.h"
+#include <string.h>
+
+/**
+ * @defgroup DBusGLibMainInternals GLib main context integration implementation \
details + * @ingroup  DBusInternals
+ * @brief Implementation details of GLib main context integration
+ *
+ * @{
+ */
+
+/**
+ * DBusGMessageQueue:
+ * A GSource subclass for dispatching DBusConnection messages.
+ * We need this on top of the IO handlers, because sometimes
+ * there are messages to dispatch queued up but no IO pending.
+ */
+typedef struct
+{
+  GSource source; /**< the parent GSource */
+  DBusConnection *connection; /**< the connection to dispatch */
+} DBusGMessageQueue;
+
+static gboolean message_queue_prepare  (GSource     *source,
+                                        gint        *timeout);
+static gboolean message_queue_check    (GSource     *source);
+static gboolean message_queue_dispatch (GSource     *source,
+                                        GSourceFunc  callback,
+                                        gpointer     user_data);
+
+static const GSourceFuncs message_queue_funcs = {
+  message_queue_prepare,
+  message_queue_check,
+  message_queue_dispatch,
+  NULL
+};
+
+static gboolean
+message_queue_prepare (GSource *source,
+                       gint    *timeout)
+{
+  DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
+  
+  *timeout = -1;
+
+  return (dbus_connection_get_dispatch_status (connection) == \
DBUS_DISPATCH_DATA_REMAINS);   +}
+
+static gboolean
+message_queue_check (GSource *source)
+{
+  return FALSE;
+}
+
+static gboolean
+message_queue_dispatch (GSource     *source,
+                        GSourceFunc  callback,
+                        gpointer     user_data)
+{
+  DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
+
+  dbus_connection_ref (connection);
+
+  /* Only dispatch once - we don't want to starve other GSource */
+  dbus_connection_dispatch (connection);
+  
+  dbus_connection_unref (connection);
+
+  return TRUE;
+}
+
+typedef struct
+{
+  GMainContext *context;      /**< the main context */
+  GSList *ios;                /**< all IOHandler */
+  GSList *timeouts;           /**< all TimeoutHandler */
+  DBusConnection *connection; /**< NULL if this is really for a server not a \
connection */ +  DBusServer *server;         /**< NULL if this is really for a \
connection not a server */ +  GSource *message_queue_source; /**< DBusGMessageQueue \
*/ +  int count;
+} ConnectionSetup;
+
+
+typedef struct
+{
+  ConnectionSetup *cs;
+  GSource *source;
+  DBusWatch *watch;
+} IOHandler;
+
+typedef struct
+{
+  ConnectionSetup *cs;
+  GSource *source;
+  DBusTimeout *timeout;
+} TimeoutHandler;
+
+static dbus_int32_t connection_slot = -1;
+static dbus_int32_t server_slot = -1;
+
+static ConnectionSetup*
+connection_setup_new (GMainContext   *context,
+                      DBusConnection *connection,
+		      DBusServer     *server)
+{
+  ConnectionSetup *cs;
+
+  cs = g_new0 (ConnectionSetup, 1);
+
+  g_assert (context != NULL);
+  
+  cs->context = context;
+  cs->count = 1;
+
+  if (connection)
+    {
+      cs->connection = connection;
+
+      cs->message_queue_source = g_source_new ((GSourceFuncs *) \
&message_queue_funcs, +                                               sizeof \
(DBusGMessageQueue)); +      \
((DBusGMessageQueue*)cs->message_queue_source)->connection = connection; +      \
g_source_attach (cs->message_queue_source, cs->context); +    }
+  else if (server)
+    {
+      cs->server = server;
+    }
+  
+  return cs;
+}
+
+static void
+io_handler_source_finalized (gpointer data)
+{
+  IOHandler *handler;
+
+  handler = data;
+
+  if (handler->cs->connection)
+    dbus_connection_unref (handler->cs->connection);
+
+  if (handler->cs->server)
+    dbus_server_unref (handler->cs->server);
+
+  if (handler->watch)
+    dbus_watch_set_data (handler->watch, NULL, NULL);
+  
+  g_free (handler);
+}
+
+static void
+io_handler_destroy_source (void *data)
+{
+  IOHandler *handler;
+
+  handler = data;
+
+  if (handler->source)
+    {
+      GSource *source = handler->source;
+      handler->source = NULL;
+      handler->cs->ios = g_slist_remove (handler->cs->ios, handler);
+      g_source_destroy (source);
+      g_source_unref (source);
+    }
+}
+
+static void
+io_handler_watch_freed (void *data)
+{
+  IOHandler *handler;
+
+  handler = data;
+
+  handler->watch = NULL;
+
+  io_handler_destroy_source (handler);
+}
+
+static gboolean
+io_handler_dispatch (GIOChannel   *source,
+                     GIOCondition  condition,
+                     gpointer      data)
+{
+  IOHandler *handler;
+  guint dbus_condition = 0;
+  DBusConnection *connection;
+  DBusServer *server;
+
+  handler = data;
+
+  connection = handler->cs->connection;
+  server = handler->cs->server;
+  
+  if (connection)
+    dbus_connection_ref (connection);
+
+  if (handler->cs->server)
+    dbus_server_ref (handler->cs->server);
+  
+  if (condition & G_IO_IN)
+    dbus_condition |= DBUS_WATCH_READABLE;
+  if (condition & G_IO_OUT)
+    dbus_condition |= DBUS_WATCH_WRITABLE;
+  if (condition & G_IO_ERR)
+    dbus_condition |= DBUS_WATCH_ERROR;
+  if (condition & G_IO_HUP)
+    dbus_condition |= DBUS_WATCH_HANGUP;
+
+  /* Note that we don't touch the handler after this, because
+   * dbus may have disabled the watch and thus killed the
+   * handler.
+   */
+  dbus_watch_handle (handler->watch, dbus_condition);
+  handler = NULL;
+
+  if (connection)
+    dbus_connection_unref (connection);
+
+  if (server)
+    dbus_server_unref (server);
+  
+  return TRUE;
+}
+
+static void
+connection_setup_add_watch (ConnectionSetup *cs,
+                            DBusWatch       *watch)
+{
+  guint flags;
+  GIOCondition condition;
+  GIOChannel *channel;
+  IOHandler *handler;
+  
+  if (!dbus_watch_get_enabled (watch))
+    return;
+  
+  g_assert (dbus_watch_get_data (watch) == NULL);
+  
+  flags = dbus_watch_get_flags (watch);
+
+  condition = G_IO_ERR | G_IO_HUP;
+  if (flags & DBUS_WATCH_READABLE)
+    condition |= G_IO_IN;
+  if (flags & DBUS_WATCH_WRITABLE)
+    condition |= G_IO_OUT;
+
+  handler = g_new0 (IOHandler, 1);
+  handler->cs = cs;
+  handler->watch = watch;
+
+  if (cs->connection)
+    dbus_connection_ref (cs->connection);
+
+  if (cs->server)
+    dbus_server_ref (cs->server);
+  
+  channel = g_io_channel_unix_new (dbus_watch_get_unix_fd (watch));
+  
+  handler->source = g_io_create_watch (channel, condition);
+  g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, \
handler, +                         io_handler_source_finalized);
+  g_source_attach (handler->source, cs->context);
+
+  cs->ios = g_slist_prepend (cs->ios, handler);
+  
+  dbus_watch_set_data (watch, handler, io_handler_watch_freed);
+  g_io_channel_unref (channel);
+}
+
+static void
+connection_setup_remove_watch (ConnectionSetup *cs,
+                               DBusWatch       *watch)
+{
+  IOHandler *handler;
+
+  handler = dbus_watch_get_data (watch);
+
+  if (handler == NULL)
+    return;
+  
+  io_handler_destroy_source (handler);
+}
+
+static void
+timeout_handler_source_finalized (gpointer data)
+{
+  TimeoutHandler *handler;
+
+  handler = data;
+
+  if (handler->cs->connection)
+    dbus_connection_unref (handler->cs->connection);
+  if (handler->cs->server)
+    dbus_server_unref (handler->cs->server);
+
+  if (handler->timeout)
+    dbus_timeout_set_data (handler->timeout, NULL, NULL);
+  
+  g_free (handler);
+}
+
+static void
+timeout_handler_destroy_source (void *data)
+{
+  TimeoutHandler *handler;
+
+  handler = data;
+
+  if (handler->source)
+    {
+      GSource *source = handler->source;
+      handler->source = NULL;
+      handler->cs->timeouts = g_slist_remove (handler->cs->timeouts, handler);
+      g_source_destroy (source);
+      g_source_unref (source);
+    }
+}
+
+static void
+timeout_handler_timeout_freed (void *data)
+{
+  TimeoutHandler *handler;
+
+  handler = data;
+
+  handler->timeout = NULL;
+
+  timeout_handler_destroy_source (handler);
+}
+
+static gboolean
+timeout_handler_dispatch (gpointer      data)
+{
+  TimeoutHandler *handler;
+
+  handler = data;
+
+  dbus_timeout_handle (handler->timeout);
+  
+  return TRUE;
+}
+
+static void
+connection_setup_add_timeout (ConnectionSetup *cs,
+                              DBusTimeout     *timeout)
+{
+  TimeoutHandler *handler;
+  
+  if (!dbus_timeout_get_enabled (timeout))
+    return;
+  
+  g_assert (dbus_timeout_get_data (timeout) == NULL);
+
+  handler = g_new0 (TimeoutHandler, 1);
+  handler->cs = cs;
+  handler->timeout = timeout;
+
+  if (cs->connection)
+    dbus_connection_ref (cs->connection);
+  if (cs->server)
+    dbus_server_ref (cs->server);
+
+  handler->source = g_timeout_source_new (dbus_timeout_get_interval (timeout));
+  g_source_set_callback (handler->source, timeout_handler_dispatch, handler,
+                         timeout_handler_source_finalized);
+  g_source_attach (handler->source, handler->cs->context);
+
+  cs->timeouts = g_slist_prepend (cs->timeouts, handler);
+
+  dbus_timeout_set_data (timeout, handler, timeout_handler_timeout_freed);
+}
+
+static void
+connection_setup_remove_timeout (ConnectionSetup *cs,
+                                 DBusTimeout       *timeout)
+{
+  TimeoutHandler *handler;
+  
+  handler = dbus_timeout_get_data (timeout);
+
+  if (handler == NULL)
+    return;
+  
+  timeout_handler_destroy_source (handler);
+}
+
+static void
+connection_setup_free (ConnectionSetup *cs)
+{
+  while (cs->ios)
+    io_handler_destroy_source (cs->ios->data);
+
+  while (cs->timeouts)
+    timeout_handler_destroy_source (cs->timeouts->data);
+
+  if (cs->message_queue_source)
+    {
+      GSource *source;
+
+      source = cs->message_queue_source;
+      cs->message_queue_source = NULL;
+
+      g_source_destroy (source);
+      g_source_unref (source);
+    }
+
+  g_free (cs);
+}
+
+static dbus_bool_t
+add_watch (DBusWatch *watch,
+	   gpointer   data)
+{
+  ConnectionSetup *cs;
+
+  cs = data;
+
+  connection_setup_add_watch (cs, watch);
+  
+  return TRUE;
+}
+
+static void
+remove_watch (DBusWatch *watch,
+	      gpointer   data)
+{
+  ConnectionSetup *cs;
+
+  cs = data;
+
+  connection_setup_remove_watch (cs, watch);
+}
+
+static void
+watch_toggled (DBusWatch *watch,
+               void      *data)
+{
+  /* Because we just exit on OOM, enable/disable is
+   * no different from add/remove
+   */
+  if (dbus_watch_get_enabled (watch))
+    add_watch (watch, data);
+  else
+    remove_watch (watch, data);
+}
+
+static dbus_bool_t
+add_timeout (DBusTimeout *timeout,
+	     void        *data)
+{
+  ConnectionSetup *cs;
+
+  cs = data;
+  
+  if (!dbus_timeout_get_enabled (timeout))
+    return TRUE;
+
+  connection_setup_add_timeout (cs, timeout);
+
+  return TRUE;
+}
+
+static void
+remove_timeout (DBusTimeout *timeout,
+		void        *data)
+{
+  ConnectionSetup *cs;
+
+  cs = data;
+
+  connection_setup_remove_timeout (cs, timeout);
+}
+
+static void
+timeout_toggled (DBusTimeout *timeout,
+                 void        *data)
+{
+  /* Because we just exit on OOM, enable/disable is
+   * no different from add/remove
+   */
+  if (dbus_timeout_get_enabled (timeout))
+    add_timeout (timeout, data);
+  else
+    remove_timeout (timeout, data);
+}
+
+static void
+wakeup_main (void *data)
+{
+  ConnectionSetup *cs = data;
+
+  g_main_context_wakeup (cs->context);
+}
+
+/** @} */ /* End of GLib main context integration internals */
+
+/** @addtogroup DBusGLib
+ * @{
+ */
+
+/**
+ * dbus_g_main_integrate_connection:
+ * @connection: the connection
+ * @context: the #GMainContext or #NULL for default context
+ *
+ * Sets the watch and timeout functions of a #DBusConnection
+ * to integrate the connection with the GLib main loop.
+ * Pass in #NULL for the #GMainContext unless you're
+ * doing something specialized.
+ *
+ * If called more than once the same context must be passed
+ * again. For every call there should be a corresponding
+ * dbus_g_main_unintegrate_connection call.
+ */
+void
+dbus_g_main_integrate_connection (DBusConnection *connection,
+				  GMainContext   *context)
+{
+  ConnectionSetup *cs;
+
+  g_return_if_fail (connection != NULL);
+  
+  if (context == NULL)
+    context = g_main_context_default ();
+
+  cs = NULL;
+ 
+  if (connection_slot >= 0)
+    cs = dbus_connection_get_data (connection, connection_slot);
+
+  if (cs != NULL && cs->context != context)
+    goto different_context;
+      
+  if (cs == NULL)
+    {
+      dbus_connection_allocate_data_slot (&connection_slot);
+      if (connection_slot < 0)
+        goto nomem;
+    }
+
+  if (cs == NULL)
+    cs = connection_setup_new (context, connection, NULL);
+  else
+    g_atomic_int_inc (&cs->count);
+
+  if (!dbus_connection_set_data (connection, connection_slot, cs,
+                                 (DBusFreeFunction)connection_setup_free))
+    goto nomem;
+  
+  if (!dbus_connection_set_watch_functions (connection,
+                                            add_watch,
+                                            remove_watch,
+                                            watch_toggled,
+                                            cs, NULL))
+    goto nomem;
+
+  if (!dbus_connection_set_timeout_functions (connection,
+                                              add_timeout,
+                                              remove_timeout,
+                                              timeout_toggled,
+                                              cs, NULL))
+    goto nomem;
+    
+  dbus_connection_set_wakeup_main_function (connection,
+					    wakeup_main,
+					    cs, NULL);
+      
+  return;
+
+ nomem:
+  g_error ("Not enough memory to set up DBusConnection for use with GLib");
+  return;
+ different_context:
+  g_warning ("Integrating into two different main contexts not supported");
+  return;
+}
+
+/**
+ * dbus_g_main_integrate_server:
+ * @server: the server
+ * @context: the #GMainContext or #NULL for default
+ *
+ * Sets the watch and timeout functions of a #DBusServer
+ * to integrate the server with the GLib main loop.
+ * In most cases the context argument should be #NULL.
+ *
+ * If called more than once the same context must be passed
+ * again. For every call there should be a corresponding
+ * dbus_g_main_unintegrate_server call.
+ */
+void
+dbus_g_main_integrate_server (DBusServer   *server,
+                              GMainContext *context)
+{
+  ConnectionSetup *cs;
+
+  g_return_if_fail (server != NULL);
+  
+  if (context == NULL)
+    context = g_main_context_default ();
+
+  cs = NULL;
+  
+  if (server_slot >= 0)
+    cs = dbus_server_get_data (server, server_slot);
+
+  if (cs != NULL && cs->context != context)
+    goto different_context;
+
+  if (cs == NULL)
+    {
+      dbus_server_allocate_data_slot (&server_slot);
+      if (server_slot < 0)
+        goto nomem;
+    }
+  
+  if (cs == NULL)
+    cs = connection_setup_new (context, NULL, server);
+  else
+    g_atomic_int_inc (&cs->count);
+
+  if (!dbus_server_set_data (server, server_slot, cs,
+                             (DBusFreeFunction)connection_setup_free))
+    goto nomem;
+  
+  if (!dbus_server_set_watch_functions (server,
+                                        add_watch,
+                                        remove_watch,
+                                        watch_toggled,
+                                        cs, NULL))
+    goto nomem;
+
+  if (!dbus_server_set_timeout_functions (server,
+                                          add_timeout,
+                                          remove_timeout,
+                                          timeout_toggled,
+                                          cs, NULL))
+    goto nomem;
+      
+  return;
+
+ nomem:
+  g_error ("Not enough memory to set up DBusServer for use with GLib");
+  return;
+ different_context:
+  g_warning ("Integrating into two different main contexts not supported");
+  return;
+}
+
+/**
+ * dbus_g_main_unintegrate_connection:
+ * @connection: the connection
+ *
+ * Unintegrates the connection from the main context.
+ * This should be called as many times as the connection
+ * was integrated.
+ */
+void dbus_g_main_unintegrate_connection (DBusConnection *connection)
+{
+  ConnectionSetup *cs;
+  g_return_if_fail (connection != NULL);
+  g_return_if_fail (connection_slot >= 0);
+
+  cs = dbus_connection_get_data (connection, connection_slot);
+  g_return_if_fail (cs != NULL);
+  g_return_if_fail (cs->count > 0);
+
+  if (!g_atomic_int_dec_and_test (&cs->count))
+    return;
+
+  /* Free any existing ConnectionSetup */
+  dbus_connection_set_data (connection, connection_slot, NULL, NULL);
+
+  /* Unset watch, wakeup and timeout functions */
+  dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL);
+  dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
+  dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
+
+  /* Unref data slot */
+  dbus_connection_free_data_slot (&connection_slot);
+}
+
+/**
+ * dbus_g_main_unintegrate_server:
+ * @server: the server
+ *
+ * Unintegrates the server from the main context.
+ * This should be called as many times as the server
+ * was integrated.
+ */
+void dbus_g_main_unintegrate_server (DBusServer *server)
+{
+  ConnectionSetup *cs;
+  g_return_if_fail (server != NULL);
+  g_return_if_fail (server_slot >= 0);
+  
+  cs = dbus_server_get_data (server, server_slot);
+  g_return_if_fail (cs != NULL);
+  g_return_if_fail (cs->count > 0);
+
+  if (!g_atomic_int_dec_and_test (&cs->count))
+    return;
+
+  /* Free any existing ConnectionSetup */
+  dbus_server_set_data (server, server_slot, NULL, NULL);
+
+  /* Unset watch and timeout functions */
+  dbus_server_set_timeout_functions (server, NULL, NULL, NULL, NULL, NULL);
+  dbus_server_set_watch_functions (server, NULL, NULL, NULL, NULL, NULL);
+
+  /* Unref data slot */
+  dbus_server_free_data_slot (&server_slot);
+}
+
diff --git a/glib/dbus-glib-main.h b/glib/dbus-glib-main.h
new file mode 100644
index 0000000..3baa43e
--- /dev/null
+++ b/glib/dbus-glib-main.h
@@ -0,0 +1,44 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-glib-main.h GLib main context integration integration
+ *
+ * Copyright (C) 2002, 2003  CodeFactory AB
+ * Copyright (C) 2003, 2004 Red Hat, Inc.
+ * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+#ifndef DBUS_G_MAIN_H
+#define DBUS_G_MAIN_H
+
+#include <glib.h>
+#include <dbus/dbus.h>
+
+G_BEGIN_DECLS
+
+void        dbus_g_main_integrate_connection     (DBusConnection  *connection,
+                                                  GMainContext    *context);
+void        dbus_g_main_integrate_server         (DBusServer      *server,
+                                                  GMainContext    *context);
+
+void        dbus_g_main_unintegrate_connection   (DBusConnection  *connection);
+void        dbus_g_main_unintegrate_server       (DBusServer  *server);
+
+G_END_DECLS
+
+#endif /* DBUS_G_MAIN_H */
+


["signature.asc" (application/pgp-signature)]

_______________________________________________
dbus mailing list
dbus@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dbus


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic