evolution r36049 - branches/mail-dbus-remoting/mail
- From: sragavan svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution r36049 - branches/mail-dbus-remoting/mail
- Date: Mon, 25 Aug 2008 18:17:00 +0000 (UTC)
Author: sragavan
Date: Mon Aug 25 18:17:00 2008
New Revision: 36049
URL: http://svn.gnome.org/viewvc/evolution?rev=36049&view=rev
Log:
Initial commit for Mail to e-d-s.
Added:
branches/mail-dbus-remoting/mail/camel-session-remote-impl.c
branches/mail-dbus-remoting/mail/camel-session-remote.c
branches/mail-dbus-remoting/mail/camel-session-remote.h
branches/mail-dbus-remoting/mail/camel-store-remote-impl.c
branches/mail-dbus-remoting/mail/camel-store-remote.c
branches/mail-dbus-remoting/mail/camel-store-remote.h
branches/mail-dbus-remoting/mail/dbind-any.c
branches/mail-dbus-remoting/mail/dbind-any.h
branches/mail-dbus-remoting/mail/dbind-config.h
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-impl.c
branches/mail-dbus-remoting/mail/mail-session-remote.c
branches/mail-dbus-remoting/mail/mail-session-remote.h
Modified:
branches/mail-dbus-remoting/mail/Makefile.am
branches/mail-dbus-remoting/mail/mail-component.c
Modified: branches/mail-dbus-remoting/mail/Makefile.am
==============================================================================
--- branches/mail-dbus-remoting/mail/Makefile.am (original)
+++ branches/mail-dbus-remoting/mail/Makefile.am Mon Aug 25 18:17:00 2008
@@ -29,7 +29,9 @@
-DEVOLUTION_UIDIR=\""$(evolutionuidir)"\" \
-DCAMEL_PROVIDERDIR=\""$(camel_providerdir)"\" \
-DPREFIX=\""$(prefix)"\" \
- -DG_LOG_DOMAIN=\"evolution-mail\"
+ -DG_LOG_DOMAIN=\"evolution-mail\" \
+ -I/usr/include/dbus-1.0 \
+ -I/usr/lib/dbus-1.0/include
component_LTLIBRARIES = libevolution-mail.la
@@ -184,7 +186,28 @@
message-tag-editor.c \
message-tag-editor.h \
message-tag-followup.c \
- message-tag-followup.h
+ message-tag-followup.h \
+ dbind.c \
+ dbind.h \
+ dbind-any.c \
+ dbind-any.h \
+ camel-store-remote.c \
+ camel-store-remote.h \
+ camel-store-remote-impl.c \
+ camel-store-remote-impl.h \
+ mail-dbus.c \
+ mail-dbus.h \
+ evo-dbus.c \
+ evo-dbus.h \
+ camel-session-remote.c \
+ camel-session-remote.h \
+ camel-session-remote-impl.c \
+ camel-session-remote-impl.h \
+ mail-session-remote.c \
+ mail-session-remote.h \
+ mail-session-remote-impl.c \
+ mail-session-remote-impl.h
+
if ENABLE_SMIME
SMIME_LIBS = \
@@ -210,7 +233,8 @@
$(EVOLUTION_MAIL_LIBS) \
$(GTKHTML_LIBS) \
$(REGEX_LIBS) \
- $(THREADS_LIBS)
+ $(THREADS_LIBS) \
+ -ldbus-1 -ldbus-glib-1
libevolution_mail_la_LDFLAGS = \
-avoid-version -module $(NO_UNDEFINED)
Added: branches/mail-dbus-remoting/mail/camel-session-remote-impl.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-session-remote-impl.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,45 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <glib.h>
+#include "mail-dbus.h"
+
+#define CAMEL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session"
+
+static gboolean session_setup = FALSE;
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+
+
+
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ const char *method = dbus_message_get_member (message);
+
+ 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;
+
+}
+
+void
+camel_session_remote_impl_init ()
+{
+ session_setup = TRUE;
+ e_dbus_register_handler (CAMEL_SESSION_OBJECT_PATH, dbus_listener_message_handler, NULL);
+}
+
+
Added: branches/mail-dbus-remoting/mail/camel-session-remote.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-session-remote.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,8 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#define CAMEL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session"
+#define CAMEL_DBUS_NAME "org.gnome.evolution.camel"
+
Added: branches/mail-dbus-remoting/mail/camel-session-remote.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-session-remote.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,8 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+typedef struct CamelSessionRemote {
+ char *object_id;
+};
Added: branches/mail-dbus-remoting/mail/camel-store-remote-impl.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-store-remote-impl.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,47 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <glib.h>
+#include "mail-dbus.h"
+
+#define CAMEL_STORE_OBJECT_PATH "/org/gnome/evolution/camel/store"
+
+static gboolean store_setup = FALSE;
+GHashTable *store_hash = NULL;
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+
+
+
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ const char *method = dbus_message_get_member (message);
+
+ 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;
+
+}
+
+void
+camel_store_remote_impl_init ()
+{
+ store_setup = TRUE;
+ store_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ e_dbus_register_handler (CAMEL_STORE_OBJECT_PATH, dbus_listener_message_handler, NULL);
+}
+
+
Added: branches/mail-dbus-remoting/mail/camel-store-remote.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-store-remote.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,8 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#define DBUS_SERVER_OBJECT_PATH "/org/gnome/evolution/camel/store"
+#define DBUS_BUS_NAME "org.gnome.evolution.camel"
+
Added: branches/mail-dbus-remoting/mail/camel-store-remote.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/camel-store-remote.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,8 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+typedef struct CamelStoreRemote {
+ char *object_id;
+};
Added: branches/mail-dbus-remoting/mail/dbind-any.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/dbind-any.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,453 @@
+/* type driven marshalling */
+#include "config.h"
+#include "dbind-config.h"
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <stdio.h>
+#include <glib.h>
+#include "dbind-any.h"
+
+#undef DEBUG
+
+/* Align a value upward to a boundary, expressed as a number of bytes.
+ E.g. align to an 8-byte boundary with argument of 8. */
+
+/*
+ * (this + boundary - 1)
+ * &
+ * ~(boundary - 1)
+ */
+
+#define ALIGN_VALUE(this, boundary) \
+ (( ((gulong)(this)) + (((gulong)(boundary)) -1)) & (~(((gulong)(boundary))-1)))
+
+#define ALIGN_ADDRESS(this, boundary) \
+ ((gpointer)ALIGN_VALUE(this, boundary))
+
+#define PTR_PLUS(ptr, offset) \
+ ((gpointer) (((guchar *)(ptr)) + (offset)))
+
+unsigned int dbind_find_c_alignment_r (char **type);
+unsigned int dbind_find_c_alignment (char *type);
+
+static void
+warn_braces ()
+{
+ fprintf (stderr, "Error: dbus flags structures & dicts with braces rather than "
+ " an explicit type member of 'struct'\n");
+}
+
+/* gather immediate allocation information for this type */
+size_t dbind_gather_alloc_info_r (char **type)
+{
+ char t = **type;
+ (*type)++;
+ if (t == DBUS_TYPE_ARRAY) {
+ switch (**type) {
+ case DBUS_STRUCT_BEGIN_CHAR:
+ while (**type != DBUS_STRUCT_END_CHAR && **type != '\0') (*type)++;
+ if (**type != '\0') (*type)++;
+ break;
+ case '\0':
+ break;
+ default:
+ (*type)++;
+ break;
+ }
+ }
+
+ switch (t) {
+ case DBUS_TYPE_BYTE:
+ return sizeof (char);
+ case DBUS_TYPE_BOOLEAN:
+ return sizeof (dbus_bool_t);
+ case DBUS_TYPE_INT16:
+ case DBUS_TYPE_UINT16:
+ return sizeof (dbus_int16_t);
+ case DBUS_TYPE_INT32:
+ case DBUS_TYPE_UINT32:
+ return sizeof (dbus_int32_t);
+ case DBUS_TYPE_INT64:
+ case DBUS_TYPE_UINT64:
+ return sizeof (dbus_int64_t);
+ case DBUS_TYPE_DOUBLE:
+ return sizeof (double);
+ /* ptr types */
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+ case DBUS_TYPE_ARRAY:
+ return sizeof (void *);
+ case DBUS_STRUCT_BEGIN_CHAR: {
+ int sum = 0, stralign;
+
+ stralign = dbind_find_c_alignment (*type - 1);
+
+ while (**type != DBUS_STRUCT_END_CHAR) {
+ sum = ALIGN_VALUE (sum, dbind_find_c_alignment (*type));
+ sum += dbind_gather_alloc_info_r (type);
+ }
+ sum = ALIGN_VALUE (sum, stralign);
+
+ g_assert (**type == DBUS_STRUCT_END_CHAR);
+ (*type)++;
+
+ return sum;
+ }
+ case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
+ warn_braces ();
+ default:
+ return 0;
+ }
+}
+
+size_t dbind_gather_alloc_info (char *type)
+{
+ return dbind_gather_alloc_info_r (&type);
+}
+
+unsigned int
+dbind_find_c_alignment_r (char **type)
+{
+ unsigned int retval = 1;
+
+ char t = **type;
+ (*type)++;
+
+#ifdef DEBUG
+ fprintf (stderr, "\tfind align for %c (0x%x)\n", t, t);
+#endif
+
+ switch (t) {
+ case DBUS_TYPE_BYTE:
+ return DBIND_ALIGNOF_CHAR;
+ case DBUS_TYPE_BOOLEAN:
+ return DBIND_ALIGNOF_DBUS_BOOL_T;
+ case DBUS_TYPE_INT16:
+ case DBUS_TYPE_UINT16:
+ return DBIND_ALIGNOF_DBUS_INT16_T;
+ case DBUS_TYPE_INT32:
+ case DBUS_TYPE_UINT32:
+ return DBIND_ALIGNOF_DBUS_INT32_T;
+ case DBUS_TYPE_INT64:
+ case DBUS_TYPE_UINT64:
+ return DBIND_ALIGNOF_DBUS_INT64_T;
+ case DBUS_TYPE_DOUBLE:
+ return DBIND_ALIGNOF_DOUBLE;
+ /* ptr types */
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+ case DBUS_TYPE_ARRAY:
+ return DBIND_ALIGNOF_DBIND_POINTER;
+ case DBUS_STRUCT_BEGIN_CHAR:
+#if DBIND_ALIGNOF_DBIND_STRUCT > 1
+ retval = MAX (retval, DBIND_ALIGNOF_DBIND_STRUCT);
+#endif
+ while (**type != DBUS_STRUCT_END_CHAR) {
+ int elem_align = dbind_find_c_alignment_r (type);
+ retval = MAX (retval, elem_align);
+ }
+ (*type)++;
+ return retval;
+ case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
+ warn_braces ();
+ return DBIND_ALIGNOF_DBIND_POINTER;
+ case '\0':
+ g_assert_not_reached();
+ break;
+ default:
+ return 1;
+ }
+}
+
+unsigned int
+dbind_find_c_alignment (char *type)
+{
+ return dbind_find_c_alignment_r (&type);
+}
+
+#define DBIND_POD_CASES \
+ DBUS_TYPE_BYTE: \
+ case DBUS_TYPE_INT16: \
+ case DBUS_TYPE_UINT16: \
+ case DBUS_TYPE_INT32: \
+ case DBUS_TYPE_UINT32: \
+ case DBUS_TYPE_BOOLEAN: \
+ case DBUS_TYPE_INT64: \
+ case DBUS_TYPE_UINT64: \
+ case DBUS_TYPE_DOUBLE
+
+void
+dbind_any_marshal (DBusMessageIter *iter,
+ char **type,
+ void **data)
+{
+ size_t len;
+
+#ifdef DEBUG
+ fprintf (stderr, "any marshal '%c' to %p\n", **type, *data);
+#endif
+
+ switch (**type) {
+ case DBIND_POD_CASES:
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+ len = dbind_gather_alloc_info (*type);
+ dbus_message_iter_append_basic (iter, **type, *data);
+ *data = ((guchar *)*data) + len;
+ (*type)++;
+ break;
+ case DBUS_TYPE_ARRAY: {
+ int i;
+ GArray *vals = **(void ***)data;
+ size_t elem_size, elem_align;
+ DBusMessageIter sub;
+ char *saved_child_type, *child_type_string;
+
+ (*type)++;
+ saved_child_type = *type;
+
+ elem_size = dbind_gather_alloc_info (*type);
+ elem_align = dbind_find_c_alignment_r (type);
+
+ /* wow this part of the API sucks too ... */
+ child_type_string = g_strndup (saved_child_type, *type - saved_child_type);
+/* fprintf (stderr, "array child type '%s'\n", child_type_string); */
+ dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY,
+ child_type_string, &sub);
+ for (i = 0; i < vals->len; i++) {
+ void *ptr = vals->data + elem_size * i;
+ *type = saved_child_type; /* rewind type info */
+ ptr = ALIGN_ADDRESS (ptr, elem_align);
+ dbind_any_marshal (&sub, type, &ptr);
+ }
+
+ dbus_message_iter_close_container (iter, &sub);
+ g_free (child_type_string);
+ break;
+ }
+ case DBUS_STRUCT_BEGIN_CHAR: {
+ gconstpointer data0 = *data;
+ int offset = 0, stralign;
+ DBusMessageIter sub;
+
+ stralign = dbind_find_c_alignment (*type);
+
+ (*type)++;
+
+ dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL, &sub);
+
+ offset = 0 ;
+ while (**type != DBUS_STRUCT_END_CHAR) {
+ char *subt = *type;
+ offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
+ *data = PTR_PLUS (data0, offset);
+ dbind_any_marshal (&sub, type, data);
+ offset += dbind_gather_alloc_info (subt);
+ }
+
+ offset = ALIGN_VALUE (offset, stralign);
+ *data = PTR_PLUS (data0, offset);
+
+ dbus_message_iter_close_container (iter, &sub);
+
+ g_assert (**type == DBUS_STRUCT_END_CHAR);
+ (*type)++;
+
+ break;
+ }
+ case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
+ warn_braces ();
+ break;
+ }
+}
+
+void
+dbind_any_demarshal (DBusMessageIter *iter,
+ char **type,
+ void **data)
+{
+ size_t len;
+
+#ifdef DEBUG
+ fprintf (stderr, "any demarshal '%c' to %p\n", **type, *data);
+#endif
+
+ switch (**type) {
+ case DBIND_POD_CASES:
+ len = dbind_gather_alloc_info (*type);
+ dbus_message_iter_get_basic (iter, *data);
+ *data = ((guchar *)*data) + len;
+ (*type)++;
+ break;
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+ len = dbind_gather_alloc_info (*type);
+ dbus_message_iter_get_basic (iter, *data);
+#ifdef DEBUG
+ fprintf (stderr, "dup string '%s' (%p)\n", **(void ***)data, **(void ***)data);
+#endif
+ **(void ***)data = g_strdup (**(void ***)data);
+ *data = ((guchar *)*data) + len;
+ (*type)++;
+ break;
+ case DBUS_TYPE_ARRAY: {
+ GArray *vals;
+ DBusMessageIter child;
+ size_t elem_size, elem_align;
+ char *stored_child_type;
+ int i;
+
+ (*type)++;
+ stored_child_type = *type;
+
+ elem_size = dbind_gather_alloc_info (*type);
+ elem_align = dbind_find_c_alignment_r (type);
+ vals = g_array_new (FALSE, FALSE, elem_size);
+ (**(void ***)data) = vals;
+ *data = ((guchar *)*data) + sizeof (void *);
+
+ i = 0;
+ dbus_message_iter_recurse (iter, &child);
+ while (dbus_message_iter_get_arg_type (&child) != DBUS_TYPE_INVALID) {
+ void *ptr;
+ char *subt = stored_child_type;
+ g_array_set_size (vals, i + 1);
+ ptr = vals->data + elem_size * i;
+ ptr = ALIGN_ADDRESS (ptr, elem_align);
+ dbind_any_demarshal (&child, &subt, &ptr);
+ i++;
+ dbus_message_iter_next (&child);
+ };
+ break;
+ }
+ case DBUS_STRUCT_BEGIN_CHAR: {
+ gconstpointer data0 = *data;
+ int offset = 0, stralign;
+ DBusMessageIter child;
+
+ stralign = dbind_find_c_alignment (*type);
+
+ (*type)++;
+
+ dbus_message_iter_recurse (iter, &child);
+
+ while (**type != DBUS_STRUCT_END_CHAR) {
+ char *subt = *type;
+ offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
+ *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);
+ *data = PTR_PLUS (data0, offset);
+
+ g_assert (**type == DBUS_STRUCT_END_CHAR);
+ (*type)++;
+
+ break;
+ }
+ case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
+ warn_braces ();
+ break;
+ }
+}
+
+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);
+#endif
+
+ switch (**type) {
+ case DBIND_POD_CASES:
+ *data = ((guchar *)*data) + dbind_gather_alloc_info (*type);
+ (*type)++;
+ break;
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+#ifdef DEBUG
+ fprintf (stderr, "string free %p\n", **(void ***)data);
+#endif
+ g_free (**(void ***)data);
+ *data = ((guchar *)*data) + dbind_gather_alloc_info (*type);
+ (*type)++;
+ break;
+ case DBUS_TYPE_ARRAY: {
+ int i;
+ GArray *vals = **(void ***)data;
+ size_t elem_size, elem_align;
+ char *saved_child_type, *child_type_string;
+
+ (*type)++;
+ saved_child_type = *type;
+
+ elem_size = dbind_gather_alloc_info (*type);
+ elem_align = dbind_find_c_alignment_r (type);
+
+ for (i = 0; i < vals->len; i++) {
+ void *ptr = vals->data + elem_size * i;
+ *type = saved_child_type; /* rewind type info */
+ ptr = ALIGN_ADDRESS (ptr, elem_align);
+ dbind_any_free_r (type, &ptr);
+ }
+ g_array_free (vals, TRUE);
+ break;
+ }
+ case DBUS_STRUCT_BEGIN_CHAR: {
+ gconstpointer data0 = *data;
+ int offset = 0, stralign;
+
+ stralign = dbind_find_c_alignment (*type);
+ (*type)++;
+
+ offset = 0 ;
+ while (**type != DBUS_STRUCT_END_CHAR) {
+ char *subt = *type;
+ offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
+ *data = PTR_PLUS (data0, offset);
+ dbind_any_free_r (type, data);
+ offset += dbind_gather_alloc_info (subt);
+ }
+
+ offset = ALIGN_VALUE (offset, stralign);
+ *data = PTR_PLUS (data0, offset);
+
+ g_assert (**type == DBUS_STRUCT_END_CHAR);
+ (*type)++;
+
+ break;
+ }
+ case DBUS_TYPE_STRUCT:
+ case DBUS_TYPE_DICT_ENTRY:
+ warn_braces ();
+ break;
+ }
+}
+
+/* nice deep free ... */
+void
+dbind_any_free (char *type,
+ void *ptr)
+{
+ dbind_any_free_r (&type, &ptr);
+}
+
+/* should this be the default normalization ? */
+void
+dbind_any_free_ptr (char *type, void *ptr)
+{
+ dbind_any_free (type, &ptr);
+}
Added: branches/mail-dbus-remoting/mail/dbind-any.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/dbind-any.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,18 @@
+#ifndef _DBIND_ANY_H_
+#define _DBIND_ANY_H_
+
+#include <dbus/dbus.h>
+
+size_t dbind_gather_alloc_info (char *type);
+void dbind_any_marshal (DBusMessageIter *iter,
+ char **type,
+ void **val);
+void dbind_any_demarshal (DBusMessageIter *iter,
+ char **type,
+ void **val);
+void dbind_any_free (char *type,
+ void *ptr_to_ptr);
+void dbind_any_free_ptr (char *type,
+ void *ptr);
+
+#endif /* _DBIND_ANY_H_ */
Added: branches/mail-dbus-remoting/mail/dbind-config.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/dbind-config.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,8 @@
+#define DBIND_ALIGNOF_CHAR 1
+#define DBIND_ALIGNOF_DBIND_POINTER 4
+#define DBIND_ALIGNOF_DBIND_STRUCT 1
+#define DBIND_ALIGNOF_DBUS_BOOL_T 4
+#define DBIND_ALIGNOF_DBUS_INT16_T 2
+#define DBIND_ALIGNOF_DBUS_INT32_T 4
+#define DBIND_ALIGNOF_DBUS_INT64_T 4
+#define DBIND_ALIGNOF_DOUBLE 4
Added: branches/mail-dbus-remoting/mail/dbind.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/dbind.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,216 @@
+#include "config.h"
+#include <stdio.h>
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include "dbind.h"
+#include "dbind-any.h"
+#include <glib.h>
+#include <stdarg.h>
+
+/*
+ * FIXME: compare types - to ensure they match &
+ * do dynamic padding of structures etc.
+ */
+
+struct _DBindContext {
+ DBusConnection *cnx;
+};
+
+DBindContext *
+dbind_create_context (DBusBusType type, DBusError *opt_error)
+{
+ DBindContext *ctx = NULL;
+ DBusConnection *cnx;
+ DBusError *err, real_err;
+
+ if (opt_error)
+ err = opt_error;
+ else {
+ dbus_error_init (&real_err);
+ err = &real_err;
+ }
+
+ cnx = dbus_bus_get (DBUS_BUS_SESSION, 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);
+
+ return ctx;
+}
+
+void
+dbind_context_free (DBindContext *ctx)
+{
+ if (!ctx)
+ return;
+ dbus_connection_unref (ctx->cnx);
+ g_free (ctx);
+}
+
+dbus_bool_t
+dbind_context_method_call (DBindContext *ctx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ ...)
+{
+ dbus_bool_t success;
+ va_list args;
+
+ va_start (args, arg_types);
+
+ success = dbind_connection_method_call_va
+ (ctx->cnx, bus_name, path, interface, method, opt_error, arg_types, args);
+
+ va_end (args);
+
+ return success;
+}
+
+dbus_bool_t
+dbind_connection_method_call (DBusConnection *cnx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ ...)
+{
+ dbus_bool_t success;
+ va_list args;
+
+ va_start (args, arg_types);
+
+ success = dbind_connection_method_call_va
+ (cnx, bus_name, path, interface, method, opt_error, arg_types, args);
+
+ va_end (args);
+
+ return success;
+}
+
+dbus_bool_t
+dbind_connection_method_call_va (DBusConnection *cnx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ va_list args)
+{
+ dbus_bool_t success = FALSE;
+ DBusMessage *msg = NULL, *reply = NULL;
+ DBusError *err, real_err;
+ char *p;
+
+ if (opt_error)
+ err = opt_error;
+ else {
+ dbus_error_init (&real_err);
+ err = &real_err;
+ }
+
+ msg = dbus_message_new_method_call (bus_name, path, interface, method);
+ if (!msg)
+ goto out;
+ dbus_message_set_auto_start (msg, TRUE);
+
+ /* marshal */
+ p = (char *)arg_types;
+ {
+ DBusMessageIter iter;
+
+ dbus_message_iter_init_append (msg, &iter);
+ /* special case base-types since we need to walk the stack worse-luck */
+ for (;*p != '\0' && *p != '=';) {
+ int intarg;
+ void *ptrarg;
+ double doublearg;
+ dbus_int64_t int64arg;
+ void *arg = NULL;
+
+ switch (*p) {
+ case DBUS_TYPE_BYTE:
+ case DBUS_TYPE_BOOLEAN:
+ case DBUS_TYPE_INT16:
+ case DBUS_TYPE_UINT16:
+ case DBUS_TYPE_INT32:
+ case DBUS_TYPE_UINT32:
+ intarg = va_arg (args, int);
+ arg = &intarg;
+ break;
+ case DBUS_TYPE_INT64:
+ case DBUS_TYPE_UINT64:
+ int64arg = va_arg (args, dbus_int64_t);
+ arg = &int64arg;
+ break;
+ case DBUS_TYPE_DOUBLE:
+ doublearg = va_arg (args, double);
+ arg = &doublearg;
+ break;
+ /* ptr types */
+ case DBUS_TYPE_STRING:
+ 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_TYPE_VARIANT:
+ fprintf (stderr, "No variant support yet - very toolkit specific\n");
+ ptrarg = va_arg (args, void *);
+ arg = &ptrarg;
+ break;
+ default:
+ fprintf (stderr, "Unknown / invalid arg type %c\n", *p);
+ break;
+ }
+ if (arg != NULL)
+ dbind_any_marshal (&iter, &p, &arg);
+ }
+ }
+
+ reply = dbus_connection_send_with_reply_and_block (cnx, msg, -1, err);
+ if (!reply)
+ 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 *);
+ dbind_any_demarshal (&iter, &p, &arg);
+ }
+ }
+
+ success = TRUE;
+out:
+ if (msg)
+ dbus_message_unref (msg);
+
+ if (reply)
+ dbus_message_unref (reply);
+
+ if (err == &real_err)
+ dbus_error_free (err);
+
+ return success;
+}
+
Added: branches/mail-dbus-remoting/mail/dbind.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/dbind.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,39 @@
+#ifndef _DBIND_H_
+#define _DBIND_H_
+
+
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus.h>
+
+typedef struct _DBindContext DBindContext;
+
+DBindContext *dbind_create_context (DBusBusType type, DBusError *opt_error);
+void dbind_context_free (DBindContext *ctx);
+dbus_bool_t dbind_context_method_call (DBindContext *ctx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ ...);
+
+/* dbus connection variants */
+dbus_bool_t dbind_connection_method_call (DBusConnection *cnx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ ...);
+dbus_bool_t dbind_connection_method_call_va (DBusConnection *cnx,
+ const char *bus_name,
+ const char *path,
+ const char *interface,
+ const char *method,
+ DBusError *opt_error,
+ const char *arg_types,
+ va_list args);
+
+#endif /* _DBIND_H_ */
Added: branches/mail-dbus-remoting/mail/evo-dbus.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/evo-dbus.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,46 @@
+/*
+ *
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbind.h>
+#include <dbind-any.h>
+
+
+#define d(x) x
+
+static DBindContext *ctx=NULL;
+
+int
+evolution_dbus_init ()
+{
+ if (ctx)
+ return 0;
+
+ ctx = dbind_create_context (DBUS_BUS_SESSION, NULL);
+ if (!ctx) {
+ g_warning ("DBind context setup failed\n");
+ return -1;
+ }
+
+ d(printf("DBind context setup: done\n"));
+
+ return 0;
+}
+
+DBindContext *
+evolution_dbus_peek_context ()
+{
+ if (!ctx) {
+ evolution_dbus_init ();
+ if (!ctx)
+ return NULL;
+ }
+
+ return ctx;
+}
Added: branches/mail-dbus-remoting/mail/evo-dbus.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/evo-dbus.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,16 @@
+/*
+ *
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbind.h>
+#include <dbine-any.h>
+
+
+int evolution_dbus_init (void);
+DBindContext * evolution_dbus_peek_context (void);
Modified: branches/mail-dbus-remoting/mail/mail-component.c
==============================================================================
--- branches/mail-dbus-remoting/mail/mail-component.c (original)
+++ branches/mail-dbus-remoting/mail/mail-component.c Mon Aug 25 18:17:00 2008
@@ -1272,6 +1272,9 @@
priv->lock = g_mutex_new();
priv->quit_state = -1;
+ /* Init dbus */
+ mail_dbus_init ();
+
/* FIXME This is used as both a filename and URI path throughout
* the mail code. Need to clean this up; maybe provide a
* mail_component_get_base_uri() function. */
@@ -1293,7 +1296,7 @@
e_activity_handler_set_logger (priv->activity_handler, priv->logger);
e_activity_handler_set_error_flush_time (priv->activity_handler, mail_config_get_error_timeout ()*1000);
- mail_session_init (e_get_user_data_dir ());
+ mail_session_remote_init (e_get_user_data_dir ());
priv->async_event = mail_async_event_new();
priv->store_hash = g_hash_table_new_full (
Added: branches/mail-dbus-remoting/mail/mail-dbus.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/mail-dbus.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,220 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <stdio.h>
+#include "mail-dbus.h"
+
+#define d(x) x
+#define DBUS_BUS_NAME "org.gnome.evolution.camel"
+
+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:"
+
+char *
+get_session_address ()
+{
+ const char *address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
+
+ if (!address)
+ address = DBUS_SESSION_BUS_DEFAULT_ADDRESS;
+
+ return address;
+}
+
+static DBusConnection *
+e_dbus_connection_get ()
+{
+ DBusError error;
+
+ if (dbus)
+ return dbus;
+
+ 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);
+ } else {
+ g_warning ("Failed to open connection to bus: %s\n", error.message);
+ dbus_error_free (&error);
+ return NULL;
+ }
+ printf("MAIL DBUS %p\n", dbus);
+ dbus_bus_request_name (dbus,
+ DBUS_BUS_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 NULL;
+ }
+
+ dbus_error_free (&error);
+
+ return dbus;
+}
+
+void
+e_dbus_connection_close ()
+{
+ if (dbus)
+ dbus_connection_unref (dbus);
+ dbus = NULL;
+}
+
+int
+e_dbus_setup_handlers ()
+{
+ if (dbus)
+ return 0;
+
+ if (!(dbus = e_dbus_connection_get ())) {
+ g_warning("Error setting up dbus handlers\n");
+ return -1;
+ }
+
+ d(printf("DBUS Handlers setup successfully\n"));
+
+ return 0;
+}
+
+int
+e_dbus_register_handler (const char *object_path, DBusObjectPathMessageFunction reg, DBusObjectPathUnregisterFunction unreg)
+{
+ DBusObjectPathVTable *dbus_listener_vtable;
+
+ if (!dbus)
+ e_dbus_setup_handlers ();
+
+ if (!dbus)
+ return -1;
+
+ 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 (dbus,
+ object_path,
+ dbus_listener_vtable,
+ NULL)) {
+ g_warning (("Out of memory registering object path '%s'"), object_path);
+ return -1;
+ }
+
+ d(printf("successfully inited handler for %s\n", object_path));
+ return 0;
+}
+
+char *
+e_dbus_get_store_hash (const char *store_url)
+{
+ GChecksum *checksum;
+ guint8 *digest;
+ gsize length;
+ int state = 0, save = 0;
+ char *tmp;
+ char *buffer = g_malloc0(sizeof(char)*9);
+ int i;
+
+ length = g_checksum_type_get_length (G_CHECKSUM_MD5);
+ digest = g_alloca (length);
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, (guchar *) store_url, -1);
+ g_checksum_get_digest (checksum, digest, &length);
+ g_checksum_free (checksum);
+
+ g_base64_encode_step (digest, 6, FALSE, buffer, &state, &save);
+ g_base64_encode_close (FALSE, buffer, &state, &save);
+
+ for (i=0;i<8;i++) {
+ if (buffer[i] == '+')
+ buffer[i] = '.';
+ if (buffer[i] == '/')
+ buffer[i] = '_';
+ }
+
+ return buffer;
+}
+
+char *
+e_dbus_get_folder_hash (const char *store_url, const char *folder_name)
+{
+ GChecksum *checksum;
+ guint8 *digest;
+ gsize length;
+ int state = 0, save = 0;
+ char *tmp;
+ char *buffer = g_malloc0(sizeof(char)*9);
+ int i;
+
+ length = g_checksum_type_get_length (G_CHECKSUM_MD5);
+ digest = g_alloca (length);
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, (guchar *) store_url, -1);
+ g_checksum_update (checksum, (guchar *) folder_name, -1);
+ g_checksum_get_digest (checksum, digest, &length);
+ g_checksum_free (checksum);
+
+ g_base64_encode_step (digest, 6, FALSE, buffer, &state, &save);
+ g_base64_encode_close (FALSE, buffer, &state, &save);
+
+ for (i=0;i<8;i++) {
+ if (buffer[i] == '+')
+ buffer[i] = '.';
+ if (buffer[i] == '/')
+ buffer[i] = '_';
+ }
+
+ /* End by NULL */
+ buffer[8] = 0;
+
+ return buffer;
+}
+
+static gboolean
+idle_cb(gpointer data)
+{
+ e_dbus_setup_handlers ();
+
+ /* Initialize Mail Session */
+ mail_session_remote_impl_init ();
+ return FALSE;
+}
+
+gpointer
+mail_dbus_run ()
+{
+
+ main_loop = g_main_loop_new (gm_ctx, FALSE);
+ inited = TRUE;
+ g_main_loop_run (main_loop);
+}
+
+int
+mail_dbus_init ()
+{
+ if (gm_ctx)
+ return 0;
+
+ gm_ctx = g_main_context_new ();
+ idle_cb(NULL);
+ g_thread_create (mail_dbus_run, NULL, FALSE, NULL);
+ /* FIXME: This is a hack and should be fixed well. It maynot work always */
+ while (!inited)
+ g_main_context_iteration (NULL, TRUE);
+}
Added: branches/mail-dbus-remoting/mail/mail-dbus.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/mail-dbus.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,16 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+
+
+#include <dbus/dbus.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);
+
+int e_dbus_setup_handlers (void);
Added: branches/mail-dbus-remoting/mail/mail-session-remote-impl.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/mail-session-remote-impl.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,71 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include "mail-dbus.h"
+#include "mail-session.h"
+
+#define MAIL_SESSION_OBJECT_PATH "/org/gnome/evolution/camel/session/mail"
+
+#define d(x) x
+
+static gboolean ms_setup = FALSE;
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+
+
+
+static DBusHandlerResult
+dbus_listener_message_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ const char *method = dbus_message_get_member (message);
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return (message);
+
+ d(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)));
+ if (strcmp(method, "mail_session_init") == 0) {
+ char *path;
+ gboolean ret;
+
+ ret = dbus_message_get_args(message, NULL,
+ DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+ if (!ret) {
+ g_warning ("Unable to get args\n");
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ d(printf("calling mail_session_init with: %s\n", path));
+ mail_session_init (path);
+ }
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ dbus_connection_flush (connection);
+ printf("reply send\n");
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+}
+
+void
+mail_session_remote_impl_init ()
+{
+ ms_setup = TRUE;
+ e_dbus_register_handler (MAIL_SESSION_OBJECT_PATH, dbus_listener_message_handler, NULL);
+}
+
+
Added: branches/mail-dbus-remoting/mail/mail-session-remote.c
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/mail-session-remote.c Mon Aug 25 18:17:00 2008
@@ -0,0 +1,36 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+#include <mail-dbus.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
+mail_session_remote_init (const char *base_dir)
+{
+ gboolean ret;
+ DBusError error;
+
+ dbus_error_init (&error);
+ /* Invoke the appropriate dbind call to MailSessionRemoteImpl */
+ ret = dbind_context_method_call (evolution_dbus_peek_context(),
+ CAMEL_DBUS_NAME,
+ MAIL_SESSION_OBJECT_PATH,
+ MAIL_SESSION_INTERFACE,
+ "mail_session_init",
+ &error,
+ "s", base_dir); /* Just string of base dir */
+
+ if (!ret) {
+ g_warning ("Error: Initializing mail session: %s\n", error.message);
+ return;
+ }
+
+ d(printf("Mail session initated remotely\n"));
+}
Added: branches/mail-dbus-remoting/mail/mail-session-remote.h
==============================================================================
--- (empty file)
+++ branches/mail-dbus-remoting/mail/mail-session-remote.h Mon Aug 25 18:17:00 2008
@@ -0,0 +1,10 @@
+/*
+ * Authors: Srinivasa Ragavan <sragavan novell com>
+ *
+ * */
+
+typedef struct MailSessionRemote {
+ char *object_id;
+};
+
+#define mail_session_init mail_session_remote_init
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]