[evolution-data-server] Remove e_data_book_view_register_gdbus_object().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Remove e_data_book_view_register_gdbus_object().
- Date: Sat, 13 Oct 2012 13:23:15 +0000 (UTC)
commit b10547a3cb41fcfd3c6ba469049e39396e6e6baf
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Oct 12 14:39:40 2012 -0400
Remove e_data_book_view_register_gdbus_object().
Similar to EDataBook, the first thing we do after creating a new
EDataBookView is export its D-Bus interface. This was a separate and
failable operation. If the export fails, the EDataBookView is useless.
Perfect use case for GInitable.
Now we pass the GDBusConnection and object path directly to
e_data_book_view_new(), and if exporting fails the function sets a
GError and returns NULL.
This also introduces a couple accessor functions:
e_data_book_view_get_connection()
e_data_book_view_get_object_path()
addressbook/libedata-book/e-data-book-view.c | 191 +++++++++++++++++---
addressbook/libedata-book/e-data-book-view.h | 8 +-
addressbook/libedata-book/e-data-book.c | 33 +++--
.../libedata-book/libedata-book-sections.txt | 3 +-
4 files changed, 195 insertions(+), 40 deletions(-)
---
diff --git a/addressbook/libedata-book/e-data-book-view.c b/addressbook/libedata-book/e-data-book-view.c
index e7698cf..870d705 100644
--- a/addressbook/libedata-book/e-data-book-view.c
+++ b/addressbook/libedata-book/e-data-book-view.c
@@ -44,7 +44,9 @@
#define THRESHOLD_SECONDS 2
struct _EDataBookViewPrivate {
+ GDBusConnection *connection;
EGdbusBookView *gdbus_object;
+ gchar *object_path;
EDataBook *book;
EBookBackend *backend;
@@ -68,14 +70,25 @@ struct _EDataBookViewPrivate {
GHashTable *fields_of_interest;
};
-G_DEFINE_TYPE (EDataBookView, e_data_book_view, G_TYPE_OBJECT);
-
enum {
PROP_0,
PROP_BACKEND,
+ PROP_CONNECTION,
+ PROP_OBJECT_PATH,
PROP_SEXP
};
+/* Forward Declarations */
+static void e_data_book_view_initable_init (GInitableIface *interface);
+
+G_DEFINE_TYPE_WITH_CODE (
+ EDataBookView,
+ e_data_book_view,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (
+ G_TYPE_INITABLE,
+ e_data_book_view_initable_init))
+
static guint
str_ic_hash (gconstpointer key)
{
@@ -354,6 +367,26 @@ data_book_view_set_backend (EDataBookView *view,
}
static void
+data_book_view_set_connection (EDataBookView *view,
+ GDBusConnection *connection)
+{
+ g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
+ g_return_if_fail (view->priv->connection == NULL);
+
+ view->priv->connection = g_object_ref (connection);
+}
+
+static void
+data_book_view_set_object_path (EDataBookView *view,
+ const gchar *object_path)
+{
+ g_return_if_fail (object_path != NULL);
+ g_return_if_fail (view->priv->object_path == NULL);
+
+ view->priv->object_path = g_strdup (object_path);
+}
+
+static void
data_book_view_set_sexp (EDataBookView *view,
EBookBackendSExp *sexp)
{
@@ -376,6 +409,18 @@ data_book_view_set_property (GObject *object,
g_value_get_object (value));
return;
+ case PROP_CONNECTION:
+ data_book_view_set_connection (
+ E_DATA_BOOK_VIEW (object),
+ g_value_get_object (value));
+ return;
+
+ case PROP_OBJECT_PATH:
+ data_book_view_set_object_path (
+ E_DATA_BOOK_VIEW (object),
+ g_value_get_string (value));
+ return;
+
case PROP_SEXP:
data_book_view_set_sexp (
E_DATA_BOOK_VIEW (object),
@@ -400,6 +445,20 @@ data_book_view_get_property (GObject *object,
E_DATA_BOOK_VIEW (object)));
return;
+ case PROP_CONNECTION:
+ g_value_set_object (
+ value,
+ e_data_book_view_get_connection (
+ E_DATA_BOOK_VIEW (object)));
+ return;
+
+ case PROP_OBJECT_PATH:
+ g_value_set_string (
+ value,
+ e_data_book_view_get_object_path (
+ E_DATA_BOOK_VIEW (object)));
+ return;
+
case PROP_SEXP:
g_value_set_object (
value,
@@ -418,6 +477,11 @@ data_book_view_dispose (GObject *object)
priv = E_DATA_BOOK_VIEW_GET_PRIVATE (object);
+ if (priv->connection != NULL) {
+ g_object_unref (priv->connection);
+ priv->connection = NULL;
+ }
+
if (priv->book != NULL) {
/* Remove the weak reference */
g_object_weak_unref (
@@ -456,6 +520,8 @@ data_book_view_finalize (GObject *object)
priv = E_DATA_BOOK_VIEW_GET_PRIVATE (object);
+ g_free (priv->object_path);
+
reset_array (priv->adds);
reset_array (priv->changes);
reset_array (priv->removes);
@@ -474,6 +540,22 @@ data_book_view_finalize (GObject *object)
G_OBJECT_CLASS (e_data_book_view_parent_class)->finalize (object);
}
+static gboolean
+data_book_view_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ EDataBookView *view;
+
+ view = E_DATA_BOOK_VIEW (initable);
+
+ return e_gdbus_book_view_register_object (
+ view->priv->gdbus_object,
+ view->priv->connection,
+ view->priv->object_path,
+ error);
+}
+
static void
e_data_book_view_class_init (EDataBookViewClass *class)
{
@@ -501,6 +583,32 @@ e_data_book_view_class_init (EDataBookViewClass *class)
g_object_class_install_property (
object_class,
+ PROP_CONNECTION,
+ g_param_spec_object (
+ "connection",
+ "Connection",
+ "The GDBusConnection on which "
+ "to export the view interface",
+ G_TYPE_DBUS_CONNECTION,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_OBJECT_PATH,
+ g_param_spec_string (
+ "object-path",
+ "Object Path",
+ "The object path at which to "
+ "export the view interface",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
PROP_SEXP,
g_param_spec_object (
"sexp",
@@ -513,6 +621,12 @@ e_data_book_view_class_init (EDataBookViewClass *class)
}
static void
+e_data_book_view_initable_init (GInitableIface *interface)
+{
+ interface->init = data_book_view_initable_init;
+}
+
+static void
e_data_book_view_init (EDataBookView *view)
{
view->priv = E_DATA_BOOK_VIEW_GET_PRIVATE (view);
@@ -568,21 +682,31 @@ e_data_book_view_init (EDataBookView *view)
*/
EDataBookView *
e_data_book_view_new (EDataBook *book,
- EBookBackendSExp *sexp)
+ EBookBackendSExp *sexp,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
{
EDataBookView *view;
EBookBackend *backend;
g_return_val_if_fail (E_IS_DATA_BOOK (book), NULL);
g_return_val_if_fail (E_IS_BOOK_BACKEND_SEXP (sexp), NULL);
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (object_path != NULL, NULL);
backend = e_data_book_get_backend (book);
- view = g_object_new (
- E_TYPE_DATA_BOOK_VIEW,
+ view = g_initable_new (
+ E_TYPE_DATA_BOOK_VIEW, NULL, error,
"backend", backend,
+ "connection", connection,
+ "object-path", object_path,
"sexp", sexp, NULL);
+ if (view == NULL)
+ return NULL;
+
view->priv->book = book;
/* Attach a weak reference to the book, so
* if it dies the book view is destroyed too. */
@@ -594,25 +718,6 @@ e_data_book_view_new (EDataBook *book,
}
/**
- * e_data_book_view_register_gdbus_object:
- *
- * Since: 2.32
- **/
-guint
-e_data_book_view_register_gdbus_object (EDataBookView *query,
- GDBusConnection *connection,
- const gchar *object_path,
- GError **error)
-{
- g_return_val_if_fail (E_IS_DATA_BOOK_VIEW (query), 0);
- g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
- g_return_val_if_fail (object_path != NULL, 0);
-
- return e_gdbus_book_view_register_object (
- query->priv->gdbus_object, connection, object_path, error);
-}
-
-/**
* e_data_book_view_get_backend:
* @view: an #EDataBookView
*
@@ -645,6 +750,44 @@ e_data_book_view_get_sexp (EDataBookView *view)
}
/**
+ * e_data_book_view_get_connection:
+ * @view: an #EDataBookView
+ *
+ * Returns the #GDBusConnection on which the AddressBookView D-Bus
+ * interface is exported.
+ *
+ * Returns: the #GDBusConnection
+ *
+ * Since: 3.8
+ **/
+GDBusConnection *
+e_data_book_view_get_connection (EDataBookView *view)
+{
+ g_return_val_if_fail (E_IS_DATA_BOOK_VIEW (view), NULL);
+
+ return view->priv->connection;
+}
+
+/**
+ * e_data_book_view_get_object_path:
+ * @view: an #EDataBookView
+ *
+ * Returns the object path at which the AddressBookView D-Bus interface
+ * is exported.
+ *
+ * Returns: the object path
+ *
+ * Since: 3.8
+ **/
+const gchar *
+e_data_book_view_get_object_path (EDataBookView *view)
+{
+ g_return_val_if_fail (E_IS_DATA_BOOK_VIEW (view), NULL);
+
+ return view->priv->object_path;
+}
+
+/**
* e_data_book_view_get_flags:
* @view: an #EDataBookView
*
diff --git a/addressbook/libedata-book/e-data-book-view.h b/addressbook/libedata-book/e-data-book-view.h
index 53291d1..5cda7ca 100644
--- a/addressbook/libedata-book/e-data-book-view.h
+++ b/addressbook/libedata-book/e-data-book-view.h
@@ -71,14 +71,16 @@ struct _EDataBookViewClass {
GType e_data_book_view_get_type (void) G_GNUC_CONST;
EDataBookView * e_data_book_view_new (struct _EDataBook *book,
- EBookBackendSExp *sexp);
-guint e_data_book_view_register_gdbus_object
- (EDataBookView *query,
+ EBookBackendSExp *sexp,
GDBusConnection *connection,
const gchar *object_path,
GError **error);
struct _EBookBackend *
e_data_book_view_get_backend (EDataBookView *view);
+GDBusConnection *
+ e_data_book_view_get_connection (EDataBookView *view);
+const gchar * e_data_book_view_get_object_path
+ (EDataBookView *view);
EBookBackendSExp *
e_data_book_view_get_sexp (EDataBookView *view);
EBookClientViewFlags
diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c
index 7747097..704fdef 100644
--- a/addressbook/libedata-book/e-data-book.c
+++ b/addressbook/libedata-book/e-data-book.c
@@ -195,9 +195,10 @@ operation_thread (gpointer data,
break;
case OP_GET_VIEW:
if (op->d.query) {
+ EDataBookView *view;
EBookBackendSExp *card_sexp;
- EDataBookView *book_view;
- gchar *path;
+ GDBusConnection *connection;
+ gchar *object_path;
GError *error = NULL;
card_sexp = e_book_backend_sexp_new (op->d.query);
@@ -210,27 +211,35 @@ operation_thread (gpointer data,
break;
}
- path = construct_bookview_path ();
+ object_path = construct_bookview_path ();
+ connection = e_gdbus_book_stub_get_connection (
+ op->book->priv->gdbus_object);
- book_view = e_data_book_view_new (op->book, card_sexp);
- e_data_book_view_register_gdbus_object (book_view, e_gdbus_book_stub_get_connection (op->book->priv->gdbus_object), path, &error);
+ view = e_data_book_view_new (
+ op->book, card_sexp,
+ connection, object_path, &error);
- if (error) {
+ g_object_unref (card_sexp);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((view != NULL) && (error == NULL)) ||
+ ((view == NULL) && (error != NULL)));
+
+ if (error != NULL) {
/* Translators: This is prefix to a detailed error message */
g_prefix_error (&error, "%s", _("Invalid query: "));
e_gdbus_book_emit_get_view_done (op->book->priv->gdbus_object, op->id, error, NULL);
g_error_free (error);
- g_object_unref (book_view);
- g_free (path);
-
+ g_free (object_path);
break;
}
- e_book_backend_add_view (backend, book_view);
+ e_book_backend_add_view (backend, view);
- e_gdbus_book_emit_get_view_done (op->book->priv->gdbus_object, op->id, NULL, path);
+ e_gdbus_book_emit_get_view_done (op->book->priv->gdbus_object, op->id, NULL, object_path);
- g_free (path);
+ g_free (object_path);
}
g_free (op->d.query);
break;
diff --git a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
index ad8831f..c018586 100644
--- a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
+++ b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
@@ -328,8 +328,9 @@ e_data_book_factory_get_type
<TITLE>EDataBookView</TITLE>
EDataBookView
e_data_book_view_new
-e_data_book_view_register_gdbus_object
e_data_book_view_get_backend
+e_data_book_view_get_connection
+e_data_book_view_get_object_path
e_data_book_view_get_sexp
e_data_book_view_get_flags
e_data_book_view_notify_update
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]