evolution r36077 - branches/mail-dbus-remoting/mail



Author: sragavan
Date: Tue Aug 26 10:43:19 2008
New Revision: 36077
URL: http://svn.gnome.org/viewvc/evolution?rev=36077&view=rev

Log:
Implement CamelRemoteObject:


Added:
   branches/mail-dbus-remoting/mail/camel-object-remote-impl.c
   branches/mail-dbus-remoting/mail/camel-object-remote-impl.h
   branches/mail-dbus-remoting/mail/camel-object-remote.c
   branches/mail-dbus-remoting/mail/camel-object-remote.h
Modified:
   branches/mail-dbus-remoting/mail/Makefile.am

Modified: branches/mail-dbus-remoting/mail/Makefile.am
==============================================================================
--- branches/mail-dbus-remoting/mail/Makefile.am	(original)
+++ branches/mail-dbus-remoting/mail/Makefile.am	Tue Aug 26 10:43:19 2008
@@ -206,7 +206,11 @@
 	mail-session-remote.c			\
 	mail-session-remote.h			\
 	mail-session-remote-impl.c		\
-	mail-session-remote-impl.h		
+	mail-session-remote-impl.h		\
+	camel-object-remote.c			\
+	camel-object-remote.h			\
+	camel-object-remote-impl.c		\
+	camel-object-remote-impl.h	
 
 
 if ENABLE_SMIME

Added: branches/mail-dbus-remoting/mail/camel-object-remote-impl.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-object-remote-impl.c	Tue Aug 26 10:43:19 2008
@@ -0,0 +1,260 @@
+/*
+ * 
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <string.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus.h>
+#include "mail-dbus.h"
+#include <camel/camel.h>
+#include "camel-object-remote-impl.h"
+
+extern GHashTable *store_hash;
+extern GHashTable *folder_hash;
+extern CamelSession *session;
+
+
+#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.mail"
+#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 DBusHandlerResult
+dbus_listener_session_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+
+static void 
+session_signal_cb (CamelObject *sess, gpointer ev_data, gpointer data)
+{
+	/* Signal back to the caller */
+	DBusMessage *signal;
+	DBusConnection *dbus = e_dbus_connection_get();
+
+	signal = dbus_message_new_signal (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_STRING, &data, DBUS_TYPE_INVALID);
+	dbus_connection_send (dbus, signal, NULL);
+	dbus_message_unref (signal);
+	dbus_connection_flush(dbus);
+}
+
+static DBusHandlerResult
+dbus_listener_session_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+	const char *method = dbus_message_get_member (message);
+	DBusMessage *return_val;
+	gboolean added = FALSE;
+	CamelSession *session = NULL;
+
+  	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+	
+	
+	return_val = dbus_message_new_method_return (message);
+
+	if (strcmp(method, "camel_object_hook_event") == 0) {
+		char *signal, *data, *object_hash;
+		unsigned int ret_id;
+
+		dbus_message_get_args(message, NULL,
+				DBUS_TYPE_STRING, &object_hash,
+				DBUS_TYPE_STRING, &signal,
+				DBUS_TYPE_STRING, &data,
+				DBUS_TYPE_INVALID);
+
+		ret_id = camel_object_hook_event (session, signal, (CamelObjectEventHookFunc)session_signal_cb, data);
+		dbus_message_append_args (return_val, DBUS_TYPE_UINT32, &ret_id, DBUS_TYPE_INVALID);
+		added = TRUE;
+	} else /* FIXME: Free memory and return */
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!added)
+		dbus_message_append_args (return_val, DBUS_TYPE_INVALID);
+
+	dbus_connection_send (connection, return_val, NULL);
+	dbus_message_unref (return_val);
+	dbus_connection_flush(connection);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+
+}
+
+/* Store */
+static DBusHandlerResult
+dbus_listener_store_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+
+static char *
+hash_store (CamelObject *store)
+{
+	return e_dbus_get_store_hash (camel_service_get_url((CamelService *)store));
+}
+
+static void 
+store_signal_cb (CamelObject *store, gpointer ev_data, gpointer data)
+{
+	/* Signal back to the caller */
+	DBusMessage *signal;
+	DBusConnection *dbus = e_dbus_connection_get();
+	char *hash = hash_store (store);
+
+	signal = dbus_message_new_signal (CAMEL_STORE_OBJECT_PATH, 
+					CAMEL_STORE_INTERFACE, 
+					"store_signal");
+	/* It sucks here to pass the pointer across the object */
+	dbus_message_append_args (signal, DBUS_TYPE_STRING, &hash, DBUS_TYPE_INT32, &ev_data, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID);
+	dbus_connection_send (dbus, signal, NULL);
+	dbus_message_unref (signal);
+	dbus_connection_flush(dbus);
+}
+
+static DBusHandlerResult
+dbus_listener_store_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+	const char *method = dbus_message_get_member (message);
+	DBusMessage *return_val;
+	gboolean added = FALSE;
+
+  	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+	
+	
+	return_val = dbus_message_new_method_return (message);
+
+	if (strcmp(method, "camel_object_hook_event") == 0) {
+		char *signal, *data, *object_hash;
+		unsigned int ret_id;
+		CamelObject *obj;
+
+		dbus_message_get_args(message, NULL,
+				DBUS_TYPE_STRING, &object_hash,
+				DBUS_TYPE_STRING, &signal,
+				DBUS_TYPE_STRING, &data,
+				DBUS_TYPE_INVALID);
+		obj = g_hash_table_lookup (store_hash, object_hash);
+		ret_id = camel_object_hook_event (obj, signal, (CamelObjectEventHookFunc)store_signal_cb, data);
+		dbus_message_append_args (return_val, DBUS_TYPE_UINT32, &ret_id, DBUS_TYPE_INVALID);
+		added = TRUE;
+	} else /* FIXME: Free memory and return */
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!added)
+		dbus_message_append_args (return_val, DBUS_TYPE_INVALID);
+
+	dbus_connection_send (connection, return_val, NULL);
+	dbus_message_unref (return_val);
+	dbus_connection_flush(connection);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+
+}
+
+
+/* Folder */
+static DBusHandlerResult
+dbus_listener_folder_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+
+static char *
+hash_folder (CamelObject *obj)
+{
+	CamelFolder *folder = (CamelFolder *)obj;
+	return e_dbus_get_folder_hash (camel_service_get_url((CamelService *)folder->parent_store), folder->full_name);
+}
+
+static void 
+folder_signal_cb (CamelObject *folder, gpointer ev_data, gpointer data)
+{
+	/* Signal back to the caller */
+	DBusMessage *signal;
+	DBusConnection *dbus = e_dbus_connection_get();
+	char *hash = hash_folder(folder);
+	signal = dbus_message_new_signal (CAMEL_FOLDER_OBJECT_PATH, 
+					CAMEL_FOLDER_INTERFACE, 
+					"folder_signal");
+	/* It sucks here to pass the pointer across the object */
+	dbus_message_append_args (signal, DBUS_TYPE_STRING, &hash, DBUS_TYPE_INT32, &ev_data, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID);
+	dbus_connection_send (dbus, signal, NULL);
+	dbus_message_unref (signal);
+	dbus_connection_flush(dbus);
+}
+
+static DBusHandlerResult
+dbus_listener_folder_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+	const char *method = dbus_message_get_member (message);
+	DBusMessage *return_val;
+	gboolean added = FALSE;
+
+  	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+	
+	
+	return_val = dbus_message_new_method_return (message);
+
+	if (strcmp(method, "camel_object_hook_event") == 0) {
+		char *signal, *data, *object_hash;
+		unsigned int ret_id;
+		CamelObject *obj;
+
+		dbus_message_get_args(message, NULL,
+				DBUS_TYPE_STRING, &object_hash,
+				DBUS_TYPE_STRING, &signal,
+				DBUS_TYPE_STRING, &data,
+				DBUS_TYPE_INVALID);
+		obj = g_hash_table_lookup (folder_hash, object_hash);
+		ret_id = camel_object_hook_event (obj, signal, (CamelObjectEventHookFunc)folder_signal_cb, data);
+		dbus_message_append_args (return_val, DBUS_TYPE_UINT32, &ret_id, DBUS_TYPE_INVALID);
+		added = TRUE;
+	} else /* FIXME: Free memory and return */
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!added)
+		dbus_message_append_args (return_val, DBUS_TYPE_INVALID);
+
+	dbus_connection_send (connection, return_val, NULL);
+	dbus_message_unref (return_val);
+	dbus_connection_flush(connection);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+
+}
+
+
+void
+camel_object_remote_impl_init ()
+{
+	e_dbus_register_handler (CAMEL_SESSION_OBJECT_PATH, dbus_listener_session_handler, NULL);
+	e_dbus_register_handler (CAMEL_STORE_OBJECT_PATH, dbus_listener_store_handler, NULL);
+	e_dbus_register_handler (CAMEL_FOLDER_OBJECT_PATH, dbus_listener_folder_handler, NULL);
+}
+

Added: branches/mail-dbus-remoting/mail/camel-object-remote-impl.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-object-remote-impl.h	Tue Aug 26 10:43:19 2008
@@ -0,0 +1,14 @@
+/*  
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+
+#ifndef CAMEL_OBJECT_REMOTE_IMPL_H
+#define CAMEL_OBJECT_REMOTE_IMPL_H
+
+
+void
+camel_object_remote_impl_init (void);
+
+#endif

Added: branches/mail-dbus-remoting/mail/camel-object-remote.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-object-remote.c	Tue Aug 26 10:43:19 2008
@@ -0,0 +1,155 @@
+/*
+ * 
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+
+#include "camel-object-remote.h"
+#include <dbus/dbus.h>
+#include <dbind.h>
+#include <evo-dbus.h>
+
+#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;
+static GHashTable *objects;
+
+static DBusHandlerResult
+dbus_listener_store_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+static DBusHandlerResult
+dbus_listener_session_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+
+static DBusHandlerResult
+dbus_listener_folder_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data);
+
+
+static int 
+register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg)
+{
+	DBusObjectPathVTable *dbus_listener_vtable;
+	DBindContext *ctx = evolution_dbus_peek_context ();
+
+	dbus_listener_vtable = g_new0 (DBusObjectPathVTable, 1);
+	dbus_listener_vtable->message_function = reg;
+	dbus_listener_vtable->unregister_function = unreg;
+
+	if (!dbus_connection_register_object_path (ctx->cnx,
+						   object_path,
+						   dbus_listener_vtable,
+						   NULL)) {
+		g_warning (("Out of memory registering object path '%s'"), object_path);
+		return -1;
+	}
+
+	d(printf("successfully inited signal for %s\n", object_path));
+	return 0;
+}
+
+static char *
+hash_data (CamelObjectEventHookFunc func, gpointer data)
+{
+	return g_strdup_printf ("%p:%p", (gpointer)func, data);
+}
+
+unsigned int
+camel_object_remote_hook_event (CamelRemoteObject *object, char *signal, CamelObjectEventHookFunc func, gpointer data)
+{
+	CamelRemoteHook *hook;
+	gboolean ret;
+	DBusError error;
+	char *hash;
+
+	if (!signal_inited) {
+		signal_inited = TRUE;
+		objects = g_hash_table_new (g_str_hash, g_str_equal);
+		register_handler (CAMEL_SESSION_OBJECT_PATH, dbus_listener_session_handler, NULL);
+		register_handler (CAMEL_STORE_OBJECT_PATH, dbus_listener_store_handler, NULL);
+		register_handler (CAMEL_FOLDER_OBJECT_PATH, dbus_listener_folder_handler, NULL);
+	}
+
+	hook = g_new (CamelRemoteHook, 1);
+	hook->object_id = g_strdup (object->object_id);
+	hook->signal = g_strdup (signal);
+	hook->func = func;
+	hook->data = data;
+	hook->remote_id = 0;
+
+	dbus_error_init (&error);
+	/* Invoke the appropriate dbind call to MailSessionRemoteImpl */
+	hash = hash_data (func, data);
+	ret = dbind_context_method_call (evolution_dbus_peek_context(), 
+			CAMEL_DBUS_NAME,
+			obj_path[object->type],
+			obj_if[object->type],
+			"camel_object_hook_event",
+			&error, 
+			"sss=>u", object->object_id, signal, hash, &hook->remote_id); /* Just string of base dir */
+
+	if (!ret) {
+		g_warning ("Error: Initializing mail session: %s\n", error.message);
+		return 0;
+	}
+	
+	/* We purposefully append */
+	object->hooks = g_list_append (object->hooks, hook);
+	d(printf("Mail session initated remotely\n"));
+	if(!g_hash_table_lookup(objects, object->object_id))
+		g_hash_table_insert (objects, object->object_id, object);
+
+	return hook->remote_id;
+}
+
+
+static DBusHandlerResult
+dbus_listener_store_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+  	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+static DBusHandlerResult
+dbus_listener_session_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+
+}
+static DBusHandlerResult
+dbus_listener_folder_handler (DBusConnection *connection,
+                                    DBusMessage    *message,
+                                    void           *user_data)
+{
+	printf ("D-Bus message: obj_path = '%s' interface = '%s' method = '%s' destination = '%s'\n",
+           dbus_message_get_path (message),
+           dbus_message_get_interface (message),
+           dbus_message_get_member (message),
+           dbus_message_get_destination (message));
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+

Added: branches/mail-dbus-remoting/mail/camel-object-remote.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-object-remote.h	Tue Aug 26 10:43:19 2008
@@ -0,0 +1,50 @@
+/*
+ * 
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+
+#ifndef CAMEL_OBJECT_REMOTE_IMPL_H
+#define CAMEL_OBJECT_REMOTE_IMPL_H
+
+
+#include <camel/camel.h>
+
+#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.mail"
+#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"
+
+typedef struct _CamelRemoteHook {
+	char *object_id;
+	char *signal;
+	CamelObjectEventHookFunc func;
+	gpointer data;
+	guint remote_id;
+}CamelRemoteHook;
+
+typedef enum {
+	CAMEL_RO_SESSION=0,
+	CAMEL_RO_MSESSION,
+	CAMEL_RO_STORE,
+	CAMEL_RO_FOLDER
+}CamelRemoteObjectType;
+
+
+typedef struct _CamelRemoteObject {
+	char *object_id;
+	CamelRemoteObjectType type;
+	GList *hooks; /* Hooks of CamelRemoteHook */
+}CamelRemoteObject;
+
+
+unsigned int
+camel_object_remote_hook_event (CamelRemoteObject *object, char *signal, CamelObjectEventHookFunc func, gpointer data);
+
+#endif



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