[evolution-data-server/treitter-client-gdbus] Switch libebook over to gdbus (so far, only for the factory methods)



commit f8cbb449c5ebad7f8928fb97e00340b864548c9d
Author: Travis Reitter <treitter gmail com>
Date:   Mon Nov 23 14:08:23 2009 -0800

    Switch libebook over to gdbus (so far, only for the factory methods)

 addressbook/libebook/Makefile.am                   |    1 +
 addressbook/libebook/e-book.c                      |   69 ++++++++++++++++++--
 .../libebook/e-data-book-factory-gdbus-bindings.h  |   38 +++++++++++
 configure.ac                                       |   12 +++-
 4 files changed, 112 insertions(+), 8 deletions(-)
---
diff --git a/addressbook/libebook/Makefile.am b/addressbook/libebook/Makefile.am
index 2210723..33e4822 100644
--- a/addressbook/libebook/Makefile.am
+++ b/addressbook/libebook/Makefile.am
@@ -61,6 +61,7 @@ e-name-western-tables.h: e-name-western-tables.h.in
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libebook-$(API_VERSION).pc
 
+# FIXME: cut out e-data-book-factory-bindings.h
 DBUS_GENERATED_H = e-data-book-factory-bindings.h e-data-book-bindings.h e-data-book-view-bindings.h
 %-bindings.h: $(top_srcdir)/addressbook/libedata-book/%.xml
 	dbus-binding-tool --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index 8982d81..8fe617b 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -32,6 +32,7 @@
 #include "e-contact.h"
 #include "e-book-view-private.h"
 #include "e-data-book-factory-bindings.h"
+#include "e-data-book-factory-gdbus-bindings.h"
 #include "e-data-book-bindings.h"
 #include "libedata-book/e-data-book-types.h"
 #include "e-book-marshal.h"
@@ -69,6 +70,8 @@ struct _EBookPrivate {
 
 static DBusGConnection *connection = NULL;
 static DBusGProxy *factory_proxy = NULL;
+static GDBusConnection *connection_gdbus = NULL;
+static GDBusProxy *factory_proxy_gdbus = NULL;
 
 /* guards both connection and factory_proxy */
 static GStaticRecMutex connection_lock = G_STATIC_REC_MUTEX_INIT;
@@ -223,7 +226,7 @@ e_book_activate(GError **error)
 
 	LOCK_CONN ();
 
-	if (G_LIKELY (factory_proxy)) {
+	if (G_LIKELY (factory_proxy && factory_proxy_gdbus)) {
 		UNLOCK_CONN ();
 		return TRUE;
 	}
@@ -243,15 +246,19 @@ e_book_activate(GError **error)
 		dbus_set_g_error (error, &derror);
 		dbus_error_free (&derror);
 		UNLOCK_CONN ();
+
+		/* FIXME: cut this */
+		g_debug (G_STRLOC ": FAILED to start " E_DATA_BOOK_FACTORY_SERVICE_NAME);
+
 		return FALSE;
 	}
 
 	if (!factory_proxy) {
 		factory_proxy = dbus_g_proxy_new_for_name_owner (connection,
-								 E_DATA_BOOK_FACTORY_SERVICE_NAME,
-								 "/org/gnome/evolution/dataserver/addressbook/BookFactory",
-								 "org.gnome.evolution.dataserver.addressbook.BookFactory",
-								 error);
+									E_DATA_BOOK_FACTORY_SERVICE_NAME,
+									"/org/gnome/evolution/dataserver/addressbook/BookFactory",
+									"org.gnome.evolution.dataserver.addressbook.BookFactory",
+									error);
 		if (!factory_proxy) {
 			UNLOCK_CONN ();
 			return FALSE;
@@ -259,6 +266,55 @@ e_book_activate(GError **error)
 		g_object_add_weak_pointer (G_OBJECT (factory_proxy), (gpointer)&factory_proxy);
 	}
 
+	/* FIXME: better to just watch for the proxy instead of using the
+	 * connection directly? */
+	if (!connection_gdbus) {
+		connection_gdbus = g_dbus_connection_bus_get_private_sync (G_BUS_TYPE_SESSION, NULL, error);
+		if (!connection_gdbus) {
+			UNLOCK_CONN ();
+
+			/* FIXME: cut this */
+			g_debug (G_STRLOC ": *** FAILED to create the factory connection gdbus");
+
+			return FALSE;
+		}
+	} else {
+		/* FIXME: cut this */
+		g_debug (G_STRLOC ": *** already have a factory connection gdbus");
+	}
+
+	/* FIXME: it may be insufficient to create this; we probably have to
+	 * watch it to see if it dies. There's gdbusproxywatch for that */
+
+	/* FIXME: we don't need properties from this object, but what if we do
+	 * from others? -- maybe it's handled automatically if any properties
+	 * actually are defined? */
+	/* FIXME: same for signals - this doesn't have any, but what about the
+	 * other objects (which do have signals)? */
+	if (!factory_proxy_gdbus) {
+		factory_proxy_gdbus = g_dbus_proxy_new_sync (connection_gdbus,
+								G_TYPE_DBUS_PROXY,
+								G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+								E_DATA_BOOK_FACTORY_SERVICE_NAME,
+								"/org/gnome/evolution/dataserver/addressbook/BookFactory",
+								"org.gnome.evolution.dataserver.addressbook.BookFactory",
+								NULL,
+								error);
+		if (!factory_proxy_gdbus) {
+			UNLOCK_CONN ();
+
+			/* FIXME: cut this */
+			g_debug (G_STRLOC ": *** FAILED TO create the factory proxy gdbus, %s", (*error)->message);
+
+			return FALSE;
+		}
+
+		g_object_add_weak_pointer (G_OBJECT (factory_proxy_gdbus), (gpointer)&factory_proxy_gdbus);
+	} else {
+		/* FIXME: cut this */
+		g_debug (G_STRLOC ": *** already have a factory proxy gdbus");
+	}
+
 	UNLOCK_CONN ();
 	return TRUE;
 }
@@ -2161,7 +2217,7 @@ e_book_new (ESource *source, GError **error)
 	xml = e_source_to_standalone_xml (source);
 
 	LOCK_CONN ();
-	if (!org_gnome_evolution_dataserver_addressbook_BookFactory_get_book (factory_proxy, xml, &path, &err)) {
+	if (!e_data_book_factory_gdbus_get_book (factory_proxy_gdbus, xml, &path, &err)) {
 		UNLOCK_CONN ();
 		g_free (xml);
 		g_warning (G_STRLOC ": cannot get book from factory: %s", err ? err->message : "[no error]");
@@ -2171,6 +2227,7 @@ e_book_new (ESource *source, GError **error)
 	}
 	g_free (xml);
 
+	/* FIXME: switch this over to g_dbus */
 	book->priv->proxy = dbus_g_proxy_new_for_name_owner (connection,
 							     E_DATA_BOOK_FACTORY_SERVICE_NAME, path,
 							     "org.gnome.evolution.dataserver.addressbook.Book",
diff --git a/addressbook/libebook/e-data-book-factory-gdbus-bindings.h b/addressbook/libebook/e-data-book-factory-gdbus-bindings.h
new file mode 100644
index 0000000..ef70a77
--- /dev/null
+++ b/addressbook/libebook/e-data-book-factory-gdbus-bindings.h
@@ -0,0 +1,38 @@
+#include <glib.h>
+#include <gdbus/gdbus.h>
+
+G_BEGIN_DECLS
+
+/* FIXME: These bindings were created manually; replace with generated bindings
+ * when possible */
+
+static gboolean
+e_data_book_factory_gdbus_get_book (GDBusProxy *proxy, const char * IN_source, char** OUT_path, GError **error)
+
+{
+	GVariant *parameters;
+	GVariant *retvals;
+	gboolean success = TRUE;
+
+	parameters = g_variant_new ("(s)", IN_source);
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "getBook", parameters,
+							-1, NULL, error);
+	if (retvals) {
+		char *const_path = NULL;
+
+		g_variant_get (retvals, "(o)", &const_path);
+		if (const_path) {
+			*OUT_path = g_strdup (const_path);
+		} else {
+			success = FALSE;
+		}
+
+		g_variant_unref (retvals);
+	} else {
+		success = FALSE;
+	}
+
+	return success;
+}
+
+G_END_DECLS
diff --git a/configure.ac b/configure.ac
index b22351a..f01fa36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,7 @@ m4_define([sqlite_minimum_version], [3.5])
 m4_define([gweather_minimum_version], [2.25.4])
 m4_define([libical_minimum_version], [0.43])
 m4_define([dbus_glib_minimum_version], [0.6])
+m4_define([gdbus_standalone_minimum_version], [0.1])
 
 AC_SUBST([BASE_VERSION],[base_version])
 AC_SUBST([API_VERSION],[api_version])
@@ -1142,6 +1143,9 @@ fi
 DBUS_GLIB_REQUIRED=dbus_glib_minimum_version
 AC_SUBST(DBUS_GLIB_REQUIRED)
 
+GDBUS_STANDALONE_REQUIRED=gdbus_standalone_minimum_version
+AC_SUBST(GDBUS_STANDALONE_REQUIRED)
+
 dnl ******************************
 dnl GObject marshalling
 dnl ******************************
@@ -1181,6 +1185,10 @@ PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= dbus_glib_minimum_version)
 AC_SUBST(DBUS_GLIB_CFLAGS)
 AC_SUBST(DBUS_GLIB_LIBS)
 
+PKG_CHECK_MODULES(GDBUS_STANDALONE, gdbus-standalone >= gdbus_standalone_minimum_version)
+AC_SUBST(GDBUS_STANDALONE_CFLAGS)
+AC_SUBST(GDBUS_STANDALONE_LIBS)
+
 dnl ***********************
 dnl Gnome keyring support
 dnl ***********************
@@ -1239,7 +1247,7 @@ AC_SUBST(E_BACKEND_LIBS)
 dnl ******************************
 dnl evolution-addressbook flags
 dnl ******************************
-EVOLUTION_ADDRESSBOOK_DEPS="libxml-2.0 dbus-glib-1 gobject-2.0 gthread-2.0 gconf-2.0"
+EVOLUTION_ADDRESSBOOK_DEPS="libxml-2.0 dbus-glib-1 gdbus-standalone gobject-2.0 gthread-2.0 gconf-2.0"
 
 EVO_SET_COMPILE_FLAGS(EVOLUTION_ADDRESSBOOK, $EVOLUTION_ADDRESSBOOK_DEPS)
 AC_SUBST(EVOLUTION_ADDRESSBOOK_CFLAGS)
@@ -1249,7 +1257,7 @@ dnl ******************************
 dnl evolution-calendar flags
 dnl ******************************
 if test "x${enable_calendar}" = "xyes"; then
-	EVOLUTION_CALENDAR_DEPS="libical >= libical_minimum_version libxml-2.0 dbus-glib-1 gio-2.0 gobject-2.0 gthread-2.0 gconf-2.0"
+	EVOLUTION_CALENDAR_DEPS="libical >= libical_minimum_version libxml-2.0 dbus-glib-1 gdbus-standalone gio-2.0 gobject-2.0 gthread-2.0 gconf-2.0"
 
 dnl *****
 dnl libical.pc from libical-0.43 has a bug in it's CFlags.



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