[evolution-data-server/treitter-client-gdbus] Port the BookView D-Bus methods to gdbus.



commit 17560b94bd3541f6d1b3092cd7358b714aacff89
Author: Travis Reitter <treitter gmail com>
Date:   Tue Dec 15 17:41:40 2009 -0800

    Port the BookView D-Bus methods to gdbus.

 addressbook/libebook/Makefile.am                   |    8 +--
 addressbook/libebook/e-book-view-private.h         |    4 +-
 addressbook/libebook/e-book-view.c                 |   87 ++++++++++++++------
 addressbook/libebook/e-book.c                      |   33 +++++---
 .../libebook/e-data-book-view-gdbus-bindings.h     |   74 +++++++++++++++++
 addressbook/tests/ebook/test-ebook-get-book-view.c |    2 +
 6 files changed, 165 insertions(+), 43 deletions(-)
---
diff --git a/addressbook/libebook/Makefile.am b/addressbook/libebook/Makefile.am
index 37bad80..2694d06 100644
--- a/addressbook/libebook/Makefile.am
+++ b/addressbook/libebook/Makefile.am
@@ -18,7 +18,6 @@ libebook_1_2_la_CPPFLAGS = \
 
 libebook_1_2_la_SOURCES =				\
 	$(MARSHAL_GENERATED)				\
-	$(DBUS_GENERATED_H)				\
 	e-address-western.c				\
 	e-book-query.c					\
 	e-book-view-private.h				\
@@ -27,6 +26,7 @@ libebook_1_2_la_SOURCES =				\
 	e-contact.c					\
 	e-data-book-factory-gdbus-bindings.h            \
 	e-data-book-gdbus-bindings.h                    \
+	e-data-book-view-gdbus-bindings.h               \
 	e-destination.c					\
 	e-name-western.c				\
 	e-name-western-tables.h                         \
@@ -63,11 +63,7 @@ e-name-western-tables.h: e-name-western-tables.h.in
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libebook-$(API_VERSION).pc
 
-DBUS_GENERATED_H = e-data-book-view-bindings.h
-%-bindings.h: $(top_srcdir)/addressbook/libedata-book/%.xml
-	dbus-binding-tool --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^
-
-BUILT_SOURCES = $(DBUS_GENERATED_H) $(MARSHAL_GENERATED)
+BUILT_SOURCES = $(MARSHAL_GENERATED)
 CLEANFILES    = $(BUILT_SOURCES)
 DISTCLEANFILES = $(pkgconfig_DATA)
 
diff --git a/addressbook/libebook/e-book-view-private.h b/addressbook/libebook/e-book-view-private.h
index b6dcb57..7ce3a1a 100644
--- a/addressbook/libebook/e-book-view-private.h
+++ b/addressbook/libebook/e-book-view-private.h
@@ -22,10 +22,12 @@
 #ifndef __E_BOOK_VIEW_PRIVATE_H__
 #define __E_BOOK_VIEW_PRIVATE_H__
 
+#include <gdbus/gdbus.h>
+
 #include "e-book.h"
 #include "e-book-view.h"
 
-EBookView *_e_book_view_new (EBook *book, DBusGProxy *view_proxy, GStaticRecMutex *connection_lock);
+EBookView *_e_book_view_new (EBook *book, GDBusProxy *view_proxy, GStaticRecMutex *connection_lock);
 
 G_END_DECLS
 
diff --git a/addressbook/libebook/e-book-view.c b/addressbook/libebook/e-book-view.c
index 6b03068..347996a 100644
--- a/addressbook/libebook/e-book-view.c
+++ b/addressbook/libebook/e-book-view.c
@@ -21,11 +21,10 @@
  */
 
 #include <glib-object.h>
-#include <dbus/dbus-glib.h>
 #include "e-book.h"
 #include "e-book-view.h"
 #include "e-book-view-private.h"
-#include "e-data-book-view-bindings.h"
+#include "e-data-book-view-gdbus-bindings.h"
 #include "e-book-marshal.h"
 
 G_DEFINE_TYPE(EBookView, e_book_view, G_TYPE_OBJECT);
@@ -35,7 +34,7 @@ G_DEFINE_TYPE(EBookView, e_book_view, G_TYPE_OBJECT);
 
 struct _EBookViewPrivate {
 	EBook *book;
-	DBusGProxy *view_proxy;
+	GDBusProxy *view_proxy;
 	GStaticRecMutex *view_proxy_lock;
 	gboolean running;
 };
@@ -51,8 +50,12 @@ enum {
 
 static guint signals [LAST_SIGNAL];
 
+#define LOCK_CONN()   g_static_rec_mutex_lock (book_view->priv->view_proxy_lock)
+#define UNLOCK_CONN() g_static_rec_mutex_unlock (book_view->priv->view_proxy_lock)
+
 static void
-status_message_cb (DBusGProxy *proxy, const gchar *message, EBookView *book_view)
+book_view_handle_signal_status_message (EBookView   *book_view,
+					const gchar *message)
 {
 	if (!book_view->priv->running)
 		return;
@@ -61,7 +64,8 @@ status_message_cb (DBusGProxy *proxy, const gchar *message, EBookView *book_view
 }
 
 static void
-contacts_added_cb (DBusGProxy *proxy, const gchar **vcards, EBookView *book_view)
+book_view_handle_signal_contacts_added (EBookView   *book_view,
+					const char **vcards)
 {
 	const gchar **p;
 	GList *contacts = NULL;
@@ -81,7 +85,8 @@ contacts_added_cb (DBusGProxy *proxy, const gchar **vcards, EBookView *book_view
 }
 
 static void
-contacts_changed_cb (DBusGProxy *proxy, const gchar **vcards, EBookView *book_view)
+book_view_handle_signal_contacts_changed (EBookView   *book_view,
+					  const char **vcards)
 {
 	const gchar **p;
 	GList *contacts = NULL;
@@ -101,7 +106,8 @@ contacts_changed_cb (DBusGProxy *proxy, const gchar **vcards, EBookView *book_vi
 }
 
 static void
-contacts_removed_cb (DBusGProxy *proxy, const gchar **ids, EBookView *book_view)
+book_view_handle_signal_contacts_removed (EBookView   *book_view,
+					  const char **ids)
 {
 	const gchar **p;
 	GList *list = NULL;
@@ -121,7 +127,8 @@ contacts_removed_cb (DBusGProxy *proxy, const gchar **ids, EBookView *book_view)
 }
 
 static void
-complete_cb (DBusGProxy *proxy, guint status, EBookView *book_view)
+book_view_handle_signal_complete (EBookView *book_view,
+				  guint      status)
 {
 	if (!book_view->priv->running)
 		return;
@@ -129,13 +136,50 @@ complete_cb (DBusGProxy *proxy, guint status, EBookView *book_view)
 	g_signal_emit (book_view, signals[SEQUENCE_COMPLETE], 0, status);
 }
 
-#define LOCK_CONN()   g_static_rec_mutex_lock (book_view->priv->view_proxy_lock)
-#define UNLOCK_CONN() g_static_rec_mutex_unlock (book_view->priv->view_proxy_lock)
+static void
+book_view_proxy_signal_cb (GDBusProxy *proxy,
+			   gchar      *sender_name,
+			   gchar      *signal_name,
+			   GVariant   *parameters,
+			   EBookView  *book_view)
+{
+        if (FALSE) {
+        } else if (!g_strcmp0 (signal_name, "StatusMessage")) {
+		const char *value;
+		g_variant_get (parameters, "(&s)", &value);
+
+                book_view_handle_signal_status_message (book_view, value);
+        } else if (!g_strcmp0 (signal_name, "ContactsAdded")) {
+		const char **value;
+
+		g_variant_get (parameters, "(^a&s)", &value, NULL);
+
+                book_view_handle_signal_contacts_added (book_view, value);
+		g_free (value);
+        } else if (!g_strcmp0 (signal_name, "ContactsChanged")) {
+		const char **value;
+		g_variant_get (parameters, "(^a&s)", &value, NULL);
+
+                book_view_handle_signal_contacts_changed (book_view, value);
+		g_free (value);
+        } else if (!g_strcmp0 (signal_name, "ContactsRemoved")) {
+		const char **value;
+		g_variant_get (parameters, "(^a&s)", &value, NULL);
+
+                book_view_handle_signal_contacts_removed (book_view, value);
+		g_free (value);
+        } else if (!g_strcmp0 (signal_name, "Complete")) {
+		const guint value;
+		g_variant_get (parameters, "(u)", &value);
+
+                book_view_handle_signal_complete (book_view, value);
+        }
+}
 
 /*
  * e_book_view_new:
  * @book: an #EBook
- * @view_proxy: The #DBusGProxy to get signals from
+ * @view_proxy: The #GDBusProxy to get signals from
  *
  * Creates a new #EBookView based on #EBook and listening to @view_proxy.  This
  * is a private function, applications should call #e_book_get_book_view or
@@ -144,7 +188,9 @@ complete_cb (DBusGProxy *proxy, guint status, EBookView *book_view)
  * Return value: A new #EBookView.
  **/
 EBookView *
-_e_book_view_new (EBook *book, DBusGProxy *view_proxy, GStaticRecMutex *view_proxy_lock)
+_e_book_view_new (EBook           *book,
+		  GDBusProxy      *view_proxy,
+		  GStaticRecMutex *view_proxy_lock)
 {
 	EBookView *view;
 	EBookViewPrivate *priv;
@@ -159,16 +205,7 @@ _e_book_view_new (EBook *book, DBusGProxy *view_proxy, GStaticRecMutex *view_pro
 	priv->view_proxy_lock = view_proxy_lock;
 	g_object_add_weak_pointer (G_OBJECT (view_proxy), (gpointer)&priv->view_proxy);
 
-	dbus_g_proxy_add_signal (view_proxy, "StatusMessage", G_TYPE_STRING, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (view_proxy, "StatusMessage", G_CALLBACK (status_message_cb), view, NULL);
-	dbus_g_proxy_add_signal (view_proxy, "ContactsAdded", G_TYPE_STRV, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (view_proxy, "ContactsAdded", G_CALLBACK (contacts_added_cb), view, NULL);
-	dbus_g_proxy_add_signal (view_proxy, "ContactsChanged", G_TYPE_STRV, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (view_proxy, "ContactsChanged", G_CALLBACK (contacts_changed_cb), view, NULL);
-	dbus_g_proxy_add_signal (view_proxy, "ContactsRemoved", G_TYPE_STRV, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (view_proxy, "ContactsRemoved", G_CALLBACK (contacts_removed_cb), view, NULL);
-	dbus_g_proxy_add_signal (view_proxy, "Complete", G_TYPE_UINT, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (view_proxy, "Complete", G_CALLBACK (complete_cb), view, NULL);
+	g_signal_connect (view_proxy, "g-signal", G_CALLBACK (book_view_proxy_signal_cb), view);
 
 	return view;
 }
@@ -206,7 +243,7 @@ e_book_view_start (EBookView *book_view)
 
 	if (book_view->priv->view_proxy) {
 		LOCK_CONN ();
-		org_gnome_evolution_dataserver_addressbook_BookView_start (book_view->priv->view_proxy, &error);
+		e_data_book_view_gdbus_start_sync (book_view->priv->view_proxy, &error);
 		UNLOCK_CONN ();
 		if (error) {
 			g_warning ("Cannot start book view: %s\n", error->message);
@@ -238,7 +275,7 @@ e_book_view_stop (EBookView *book_view)
 
 	if (book_view->priv->view_proxy) {
 		LOCK_CONN ();
-		org_gnome_evolution_dataserver_addressbook_BookView_stop (book_view->priv->view_proxy, &error);
+		e_data_book_view_gdbus_stop_sync (book_view->priv->view_proxy, &error);
 		UNLOCK_CONN ();
 		if (error) {
 			g_warning ("Cannot stop book view: %s\n", error->message);
@@ -267,7 +304,7 @@ e_book_view_dispose (GObject *object)
 
 	if (book_view->priv->view_proxy) {
 		LOCK_CONN ();
-		org_gnome_evolution_dataserver_addressbook_BookView_dispose (book_view->priv->view_proxy, NULL);
+		e_data_book_view_gdbus_dispose_sync (book_view->priv->view_proxy, NULL);
 		g_object_unref (book_view->priv->view_proxy);
 		book_view->priv->view_proxy = NULL;
 		UNLOCK_CONN ();
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index b82e663..0a1fa34 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -1279,7 +1279,7 @@ e_book_get_book_view (EBook       *book,
 		      GError     **error)
 {
 	GError *err = NULL;
-	DBusGProxy *view_proxy;
+	GDBusProxy *view_proxy_gdbus;
 	gchar *sexp, *view_path;
 	gboolean ret = TRUE;
 
@@ -1295,13 +1295,18 @@ e_book_get_book_view (EBook       *book,
 		g_free (sexp);
 		return unwrap_gerror (err, error);
 	}
-	view_proxy = dbus_g_proxy_new_for_name_owner (connection,
-						      E_DATA_BOOK_FACTORY_SERVICE_NAME, view_path,
-						      "org.gnome.evolution.dataserver.addressbook.BookView", error);
+	view_proxy_gdbus = g_dbus_proxy_new_sync (connection_gdbus,
+						  G_TYPE_DBUS_PROXY,
+						  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+						  g_dbus_proxy_get_unique_bus_name (factory_proxy_gdbus),
+						  view_path,
+						  "org.gnome.evolution.dataserver.addressbook.BookView",
+						  NULL,
+						  error);
 	UNLOCK_CONN ();
 
-	if (view_proxy) {
-		*book_view = _e_book_view_new (book, view_proxy, &connection_lock);
+	if (view_proxy_gdbus) {
+		*book_view = _e_book_view_new (book, view_proxy_gdbus, &connection_lock);
 	} else {
 		*book_view = NULL;
 		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION,
@@ -1325,16 +1330,22 @@ get_book_view_reply (GDBusProxy *proxy,
 	GError *err = NULL;
 	EBookView *view = NULL;
 	EBookBookViewCallback cb = data->callback;
-	DBusGProxy *view_proxy;
+	GDBusProxy *view_proxy_gdbus;
 	EBookStatus status;
 
 	if (view_path) {
 		LOCK_CONN ();
-		view_proxy = dbus_g_proxy_new_for_name_owner (connection, E_DATA_BOOK_FACTORY_SERVICE_NAME, view_path,
-							      "org.gnome.evolution.dataserver.addressbook.BookView", &err);
+		view_proxy_gdbus = g_dbus_proxy_new_sync (connection_gdbus,
+							  G_TYPE_DBUS_PROXY,
+							  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+							  g_dbus_proxy_get_unique_bus_name (factory_proxy_gdbus),
+							  view_path,
+							  "org.gnome.evolution.dataserver.addressbook.BookView",
+							  NULL,
+							  &err);
 		UNLOCK_CONN ();
-		if (view_proxy) {
-			view = _e_book_view_new (data->book, view_proxy, &connection_lock);
+		if (view_proxy_gdbus) {
+			view = _e_book_view_new (data->book, view_proxy_gdbus, &connection_lock);
 			status = E_BOOK_ERROR_OK;
 		} else {
 			g_warning (G_STRLOC ": cannot get connection to view: %s", err->message);
diff --git a/addressbook/libebook/e-data-book-view-gdbus-bindings.h b/addressbook/libebook/e-data-book-view-gdbus-bindings.h
new file mode 100644
index 0000000..f7348b8
--- /dev/null
+++ b/addressbook/libebook/e-data-book-view-gdbus-bindings.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Travis Reitter (travis reitter collabora co uk)
+ */
+
+#include <glib.h>
+#include <gdbus/gdbus.h>
+
+#include "e-data-book-gdbus-bindings-common.h"
+
+G_BEGIN_DECLS
+
+/* FIXME: These bindings were created manually; replace with generated bindings
+ * when possible */
+
+static gboolean
+e_data_book_view_gdbus_start_sync (GDBusProxy  *proxy,
+				   GError     **error)
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("()");
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "start", parameters,
+							-1, NULL, error);
+
+	return demarshal_retvals__VOID (retvals);
+}
+
+static gboolean
+e_data_book_view_gdbus_stop_sync (GDBusProxy  *proxy,
+				  GError     **error)
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("()");
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "stop", parameters,
+							-1, NULL, error);
+
+	return demarshal_retvals__VOID (retvals);
+}
+
+static gboolean
+e_data_book_view_gdbus_dispose_sync (GDBusProxy  *proxy,
+				     GError     **error)
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("()");
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "dispose", parameters,
+							-1, NULL, error);
+
+	return demarshal_retvals__VOID (retvals);
+}
+
+G_END_DECLS
diff --git a/addressbook/tests/ebook/test-ebook-get-book-view.c b/addressbook/tests/ebook/test-ebook-get-book-view.c
index 8fa1ba7..1caffad 100644
--- a/addressbook/tests/ebook/test-ebook-get-book-view.c
+++ b/addressbook/tests/ebook/test-ebook-get-book-view.c
@@ -49,6 +49,8 @@ contacts_removed (EBookView *book_view, const GList *ids)
 static void
 sequence_complete (EBookView *book_view, EBookViewStatus status)
 {
+	e_book_view_stop (book_view);
+	g_object_unref (book_view);
 	g_main_loop_quit (loop);
 }
 



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