evolution r36201 - branches/mail-dbus-remoting/mail
- From: michael svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution r36201 - branches/mail-dbus-remoting/mail
- Date: Fri, 29 Aug 2008 12:14:05 +0000 (UTC)
Author: michael
Date: Fri Aug 29 12:14:05 2008
New Revision: 36201
URL: http://svn.gnome.org/viewvc/evolution?rev=36201&view=rev
Log:
use a thread per dbus connection
Modified:
branches/mail-dbus-remoting/mail/camel-object-remote.c
branches/mail-dbus-remoting/mail/dbind.c
branches/mail-dbus-remoting/mail/evo-dbus.c
branches/mail-dbus-remoting/mail/evo-dbus.h
Modified: branches/mail-dbus-remoting/mail/camel-object-remote.c
==============================================================================
--- branches/mail-dbus-remoting/mail/camel-object-remote.c (original)
+++ branches/mail-dbus-remoting/mail/camel-object-remote.c Fri Aug 29 12:14:05 2008
@@ -33,7 +33,7 @@
register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg)
{
DBusObjectPathVTable *dbus_listener_vtable;
- DBindContext *ctx = evolution_dbus_peek_context ();
+ DBindContext *ctx = evolution_dbus_peek_main_context ();
DBusError err; int ret;
char *rule;
Modified: branches/mail-dbus-remoting/mail/dbind.c
==============================================================================
--- branches/mail-dbus-remoting/mail/dbind.c (original)
+++ branches/mail-dbus-remoting/mail/dbind.c Fri Aug 29 12:14:05 2008
@@ -47,6 +47,7 @@
{
if (!ctx)
return;
+ dbus_connection_close (ctx->cnx);
dbus_connection_unref (ctx->cnx);
g_free (ctx);
}
Modified: branches/mail-dbus-remoting/mail/evo-dbus.c
==============================================================================
--- branches/mail-dbus-remoting/mail/evo-dbus.c (original)
+++ branches/mail-dbus-remoting/mail/evo-dbus.c Fri Aug 29 12:14:05 2008
@@ -12,37 +12,65 @@
#include <dbind.h>
#include <dbind-any.h>
#include "camel-object-remote.h"
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
#define d(x) x
-static DBindContext *ctx = NULL;
+static DBindContext *main_ctx = NULL;
+static GPrivate *per_thread_ctx = NULL;
-int
-evolution_dbus_init ()
+static void
+per_thread_private_destroy (gpointer ctx)
{
- DBusError error;
+ dbind_context_free (ctx);
+}
- if (ctx)
+int
+evolution_dbus_init (void)
+{
+ if (main_ctx)
return 0;
- ctx = dbind_create_context (DBUS_BUS_SESSION, NULL);
- if (!ctx) {
- g_warning ("DBind context setup failed\n");
+ main_ctx = dbind_create_context (DBUS_BUS_SESSION, NULL);
+ /* Set up this connection to work in a GLib event loop */
+ dbus_connection_setup_with_g_main (main_ctx->cnx, NULL);
+
+ if (!main_ctx) {
+ g_warning ("DBind main context setup failed\n");
return -1;
}
d(printf("DBind context setup: done\n"));
+ per_thread_ctx = g_private_new (per_thread_private_destroy);
+
return 0;
}
DBindContext *
-evolution_dbus_peek_context ()
+evolution_dbus_peek_main_context (void)
{
- if (!ctx) {
+ if (!main_ctx)
evolution_dbus_init ();
- if (!ctx)
- return NULL;
+ return main_ctx;
+}
+
+/*
+ * Sadly we need one per thread to make dbus reliable.
+ */
+DBindContext *
+evolution_dbus_peek_context (void)
+{
+ DBindContext *ctx;
+
+ if (!main_ctx)
+ evolution_dbus_init ();
+
+ ctx = (DBindContext *)g_private_get (per_thread_ctx);
+ if (!ctx) {
+ ctx = dbind_create_context (DBUS_BUS_SESSION, NULL);
+ g_private_set (per_thread_ctx, ctx);
}
return ctx;
Modified: branches/mail-dbus-remoting/mail/evo-dbus.h
==============================================================================
--- branches/mail-dbus-remoting/mail/evo-dbus.h (original)
+++ branches/mail-dbus-remoting/mail/evo-dbus.h Fri Aug 29 12:14:05 2008
@@ -18,6 +18,12 @@
process from the client */
int evolution_dbus_init (void);
+
+/* return the dbind context for this thread */
DBindContext *evolution_dbus_peek_context (void);
+/* return a dbind context for the main thread - to listen
+ for signals on */
+DBindContext *evolution_dbus_peek_main_context (void);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]