[evolution-data-server/openismus-work] Added EDataBookDirect
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] Added EDataBookDirect
- Date: Thu, 22 Nov 2012 09:00:47 +0000 (UTC)
commit 6ce78c63bf12075c31b2d0ed47fdf6d44eddcffe
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Thu Nov 22 17:41:18 2012 +0900
Added EDataBookDirect
EDataBookDirect is a backend visible object which implements
the EGdbusBookDirect D-Bus object.
New methods added to EBookBackendClass
get_direct_book: This is implemented by backends which support direct read access
configure_direct: This passes an opaque configure string that was
previously given to the client via get_direct_book(),
and is used to ensure that direct access books are
properly configured to interface with the same data
as the server's copy of the backend.
addressbook/libedata-book/Makefile.am | 2 +
addressbook/libedata-book/e-book-backend.c | 48 +++++++++
addressbook/libedata-book/e-book-backend.h | 10 ++
addressbook/libedata-book/e-data-book-direct.c | 132 ++++++++++++++++++++++++
addressbook/libedata-book/e-data-book-direct.h | 64 ++++++++++++
addressbook/libedata-book/e-data-book.c | 40 +++++---
addressbook/libedata-book/e-data-book.h | 6 +-
addressbook/libedata-book/libedata-book.h | 1 +
8 files changed, 286 insertions(+), 17 deletions(-)
---
diff --git a/addressbook/libedata-book/Makefile.am b/addressbook/libedata-book/Makefile.am
index 51001e4..b7e9351 100644
--- a/addressbook/libedata-book/Makefile.am
+++ b/addressbook/libedata-book/Makefile.am
@@ -31,6 +31,7 @@ libedata_book_1_2_la_SOURCES = \
e-data-book.c \
e-data-book-factory.c \
e-data-book-view.c \
+ e-data-book-direct.c \
ximian-vcard.h
libedata_book_1_2_la_LIBADD = \
@@ -60,6 +61,7 @@ libedata_bookinclude_HEADERS = \
e-book-backend.h \
e-data-book-factory.h \
e-data-book-view.h \
+ e-data-book-direct.h \
e-data-book.h \
e-book-backend-cache.h \
e-book-backend-sqlitedb.h \
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index 83fd371..965f1c1 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -1036,6 +1036,54 @@ e_book_backend_set_is_removed (EBookBackend *backend,
}
/**
+ * e_book_backend_get_direct_book:
+ * @backend: an #EBookBackend
+ *
+ * Tries to create an #EDataBookDirect for @backend if
+ * backend supports direct read access.
+ *
+ * Returns: (transfer full): A new #EDataBookDirect object, or %NULL if @backend does not support direct access
+ *
+ * Since: 3.8
+ */
+EDataBookDirect *
+e_book_backend_get_direct_book (EBookBackend *backend)
+{
+ g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), NULL);
+
+ if (E_BOOK_BACKEND_GET_CLASS (backend)->get_direct_book)
+ return E_BOOK_BACKEND_GET_CLASS (backend)->get_direct_book (backend);
+
+ return NULL;
+}
+
+/**
+ * e_book_backend_configure_direct:
+ * @backend: an #EBookBackend
+ * @config: The configuration string for the given backend
+ *
+ * This method is called on @backend in direct read access mode.
+ * The @config argument is the same configuration string which
+ * the same backend reported in the #EDataBookDirect returned
+ * by e_book_backend_get_direct_book().
+ *
+ * The configuration string is optional and is used to ensure
+ * that direct access backends are properly configured to
+ * interface with the same data as the running server side backend.
+ *
+ * Since: 3.8
+ */
+void
+e_book_backend_configure_direct (EBookBackend *backend,
+ const gchar *config)
+{
+ g_return_if_fail (E_IS_BOOK_BACKEND (backend));
+
+ if (E_BOOK_BACKEND_GET_CLASS (backend)->configure_direct)
+ E_BOOK_BACKEND_GET_CLASS (backend)->configure_direct (backend, config);
+}
+
+/**
* e_book_backend_sync:
* @backend: an #EBookbackend
*
diff --git a/addressbook/libedata-book/e-book-backend.h b/addressbook/libedata-book/e-book-backend.h
index 37fa21e..434b1a3 100644
--- a/addressbook/libedata-book/e-book-backend.h
+++ b/addressbook/libedata-book/e-book-backend.h
@@ -31,6 +31,7 @@
#include <libedata-book/e-data-book.h>
#include <libedata-book/e-data-book-view.h>
+#include <libedata-book/e-data-book-direct.h>
G_BEGIN_DECLS
@@ -165,6 +166,11 @@ struct _EBookBackendClass {
void (* notify_update) (EBookBackend *backend, const EContact *contact);
+
+ EDataBookDirect *
+ (* get_direct_book) (EBookBackend *backend);
+ void (* configure_direct) (EBookBackend *backend, const gchar *config);
+
/* Notification signals */
void (* sync) (EBookBackend *backend);
};
@@ -213,6 +219,10 @@ void e_book_backend_notify_online (EBookBackend *backend, gboolean is_online);
void e_book_backend_notify_opened (EBookBackend *backend, GError *error);
void e_book_backend_notify_property_changed (EBookBackend *backend, const gchar *prop_name, const gchar *prop_value);
+EDataBookDirect *
+ e_book_backend_get_direct_book (EBookBackend *backend);
+void e_book_backend_configure_direct (EBookBackend *backend, const gchar *config);
+
void e_book_backend_sync (EBookBackend *backend);
/* protected functions for subclasses */
diff --git a/addressbook/libedata-book/e-data-book-direct.c b/addressbook/libedata-book/e-data-book-direct.c
new file mode 100644
index 0000000..df68c31
--- /dev/null
+++ b/addressbook/libedata-book/e-data-book-direct.c
@@ -0,0 +1,132 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Openismus GmbH (www.openismus.com)
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include "e-data-book-direct.h"
+#include "e-gdbus-book-direct.h"
+
+#define E_DATA_BOOK_DIRECT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_DATA_BOOK_DIRECT, EDataBookDirectPrivate))
+
+G_DEFINE_TYPE (EDataBookDirect, e_data_book_direct, G_TYPE_OBJECT);
+#define THRESHOLD_ITEMS 32 /* how many items can be hold in a cache, before propagated to UI */
+#define THRESHOLD_SECONDS 2 /* how long to wait until notifications are propagated to UI; in seconds */
+
+struct _EDataBookDirectPrivate {
+ EGdbusBookDirect *gdbus_object;
+};
+
+/* GObjectClass */
+static void
+e_data_book_direct_dispose (GObject *object)
+{
+ EDataBookDirect *direct = E_DATA_BOOK_DIRECT (object);
+
+ if (direct->priv->gdbus_object) {
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (direct->priv->gdbus_object));
+ g_object_unref (direct->priv->gdbus_object);
+ direct->priv->gdbus_object = NULL;
+ }
+
+ G_OBJECT_CLASS (e_data_book_direct_parent_class)->dispose (object);
+}
+
+static void
+e_data_book_direct_init (EDataBookDirect *direct)
+{
+ direct->priv = E_DATA_BOOK_DIRECT_GET_PRIVATE (direct);
+ direct->priv->gdbus_object = e_gdbus_book_direct_skeleton_new ();
+}
+
+static void
+e_data_book_direct_class_init (EDataBookDirectClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ g_type_class_add_private (class, sizeof (EDataBookDirectPrivate));
+
+ object_class->dispose = e_data_book_direct_dispose;
+}
+
+/**
+ * e_data_book_direct_new:
+ * @backend_path: Full path to the installed backend shared library
+ * @backend_factory_name: Type name of the EBookBackendFactory implemented by the library
+ * @config: A backend specific configuration string
+ *
+ * Creates a #EDataBookDirect to report configuration data needed for direct
+ * read access.
+ *
+ * This is returned by e_book_backend_get_direct_book() for backends
+ * which support direct read access mode.
+ *
+ * Returns: (transfer full): A newly created #EDataBookDirect
+ *
+ * Since: 3.8
+ */
+EDataBookDirect *
+e_data_book_direct_new (const gchar *backend_path,
+ const gchar *backend_factory_name,
+ const gchar *config)
+{
+ EDataBookDirect *direct;
+
+ g_return_val_if_fail (backend_path && backend_path[0], NULL);
+ g_return_val_if_fail (backend_factory_name && backend_factory_name[0], NULL);
+
+ direct = g_object_new (E_TYPE_DATA_BOOK_DIRECT, NULL);
+
+ e_gdbus_book_direct_set_backend_path (direct->priv->gdbus_object, backend_path);
+ e_gdbus_book_direct_set_backend_name (direct->priv->gdbus_object, backend_factory_name);
+ e_gdbus_book_direct_set_backend_config (direct->priv->gdbus_object, config);
+
+ return direct;
+}
+
+/**
+ * e_data_book_direct_register_gdbus_object:
+ * @direct: An #EDataBookDirect
+ * @connection: The #GDBusConnection to register with
+ * @object_path: The object path to place the direct access configuration data
+ * @error: A location to store any error which might occur while registering
+ *
+ * Places @direct on the @connection at @object_path
+ *
+ * Since: 3.8
+ **/
+gboolean
+e_data_book_direct_register_gdbus_object (EDataBookDirect *direct,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
+{
+ g_return_val_if_fail (E_IS_DATA_BOOK_DIRECT (direct), FALSE);
+ g_return_val_if_fail (connection != NULL, FALSE);
+ g_return_val_if_fail (object_path != NULL, 0);
+
+ return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (direct->priv->gdbus_object),
+ connection, object_path, error);
+}
diff --git a/addressbook/libedata-book/e-data-book-direct.h b/addressbook/libedata-book/e-data-book-direct.h
new file mode 100644
index 0000000..6d7380e
--- /dev/null
+++ b/addressbook/libedata-book/e-data-book-direct.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Openismus GmbH (www.openismus.com)
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#if !defined (__LIBEDATA_BOOK_H_INSIDE__) && !defined (LIBEDATA_BOOK_COMPILATION)
+#error "Only <libedata-book/libedata-book.h> should be included directly."
+#endif
+
+#ifndef __E_DATA_BOOK_DIRECT_H__
+#define __E_DATA_BOOK_DIRECT_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define E_TYPE_DATA_BOOK_DIRECT (e_data_book_direct_get_type ())
+#define E_DATA_BOOK_DIRECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_DATA_BOOK_DIRECT, EDataBookDirect))
+#define E_DATA_BOOK_DIRECT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), E_TYPE_DATA_BOOK_DIRECT, EDataBookDirectClass))
+#define E_IS_DATA_BOOK_DIRECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_DATA_BOOK_DIRECT))
+#define E_IS_DATA_BOOK_DIRECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_TYPE_DATA_BOOK_DIRECT))
+#define E_DATA_BOOK_DIRECT_GET_CLASS(k) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_DATA_BOOK_DIRECT, EDataBookDirect))
+
+typedef struct _EDataBookDirect EDataBookDirect;
+typedef struct _EDataBookDirectClass EDataBookDirectClass;
+typedef struct _EDataBookDirectPrivate EDataBookDirectPrivate;
+
+struct _EDataBookDirect {
+ GObject parent;
+ EDataBookDirectPrivate *priv;
+};
+
+struct _EDataBookDirectClass {
+ GObjectClass parent;
+};
+
+GType e_data_book_direct_get_type (void);
+EDataBookDirect * e_data_book_direct_new (const gchar *backend_path,
+ const gchar *backend_factory_name,
+ const gchar *config);
+
+gboolean e_data_book_direct_register_gdbus_object (EDataBookDirect *direct,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __E_DATA_BOOK_DIRECT_H__ */
diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c
index fdd90a1..362e460 100644
--- a/addressbook/libedata-book/e-data-book.c
+++ b/addressbook/libedata-book/e-data-book.c
@@ -50,6 +50,7 @@ struct _EDataBookPrivate
{
EGdbusBook *gdbus_object;
EModule *direct_module;
+ EDataBookDirect *direct_book;
EBookBackend *backend;
@@ -1531,6 +1532,12 @@ e_data_book_register_gdbus_object (EDataBook *book,
g_return_val_if_fail (connection != NULL, 0);
g_return_val_if_fail (object_path != NULL, 0);
+ if (book->priv->direct_book &&
+ !e_data_book_direct_register_gdbus_object (book->priv->direct_book,
+ connection, object_path,
+ error))
+ return 0;
+
return e_gdbus_book_register_object (book->priv->gdbus_object, connection, object_path, error);
}
@@ -1654,6 +1661,11 @@ data_book_dispose (GObject *object)
priv->backend = NULL;
}
+ if (priv->direct_book) {
+ g_object_unref (priv->direct_book);
+ priv->direct_book = NULL;
+ }
+
if (priv->direct_module) {
g_type_module_unuse (G_TYPE_MODULE (priv->direct_module));
priv->direct_module = NULL;
@@ -1761,12 +1773,18 @@ e_data_book_new (EBookBackend *backend)
g_object_unref (gdbus_object);
+ /* This will be NULL for a backend that does not support direct read access */
+ book->priv->direct_book = e_book_backend_get_direct_book (backend);
+
return book;
}
EDataBook *
e_data_book_new_direct (ESourceRegistry *registry,
- ESource *source)
+ ESource *source,
+ const gchar *backend_path,
+ const gchar *backend_name,
+ const gchar *config)
{
EDataBook *book = NULL;
EModule *module;
@@ -1774,22 +1792,11 @@ e_data_book_new_direct (ESourceRegistry *registry,
GType backend_type;
GType factory_type;
GTypeClass *factory_class;
- gchar *backend_path;
- gchar *backend_name;
- ESourceDirectAccess *direct;
g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
g_return_val_if_fail (E_IS_SOURCE (source), NULL);
-
- REGISTER_TYPE (E_TYPE_SOURCE_DIRECT_ACCESS);
- direct = e_source_get_extension (source, E_SOURCE_EXTENSION_DIRECT_ACCESS);
- backend_path = e_source_direct_access_dup_backend_path (direct);
- backend_name = e_source_direct_access_dup_backend_name (direct);
-
- if (!backend_path || !backend_name) {
- g_warning ("ESource is not configured for direct access");
- goto new_direct_finish;
- }
+ g_return_val_if_fail (backend_path && backend_path[0], NULL);
+ g_return_val_if_fail (backend_name && backend_name[0], NULL);
module = load_module (backend_path);
if (!module)
@@ -1816,12 +1823,13 @@ e_data_book_new_direct (ESourceRegistry *registry,
"registry", registry,
"source", source, NULL);
+ e_book_backend_configure_direct (backend, config);
+
book = g_object_new (E_TYPE_DATA_BOOK, "backend", backend, NULL);
book->priv->direct_module = module;
+ g_object_unref (backend);
new_direct_finish:
- g_free (backend_path);
- g_free (backend_name);
return book;
}
diff --git a/addressbook/libedata-book/e-data-book.h b/addressbook/libedata-book/e-data-book.h
index 6d6f276..9a2a312 100644
--- a/addressbook/libedata-book/e-data-book.h
+++ b/addressbook/libedata-book/e-data-book.h
@@ -131,7 +131,11 @@ const gchar *e_data_book_status_to_string (EDataBookStatus status);
GType e_data_book_get_type (void);
EDataBook * e_data_book_new (struct _EBookBackend *backend);
-EDataBook * e_data_book_new_direct (ESourceRegistry *registry, ESource *source);
+EDataBook * e_data_book_new_direct (ESourceRegistry *registry,
+ ESource *source,
+ const gchar *backend_path,
+ const gchar *backend_name,
+ const gchar *config);
struct _EBookBackend *
e_data_book_get_backend (EDataBook *book);
diff --git a/addressbook/libedata-book/libedata-book.h b/addressbook/libedata-book/libedata-book.h
index bd5457c..ec15c83 100644
--- a/addressbook/libedata-book/libedata-book.h
+++ b/addressbook/libedata-book/libedata-book.h
@@ -34,6 +34,7 @@
#include <libedata-book/e-book-backend.h>
#include <libedata-book/e-data-book-factory.h>
#include <libedata-book/e-data-book-view.h>
+#include <libedata-book/e-data-book-direct.h>
#include <libedata-book/e-data-book.h>
#undef __LIBEDATA_BOOK_H_INSIDE__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]