[evolution-data-server/treitter-client-gdbus] Port the e-book 'remove' method to gdbus.



commit 9e024d929096c5f7069f791a03ca475442ef7671
Author: Travis Reitter <treitter gmail com>
Date:   Wed Dec 2 15:25:49 2009 -0800

    Port the e-book 'remove' method to gdbus.

 addressbook/libebook/e-book.c                     |    8 +-
 addressbook/libebook/e-data-book-gdbus-bindings.h |  100 ++++++++++++++------
 addressbook/tests/ebook/Makefile.am               |    4 +-
 addressbook/tests/ebook/test-book-remove.c        |   97 ++++++++++++++++++++
 4 files changed, 175 insertions(+), 34 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index f21b544..72857b2 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -1763,14 +1763,16 @@ e_book_remove (EBook   *book,
 	e_return_error_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove (book->priv->proxy, &err);
+	e_data_book_gdbus_remove_sync (book->priv->gdbus_proxy, &err);
 	UNLOCK_CONN ();
 
 	return unwrap_gerror (err, error);
 }
 
 static void
-remove_reply(DBusGProxy *proxy, GError *error, gpointer user_data)
+remove_reply (GDBusProxy *proxy,
+	      GError *error,
+	      gpointer user_data)
 {
 	AsyncData *data = user_data;
 	EBookCallback cb = data->callback;
@@ -1808,7 +1810,7 @@ e_book_async_remove (EBook   *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_async (book->priv->proxy, remove_reply, data);
+	e_data_book_gdbus_remove (book->priv->gdbus_proxy, remove_reply, data);
 	UNLOCK_CONN ();
 
 	return 0;
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index bc91e51..00e84c7 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -17,36 +17,6 @@ closure_free (Closure *closure)
 	g_slice_free (Closure, closure);
 }
 
-/* FIXME: use this for demarshalling that has return values */
-#if 0
-static gboolean
-FUCNTION_NAME_demarshal_retvals (GVariant *retvals, char **OUT_path)
-{
-	gboolean success = TRUE;
-
-	if (retvals) {
-		/* FIXME: cut this */
-#if 0
-		/* FIXME: shouldn't we add const? */
-		char *const_path = NULL;
-
-		g_variant_get (retvals, "(o)", &const_path);
-		if (const_path) {
-			*OUT_path = g_strdup (const_path);
-		} else {
-			success = FALSE;
-		}
-#endif
-
-		g_variant_unref (retvals);
-	} else {
-		success = FALSE;
-	}
-
-	return success;
-}
-#endif
-
 static gboolean
 open_demarshal_retvals (GVariant *retvals)
 {
@@ -119,4 +89,74 @@ e_data_book_gdbus_open (GDBusProxy                   *proxy,
 	g_dbus_proxy_invoke_method (proxy, "open", parameters, -1, NULL, (GAsyncReadyCallback) open_cb, closure);
 }
 
+static gboolean
+remove_demarshal_retvals (GVariant *retvals)
+{
+	gboolean success = TRUE;
+
+	if (retvals)
+		g_variant_unref (retvals);
+	else
+		success = FALSE;
+
+	return success;
+}
+
+static gboolean
+e_data_book_gdbus_remove_sync (GDBusProxy  *proxy,
+			       GError     **error)
+
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("()");
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "remove", parameters,
+							-1, NULL, error);
+
+	return remove_demarshal_retvals (retvals);
+}
+
+typedef void (*e_data_book_gdbus_remove_reply) (GDBusProxy *proxy,
+						GError     *error,
+						gpointer    user_data);
+
+static void
+remove_cb (GDBusProxy   *proxy,
+	   GAsyncResult *result,
+	   gpointer      user_data)
+{
+	Closure *closure = user_data;
+	GVariant *retvals;
+	GError *error = NULL;
+
+	retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+	if (retvals) {
+		if (!remove_demarshal_retvals (retvals)) {
+			error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'remove'");
+		}
+	}
+
+	(*(e_data_book_gdbus_remove_reply)closure->cb) (proxy, error, closure->user_data);
+	closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_remove (GDBusProxy                     *proxy,
+			  e_data_book_gdbus_remove_reply  callback,
+			  gpointer                        user_data)
+
+{
+	GVariant *parameters;
+	Closure *closure;
+
+	parameters = g_variant_new ("()");
+
+	closure = g_slice_new (Closure);
+	closure->cb = G_CALLBACK (callback);
+	closure->user_data = user_data;
+
+	g_dbus_proxy_invoke_method (proxy, "remove", parameters, -1, NULL, (GAsyncReadyCallback) remove_cb, closure);
+}
+
 G_END_DECLS
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index ff6dcce..76597f2 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -2,7 +2,7 @@ TEST_LIBS=							\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la	\
 	$(EVOLUTION_ADDRESSBOOK_LIBS)
 
-noinst_PROGRAMS= test-changes test-categories test-date test-ebook test-ebook-async test-ebook-view test-nonexistent-id test-photo test-query test-self test-string test-undefinedfield test-untyped-phones test-search test-stress-bookviews
+noinst_PROGRAMS= test-book-remove test-changes test-categories test-date test-ebook test-ebook-async test-ebook-view test-nonexistent-id test-photo test-query test-self test-string test-undefinedfield test-untyped-phones test-search test-stress-bookviews
 
 TEST_CPPFLAGS= \
 	$(AM_CPPFLAGS)			\
@@ -12,6 +12,8 @@ TEST_CPPFLAGS= \
 	-I$(top_builddir)/addressbook	\
 	$(EVOLUTION_ADDRESSBOOK_CFLAGS)
 
+test_book_remove_LDADD=$(TEST_LIBS)
+test_book_remove_CPPFLAGS=$(TEST_CPPFLAGS)
 test_search_LDADD=$(TEST_LIBS)
 test_search_CPPFLAGS=$(TEST_CPPFLAGS)
 test_date_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/test-book-remove.c b/addressbook/tests/ebook/test-book-remove.c
new file mode 100644
index 0000000..b9fea7a
--- /dev/null
+++ b/addressbook/tests/ebook/test-book-remove.c
@@ -0,0 +1,97 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+static GMainLoop *loop;
+
+static EBook*
+create_test_addressbook (char **uri)
+{
+        EBook *book;
+	GError *error = NULL;
+	gchar *file_template;
+
+	file_template = g_build_filename (g_get_tmp_dir (),
+					  "change-test-XXXXXX/",
+					  NULL);
+	g_mkstemp (file_template);
+
+	*uri = g_filename_to_uri (file_template, NULL, &error);
+	if (!*uri) {
+		printf ("failed to convert %s to an URI: %s\n",
+			file_template, error->message);
+		exit (1);
+	}
+	g_free (file_template);
+
+	/* create a temp addressbook in /tmp */
+	printf ("loading addressbook\n");
+	book = e_book_new_from_uri (*uri, &error);
+	if (!book) {
+		printf ("failed to create addressbook: `%s': %s\n",
+			*uri, error->message);
+		exit(1);
+	}
+
+        return book;
+}
+
+static void
+remove_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                printf ("failed to asynchronously remove the book: status %d\n",
+                                status);
+                exit (1);
+        }
+
+        printf ("successfully asynchronously removed the temporary addressbook\n");
+        g_main_loop_quit (loop);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+	EBook *book;
+        char *uri = NULL;
+	GError *error = NULL;
+
+	g_type_init ();
+
+        /* Sync version */
+        book = create_test_addressbook (&uri);
+
+	if (!e_book_open (book, FALSE, &error)) {
+		printf ("failed to open addressbook: `%s': %s\n",
+			uri, error->message);
+		exit(1);
+	}
+
+	if (!e_book_remove (book, &error)) {
+		printf ("failed to remove book; %s\n", error->message);
+		exit(1);
+	}
+	printf ("successfully removed the temporary addressbook\n");
+
+	g_object_unref (book);
+
+        /* Async version */
+        book = create_test_addressbook (&uri);
+
+	if (!e_book_open (book, FALSE, &error)) {
+		printf ("failed to open addressbook: `%s': %s\n",
+			uri, error->message);
+		exit(1);
+	}
+
+	if (e_book_async_remove (book, remove_cb, NULL)) {
+		printf ("failed to set up book removal\n");
+		exit(1);
+	}
+
+        loop = g_main_loop_new (NULL, TRUE);
+        g_main_loop_run (loop);
+
+	return 0;
+}



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