evolution r36139 - in branches/mail-dbus-remoting: . mail



Author: michael
Date: Wed Aug 27 20:21:13 2008
New Revision: 36139
URL: http://svn.gnome.org/viewvc/evolution?rev=36139&view=rev

Log:
Misc fixes, back-port dbind fixes from hit head, re-organise
some small code pieces.


Modified:
   branches/mail-dbus-remoting/mail/camel-object-remote-impl.c
   branches/mail-dbus-remoting/mail/camel-object-remote.c
   branches/mail-dbus-remoting/mail/camel-object-remote.h
   branches/mail-dbus-remoting/mail/camel-session-remote.c
   branches/mail-dbus-remoting/mail/camel-store-remote.c
   branches/mail-dbus-remoting/mail/dbind-any.c
   branches/mail-dbus-remoting/mail/dbind.c
   branches/mail-dbus-remoting/mail/dbind.h
   branches/mail-dbus-remoting/mail/evo-dbus.c
   branches/mail-dbus-remoting/mail/evo-dbus.h
   branches/mail-dbus-remoting/mail/mail-dbus.c
   branches/mail-dbus-remoting/mail/mail-dbus.h
   branches/mail-dbus-remoting/mail/mail-session-remote.c
   branches/mail-dbus-remoting/server.mk

Modified: branches/mail-dbus-remoting/mail/camel-object-remote-impl.c
==============================================================================
--- branches/mail-dbus-remoting/mail/camel-object-remote-impl.c	(original)
+++ branches/mail-dbus-remoting/mail/camel-object-remote-impl.c	Wed Aug 27 20:21:13 2008
@@ -10,47 +10,31 @@
 #include <dbus/dbus.h>
 #include "mail-dbus.h"
 #include <camel/camel.h>
+#include "camel-object-remote.h"
 #include "camel-object-remote-impl.h"
-#include "dbind.h"
+#include "evo-dbus.h"
 
 extern GHashTable *store_hash;
 extern GHashTable *folder_hash;
 extern CamelSession *session;
 
-
-#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
-
-#define CAMEL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session"
-#define MAIL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session/mail"
-#define CAMEL_FOLDER_OBJECT_PATH "/org/gnome/evolution/camel/folder"
-#define CAMEL_STORE_OBJECT_PATH "/org/gnome/evolution/camel/store"
-
-#define CAMEL_SESSION_INTERFACE	"org.gnome.evolution.camel.session"
-#define MAIL_SESSION_INTERFACE	"org.gnome.evolution.camel.session.mail"
-#define CAMEL_STORE_INTERFACE "org.gnome.evolution.camel.store"
-#define CAMEL_FOLDER_INTERFACE "org.gnome.evolution.camel.folder"
-
 /* Session */
 static void 
 session_signal_cb (CamelObject *sess, gpointer ev_data, gpointer data)
 {
-	/* Signal back to the caller */
-	DBusMessage *signal;
 	DBusError err;
-	DBindContext *ctx = evolution_dbus_peek_context ();
+	dbus_bool_t ret;
 	dbus_error_init (&err);
 
-	DBusConnection *dbus = e_dbus_connection_get();
-	printf("Sending session cb signal\n");
-	signal = dbus_message_new_method_call ("org.gnome.evolution.mail", CAMEL_SESSION_OBJECT_PATH, 
-					CAMEL_SESSION_INTERFACE, 
-					"session_signal");
-	/* It sucks here to pass the pointer across the object */
-	dbus_message_append_args (signal, DBUS_TYPE_INT32, &ev_data, DBUS_TYPE_INT32, &data, DBUS_TYPE_INVALID);
-	if (!dbus_connection_send (dbus, signal, &err)) {
+	ret = dbind_context_method_call (e_dbus_peek_context(),
+					 CLIENT_DBUS_NAME,
+					 CAMEL_SESSION_OBJECT_PATH,
+					 CAMEL_SESSION_INTERFACE,
+					 "session_signal",
+					 &err, "ii", ev_data, data);
+
+	if (!ret)
 		g_warning ("error: %s\n", err.message);
-	}
-	dbus_message_unref (signal);
 }
 
 DBusHandlerResult

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	Wed Aug 27 20:21:13 2008
@@ -12,9 +12,6 @@
 
 #define d(x) x
 
-#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
-#define MAIL_SESSION_INTERFACE	"org.gnome.evolution.camel.session.mail"
-
 static char *obj_path[] = {CAMEL_SESSION_OBJECT_PATH, MAIL_SESSION_OBJECT_PATH, CAMEL_STORE_OBJECT_PATH, CAMEL_FOLDER_OBJECT_PATH};
 static char *obj_if[] = {CAMEL_SESSION_INTERFACE, MAIL_SESSION_INTERFACE, CAMEL_STORE_INTERFACE, CAMEL_FOLDER_INTERFACE};
 static int signal_inited = FALSE;
@@ -39,6 +36,7 @@
                                     void           *user_data);
 
 
+/* FIXME: needs to move into evo-dbus.[ch] */
 static int 
 register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg)
 {
@@ -50,8 +48,8 @@
 	dbus_listener_vtable->message_function = reg;
 	dbus_listener_vtable->unregister_function = unreg;
 	
-	ret = dbus_bus_request_name (ctx->cnx, "org.gnome.evolution.mail", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
-	printf("req bus :%d %s\n", ret, err.message);
+//	ret = dbus_bus_request_name (ctx->cnx, "org.gnome.evolution.mail", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
+//	printf("req bus :%d %s\n", ret, err.message);
 	if (!dbus_connection_register_object_path (ctx->cnx,
 						   object_path,
 						   dbus_listener_vtable,

Modified: branches/mail-dbus-remoting/mail/camel-object-remote.h
==============================================================================
--- branches/mail-dbus-remoting/mail/camel-object-remote.h	(original)
+++ branches/mail-dbus-remoting/mail/camel-object-remote.h	Wed Aug 27 20:21:13 2008
@@ -8,9 +8,13 @@
 #ifndef CAMEL_OBJECT_REMOTE_IMPL_H
 #define CAMEL_OBJECT_REMOTE_IMPL_H
 
-
 #include <camel/camel.h>
 
+/* the data server */
+#define CAMEL_DBUS_NAME "org.gnome.evolution.server.camel"
+/* the hard-coded, single client [yuck] */
+#define CLIENT_DBUS_NAME "org.gnome.evolution.client"
+
 #define CAMEL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session"
 #define MAIL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session/mail"
 #define CAMEL_FOLDER_OBJECT_PATH "/org/gnome/evolution/camel/folder"

Modified: branches/mail-dbus-remoting/mail/camel-session-remote.c
==============================================================================
--- branches/mail-dbus-remoting/mail/camel-session-remote.c	(original)
+++ branches/mail-dbus-remoting/mail/camel-session-remote.c	Wed Aug 27 20:21:13 2008
@@ -9,7 +9,6 @@
 #include "camel-session-remote.h"
 #include "camel-object-remote.h"
 
-#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
 extern GHashTable *store_hash;
 GHashTable *store_rhash = NULL;
 #define d(x) x

Modified: branches/mail-dbus-remoting/mail/camel-store-remote.c
==============================================================================
--- branches/mail-dbus-remoting/mail/camel-store-remote.c	(original)
+++ branches/mail-dbus-remoting/mail/camel-store-remote.c	Wed Aug 27 20:21:13 2008
@@ -8,12 +8,9 @@
 #include <dbind.h>
 #include <camel/camel-folder.h>
 #include "camel-store-remote.h"
+#include "camel-object-remote.h"
 extern GHashTable *folder_hash;
 
-#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
-#define CAMEL_STORE_INTERFACE "org.gnome.evolution.camel.store"
-#define CAMEL_STORE_OBJECT_PATH "/org/gnome/evolution/camel/store"
-
 CamelFolder *camel_store_get_folder_remote(CamelStoreRemote * store,
 					   const char *folder_name,
 					   guint32 flags,

Modified: branches/mail-dbus-remoting/mail/dbind-any.c
==============================================================================
--- branches/mail-dbus-remoting/mail/dbind-any.c	(original)
+++ branches/mail-dbus-remoting/mail/dbind-any.c	Wed Aug 27 20:21:13 2008
@@ -37,7 +37,7 @@
 }
 
 /* gather immediate allocation information for this type */
-static size_t dbind_gather_alloc_info_r (char **type)
+size_t dbind_gather_alloc_info_r (char **type)
 {
     char t = **type;
     (*type)++;
@@ -322,7 +322,6 @@
             ptr = ALIGN_ADDRESS (ptr, elem_align);
             dbind_any_demarshal (&child, &subt, &ptr);
             i++;
-	    dbus_message_iter_next (&child);
         };
         break;
     }
@@ -343,7 +342,6 @@
 			*data = PTR_PLUS (data0, offset);
             dbind_any_demarshal (&child, type, data);
             offset += dbind_gather_alloc_info (subt);
-            dbus_message_iter_next (&child);
         }
 
 		offset = ALIGN_VALUE (offset, stralign);
@@ -359,11 +357,13 @@
         warn_braces ();
         break;
     }
+    dbus_message_iter_next (iter);
 }
 
 static void
 dbind_any_free_r (char **type, void **data)
 {
+    size_t len;
 
 #ifdef DEBUG
     fprintf (stderr, "any free '%c' to %p\n", **type, *data);
@@ -388,7 +388,7 @@
         int i;
         GArray *vals = **(void ***)data;
         size_t elem_size, elem_align;
-        char *saved_child_type;
+        char *saved_child_type, *child_type_string;
 
         (*type)++;
         saved_child_type = *type;

Modified: branches/mail-dbus-remoting/mail/dbind.c
==============================================================================
--- branches/mail-dbus-remoting/mail/dbind.c	(original)
+++ branches/mail-dbus-remoting/mail/dbind.c	Wed Aug 27 20:21:13 2008
@@ -11,7 +11,6 @@
  *        do dynamic padding of structures etc.
  */
 
-
 DBindContext *
 dbind_create_context (DBusBusType type, DBusError *opt_error)
 {
@@ -26,12 +25,14 @@
         err = &real_err;
     }
    
-    cnx = dbus_bus_get (DBUS_BUS_SESSION, err);
+    cnx = dbus_bus_get_private (type, err);
     if (!cnx)
         goto out;
+
     ctx = g_new0 (DBindContext, 1);
     ctx->cnx = cnx;
     printf("DBIND DBUS %p\n", cnx);
+
 out:
     if (err == &real_err)
         dbus_error_free (err);
@@ -94,6 +95,31 @@
     return success;
 }
 
+static void set_reply (DBusPendingCall *pending, void *user_data)
+{
+  void **replyptr = (void **)user_data;
+
+  *replyptr = dbus_pending_call_steal_reply (pending);
+}
+
+static DBusMessage *
+send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, int timeout, DBusError *error)
+{
+  DBusPendingCall *pending;
+  DBusMessage *reply = NULL;
+
+  if (!dbus_connection_send_with_reply (bus, message, &pending, timeout))
+  {
+    return NULL;
+  }
+  dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
+  while (!reply)
+  {
+    if (!dbus_connection_read_write_dispatch (bus, timeout)) return NULL;
+  }
+  return reply;
+}
+
 dbus_bool_t
 dbind_connection_method_call_va (DBusConnection *cnx,
                                  const char *bus_name,
@@ -108,6 +134,7 @@
     DBusMessage *msg = NULL, *reply = NULL;
     DBusError *err, real_err;
     char *p;
+    char *dest;
 
     printf("DBIND: %s: %s: %s: %d\n", bus_name, path, method, dbus_connection_get_is_connected(cnx));
     if (opt_error)
@@ -160,11 +187,14 @@
             case DBUS_TYPE_OBJECT_PATH:
             case DBUS_TYPE_SIGNATURE:
             case DBUS_TYPE_ARRAY:
-            case DBUS_STRUCT_BEGIN_CHAR:
             case DBUS_TYPE_DICT_ENTRY:
                 ptrarg = va_arg (args, void *);
                 arg = &ptrarg;
                 break;
+            case DBUS_STRUCT_BEGIN_CHAR:
+                ptrarg = va_arg (args, void *);
+                arg = ptrarg;
+                break;
 
             case DBUS_TYPE_VARIANT:
                 fprintf (stderr, "No variant support yet - very toolkit specific\n");
@@ -180,17 +210,31 @@
             }
     }
 
-    reply = dbus_connection_send_with_reply_and_block (cnx, msg, -1, err);
+    dest = dbus_message_get_destination(msg);
+    if (!dest)
+        goto out;
+
+    /* We should clean evo.'s APIs up to not require re-enterancy later */
+    if (*p == '\0') { /* one-way */
+	success = dbus_connection_send (cnx, msg, NULL);
+	goto out;
+    } else {
+	reply = send_and_allow_reentry (cnx, msg, -1, err);
+    }
     if (!reply)
         goto out;
 
+    if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
+    {
+      char *name = dbus_message_get_error_name (reply);
+      dbus_set_error (err, name, g_strdup (""));
+      goto out;
+    }
     /* demarshal */
     if (p[0] == '=' && p[1] == '>')
     {
         DBusMessageIter iter;
         p += 2;
-        fprintf (stderr, "has return values\n");
-
         dbus_message_iter_init (reply, &iter);
         for (;*p != '\0';) {
             void *arg = va_arg (args, void *);
@@ -209,7 +253,6 @@
     if (err == &real_err)
         dbus_error_free (err);
 
-    printf("END: %d\n", dbus_connection_get_is_connected(cnx));
     return success;
 }
 

Modified: branches/mail-dbus-remoting/mail/dbind.h
==============================================================================
--- branches/mail-dbus-remoting/mail/dbind.h	(original)
+++ branches/mail-dbus-remoting/mail/dbind.h	Wed Aug 27 20:21:13 2008
@@ -5,10 +5,10 @@
 #define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/dbus.h>
 
-
 struct _DBindContext {
     DBusConnection *cnx;
 };
+
 typedef struct _DBindContext DBindContext;
 
 DBindContext *dbind_create_context         (DBusBusType type, DBusError *opt_error);
@@ -40,5 +40,4 @@
                                                const char *arg_types,
                                                va_list     args);
 
-
 #endif /* _DBIND_H_ */

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	Wed Aug 27 20:21:13 2008
@@ -11,15 +11,17 @@
 #include "evo-dbus.h"
 #include <dbind.h>
 #include <dbind-any.h>
-
+#include "camel-object-remote.h"
 
 #define d(x) x
 
-static DBindContext *ctx=NULL;
+static DBindContext *ctx = NULL;
 
 int
 evolution_dbus_init ()
 {
+	DBusError error;
+
 	if (ctx)
 		return 0;
 
@@ -29,6 +31,16 @@
 		return -1;
 	}
 
+	d(printf("Client context setup: request name\n"));
+	dbus_error_init (&error);
+	dbus_bus_request_name (ctx->cnx, CLIENT_DBUS_NAME, 0, &error);
+
+	if (dbus_error_is_set (&error)) {
+		g_warning ("**** dbus_bus_request_name error: %s\n", error.message);
+		dbus_error_free (&error);
+		return -1;
+	}
+
 	d(printf("DBind context setup: done\n"));
 
 	return 0;

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	Wed Aug 27 20:21:13 2008
@@ -14,8 +14,10 @@
 #include <dbind.h>
 #include <dbind-any.h>
 
+/* Methods to be used when calling the remote server
+   process from the client */
 
-int evolution_dbus_init (void);
-DBindContext * evolution_dbus_peek_context (void);
+int           evolution_dbus_init (void);
+DBindContext *evolution_dbus_peek_context (void);
 
 #endif

Modified: branches/mail-dbus-remoting/mail/mail-dbus.c
==============================================================================
--- branches/mail-dbus-remoting/mail/mail-dbus.c	(original)
+++ branches/mail-dbus-remoting/mail/mail-dbus.c	Wed Aug 27 20:21:13 2008
@@ -4,34 +4,22 @@
  * */
 
 #include <stdio.h>
+#include "dbind.h"
 #include "mail-dbus.h"
 #include "mail-session-remote-impl.h"
+#include "camel-object-remote.h"
 #include "camel-object-remote-impl.h"
 
 #define d(x) x
-#define DBUS_BUS_NAME "org.gnome.evolution.camel"
 
+static DBindContext *dbctx = NULL;
 static DBusConnection *dbus = NULL;
 GMainContext *gm_ctx = NULL;
 GMainLoop *main_loop = NULL;
 gboolean inited = FALSE;
 
-/* FIXME: This is from dbus internal file */
-#define DBUS_SESSION_BUS_DEFAULT_ADDRESS	"autolaunch:"
-
-static const char *
-get_session_address ()
-{
-	const char *address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
-
-	if (!address)
-		address = DBUS_SESSION_BUS_DEFAULT_ADDRESS;
-
-	return address;
-}
-
 DBusConnection *
-e_dbus_connection_get ()
+e_dbus_connection_get (void)
 {
 	DBusError error;
 
@@ -40,11 +28,10 @@
 
 	dbus_error_init (&error);
 
-//	if ((dbus = dbus_bus_get (DBUS_BUS_SESSION, &error))) {
-	if ((dbus = dbus_connection_open_private (get_session_address(), &error))) {
-		  dbus_bus_register(dbus, &error);
-	          dbus_connection_setup_with_g_main (dbus, gm_ctx);
-		  dbus_connection_set_exit_on_disconnect (dbus, FALSE);
+	dbctx = dbind_create_context (DBUS_BUS_SESSION, NULL);
+	if (dbctx && (dbus = dbctx->cnx)) {
+		dbus_connection_setup_with_g_main (dbus, gm_ctx);
+		dbus_connection_set_exit_on_disconnect (dbus, FALSE);
 	} else {
 		g_warning ("Failed to open connection to bus: %s\n", error.message);
 		dbus_error_free (&error);
@@ -52,9 +39,9 @@
 	}
 	printf("MAIL DBUS %p\n", dbus);
 	dbus_bus_request_name (dbus,
-				 DBUS_BUS_NAME,
-				 0,
-				 &error);
+			       CAMEL_DBUS_NAME,
+			       0,
+			       &error);
 
 	if (dbus_error_is_set (&error)) {
 		g_warning ("dbus_bus_request_name error: %s\n", error.message);
@@ -225,3 +212,9 @@
 
 	return 0;
 }
+
+DBindContext *
+e_dbus_peek_context (void)
+{
+	return dbctx;
+}

Modified: branches/mail-dbus-remoting/mail/mail-dbus.h
==============================================================================
--- branches/mail-dbus-remoting/mail/mail-dbus.h	(original)
+++ branches/mail-dbus-remoting/mail/mail-dbus.h	Wed Aug 27 20:21:13 2008
@@ -1,21 +1,26 @@
 /*  
  * Authors: Srinivasa Ragavan <sragavan novell com>
- *
  * */
 
-
-
-#include <dbus/dbus.h>
+#include "dbind.h"
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-int e_dbus_register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg);
-
-void e_dbus_connection_close (void);
+/* methods to be used when implementing the server process,
+   and to call-back into the client */
 
-int e_dbus_setup_handlers (void);
-char * e_dbus_get_store_hash (const char *store_url);
+int             mail_dbus_init(void);
 
-char * e_dbus_get_folder_hash (const char *store_url, const char *folder_name);
-DBusConnection * e_dbus_connection_get (void);
-int mail_dbus_init(void);
+char           *e_dbus_get_folder_hash (const char *store_url, const char *folder_name);
+DBindContext   *e_dbus_peek_context (void);
+DBusConnection *e_dbus_connection_get (void);
+int             e_dbus_setup_handlers (void);
+char           *e_dbus_get_store_hash (const char *store_url);
+int             e_dbus_register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg);
+void            e_dbus_connection_close (void);
+
+/* urgh - external init fn's we use */
+extern void mail_session_remote_impl_init (void);
+extern void camel_session_remote_impl_init (void);
+extern void camel_object_remote_impl_init (void);
+extern void camel_store_remote_impl_init (void);

Modified: branches/mail-dbus-remoting/mail/mail-session-remote.c
==============================================================================
--- branches/mail-dbus-remoting/mail/mail-session-remote.c	(original)
+++ branches/mail-dbus-remoting/mail/mail-session-remote.c	Wed Aug 27 20:21:13 2008
@@ -8,12 +8,9 @@
 #include "dbind.h"
 #include <mail-dbus.h>
 #include "evo-dbus.h"
+#include "camel-object-remote.h"
 #include "mail-session-remote.h"
 
-#define MAIL_SESSION_INTERFACE	"org.gnome.evolution.camel.session.mail"
-#define MAIL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session/mail"
-#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
-
 #define d(x) x
 
 void

Modified: branches/mail-dbus-remoting/server.mk
==============================================================================
--- branches/mail-dbus-remoting/server.mk	(original)
+++ branches/mail-dbus-remoting/server.mk	Wed Aug 27 20:21:13 2008
@@ -1,4 +1,4 @@
-%.server.in: %.server.in.in
+%.server.in: %.server.in.in $(top_srcdir)/config.h
 	sed -e 's|\ BINDIR_IN_SERVER_FILE\@|$(bindir_in_server_file)|'	\
 	-e 's|\ PRIVLIBEXECDIR_IN_SERVER_FILE\@|$(privlibexecdir_in_server_file)|'	\
 	-e 's|\ COMPONENTDIR_IN_SERVER_FILE\@|$(componentdir_in_server_file)|'	\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]