[evolution-data-server] Remove e_data_cal_view_register_gdbus_object().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Remove e_data_cal_view_register_gdbus_object().
- Date: Sat, 13 Oct 2012 13:23:20 +0000 (UTC)
commit 8bdefa87db7d0ec3f113273fbccfd864391d40f4
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Oct 12 19:15:44 2012 -0400
Remove e_data_cal_view_register_gdbus_object().
Similar to EDataCal, the first thing we do after creating a new
EDataCalView is export its D-Bus interface. This was a separate and
failable operation. If the export fails, the EDataCalView is useless.
Perfect use case for GInitable.
Now we pass the GDBusConnection and object path directly to
e_data_cal_view_new(), and if exporting fails the function sets a
GError and returns NULL.
This also introduces a couple accessor functions:
e_data_cal_view_get_connection()
e_data_cal_view_get_object_path()
calendar/libedata-cal/e-data-cal-view.c | 190 +++++++++++++++++---
calendar/libedata-cal/e-data-cal-view.h | 7 +-
calendar/libedata-cal/e-data-cal.c | 33 ++--
.../libedata-cal/libedata-cal-sections.txt | 3 +-
4 files changed, 190 insertions(+), 43 deletions(-)
---
diff --git a/calendar/libedata-cal/e-data-cal-view.c b/calendar/libedata-cal/e-data-cal-view.c
index 86917a9..f23d6c4 100644
--- a/calendar/libedata-cal/e-data-cal-view.c
+++ b/calendar/libedata-cal/e-data-cal-view.c
@@ -42,7 +42,9 @@
#define THRESHOLD_SECONDS 2
struct _EDataCalViewPrivate {
+ GDBusConnection *connection;
EGdbusCalView *gdbus_object;
+ gchar *object_path;
/* The backend we are monitoring */
ECalBackend *backend;
@@ -73,10 +75,21 @@ struct _EDataCalViewPrivate {
enum {
PROP_0,
PROP_BACKEND,
+ PROP_CONNECTION,
+ PROP_OBJECT_PATH,
PROP_SEXP
};
-G_DEFINE_TYPE (EDataCalView, e_data_cal_view, G_TYPE_OBJECT);
+/* Forward Declarations */
+static void e_data_cal_view_initable_init (GInitableIface *interface);
+
+G_DEFINE_TYPE_WITH_CODE (
+ EDataCalView,
+ e_data_cal_view,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (
+ G_TYPE_INITABLE,
+ e_data_cal_view_initable_init))
static guint
str_ic_hash (gconstpointer key)
@@ -296,6 +309,26 @@ data_cal_view_set_backend (EDataCalView *view,
}
static void
+data_cal_view_set_connection (EDataCalView *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_cal_view_set_object_path (EDataCalView *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_cal_view_set_sexp (EDataCalView *view,
ECalBackendSExp *sexp)
{
@@ -318,6 +351,18 @@ data_cal_view_set_property (GObject *object,
g_value_get_object (value));
return;
+ case PROP_CONNECTION:
+ data_cal_view_set_connection (
+ E_DATA_CAL_VIEW (object),
+ g_value_get_object (value));
+ return;
+
+ case PROP_OBJECT_PATH:
+ data_cal_view_set_object_path (
+ E_DATA_CAL_VIEW (object),
+ g_value_get_string (value));
+ return;
+
case PROP_SEXP:
data_cal_view_set_sexp (
E_DATA_CAL_VIEW (object),
@@ -342,6 +387,20 @@ data_cal_view_get_property (GObject *object,
E_DATA_CAL_VIEW (object)));
return;
+ case PROP_CONNECTION:
+ g_value_set_object (
+ value,
+ e_data_cal_view_get_connection (
+ E_DATA_CAL_VIEW (object)));
+ return;
+
+ case PROP_OBJECT_PATH:
+ g_value_set_string (
+ value,
+ e_data_cal_view_get_object_path (
+ E_DATA_CAL_VIEW (object)));
+ return;
+
case PROP_SEXP:
g_value_set_object (
value,
@@ -368,6 +427,11 @@ data_cal_view_dispose (GObject *object)
priv->backend = NULL;
}
+ if (priv->connection != NULL) {
+ g_object_unref (priv->connection);
+ priv->connection = NULL;
+ }
+
if (priv->sexp != NULL) {
g_object_unref (priv->sexp);
priv->sexp = NULL;
@@ -393,6 +457,8 @@ data_cal_view_finalize (GObject *object)
priv = E_DATA_CAL_VIEW_GET_PRIVATE (object);
+ g_free (priv->object_path);
+
reset_array (priv->adds);
reset_array (priv->changes);
reset_array (priv->removes);
@@ -412,6 +478,22 @@ data_cal_view_finalize (GObject *object)
G_OBJECT_CLASS (e_data_cal_view_parent_class)->finalize (object);
}
+static gboolean
+data_cal_view_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ EDataCalView *view;
+
+ view = E_DATA_CAL_VIEW (initable);
+
+ return e_gdbus_cal_view_register_object (
+ view->priv->gdbus_object,
+ view->priv->connection,
+ view->priv->object_path,
+ error);
+}
+
static void
e_data_cal_view_class_init (EDataCalViewClass *class)
{
@@ -439,6 +521,32 @@ e_data_cal_view_class_init (EDataCalViewClass *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",
@@ -451,6 +559,12 @@ e_data_cal_view_class_init (EDataCalViewClass *class)
}
static void
+e_data_cal_view_initable_init (GInitableIface *interface)
+{
+ interface->init = data_cal_view_initable_init;
+}
+
+static void
e_data_cal_view_init (EDataCalView *view)
{
view->priv = E_DATA_CAL_VIEW_GET_PRIVATE (view);
@@ -500,33 +614,23 @@ e_data_cal_view_init (EDataCalView *view)
EDataCalView *
e_data_cal_view_new (ECalBackend *backend,
- ECalBackendSExp *sexp)
+ ECalBackendSExp *sexp,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
{
g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
g_return_val_if_fail (E_IS_CAL_BACKEND_SEXP (sexp), NULL);
-
- return g_object_new (
- E_TYPE_DATA_CAL_VIEW,
- "backend", backend, "sexp", sexp, NULL);
-}
-
-/**
- * e_data_cal_view_register_gdbus_object:
- *
- * Since: 2.32
- **/
-guint
-e_data_cal_view_register_gdbus_object (EDataCalView *view,
- GDBusConnection *connection,
- const gchar *object_path,
- GError **error)
-{
- g_return_val_if_fail (E_IS_DATA_CAL_VIEW (view), 0);
- g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
- g_return_val_if_fail (object_path != NULL, 0);
-
- return e_gdbus_cal_view_register_object (
- view->priv->gdbus_object, connection, object_path, error);
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (object_path != NULL, NULL);
+
+ return g_initable_new (
+ E_TYPE_DATA_CAL_VIEW, NULL, error,
+ "backend", backend,
+ "connection", connection,
+ "object-path", object_path,
+ "sexp", sexp,
+ NULL);
}
static void
@@ -751,6 +855,44 @@ e_data_cal_view_get_backend (EDataCalView *view)
}
/**
+ * e_data_cal_view_get_connection:
+ * @view: an #EDataCalView
+ *
+ * Returns the #GDBusConnection on which the CalendarView D-Bus
+ * interface is exported.
+ *
+ * Returns: the #GDBusConnection
+ *
+ * Since: 3.8
+ **/
+GDBusConnection *
+e_data_cal_view_get_connection (EDataCalView *view)
+{
+ g_return_val_if_fail (E_IS_DATA_CAL_VIEW (view), NULL);
+
+ return view->priv->connection;
+}
+
+/**
+ * e_data_cal_view_get_object_path:
+ * @view: an #EDataCalView
+ *
+ * Return the object path at which the CalendarView D-Bus inteface is
+ * exported.
+ *
+ * Returns: the object path
+ *
+ * Since: 3.8
+ **/
+const gchar *
+e_data_cal_view_get_object_path (EDataCalView *view)
+{
+ g_return_val_if_fail (E_IS_DATA_CAL_VIEW (view), NULL);
+
+ return view->priv->object_path;
+}
+
+/**
* e_data_cal_view_get_sexp:
* @view: an #EDataCalView
*
diff --git a/calendar/libedata-cal/e-data-cal-view.h b/calendar/libedata-cal/e-data-cal-view.h
index d04e71c..c992615 100644
--- a/calendar/libedata-cal/e-data-cal-view.h
+++ b/calendar/libedata-cal/e-data-cal-view.h
@@ -66,14 +66,15 @@ struct _EDataCalViewClass {
GType e_data_cal_view_get_type (void) G_GNUC_CONST;
EDataCalView * e_data_cal_view_new (struct _ECalBackend *backend,
- struct _ECalBackendSExp *sexp);
-guint e_data_cal_view_register_gdbus_object
- (EDataCalView *view,
+ struct _ECalBackendSExp *sexp,
GDBusConnection *connection,
const gchar *object_path,
GError **error);
struct _ECalBackend *
e_data_cal_view_get_backend (EDataCalView *view);
+GDBusConnection *
+ e_data_cal_view_get_connection (EDataCalView *view);
+const gchar * e_data_cal_view_get_object_path (EDataCalView *view);
struct _ECalBackendSExp *
e_data_cal_view_get_sexp (EDataCalView *view);
gboolean e_data_cal_view_object_matches (EDataCalView *view,
diff --git a/calendar/libedata-cal/e-data-cal.c b/calendar/libedata-cal/e-data-cal.c
index 2a2e038..7a0a6dc 100644
--- a/calendar/libedata-cal/e-data-cal.c
+++ b/calendar/libedata-cal/e-data-cal.c
@@ -254,7 +254,8 @@ operation_thread (gpointer data,
if (op->d.sexp) {
EDataCalView *view;
ECalBackendSExp *obj_sexp;
- gchar *path;
+ GDBusConnection *connection;
+ gchar *object_path;
GError *error = NULL;
/* we handle this entirely here, since it doesn't require any
@@ -268,32 +269,34 @@ operation_thread (gpointer data,
break;
}
- view = e_data_cal_view_new (backend, obj_sexp);
+ object_path = construct_calview_path ();
+ connection = e_gdbus_cal_stub_get_connection (
+ op->cal->priv->gdbus_object);
+
+ view = e_data_cal_view_new (
+ backend, obj_sexp,
+ connection, object_path, &error);
+
g_object_unref (obj_sexp);
- if (!view) {
- g_free (op->d.sexp);
- e_data_cal_respond_get_view (op->cal, op->id, EDC_ERROR (OtherError), NULL);
- break;
- }
- path = construct_calview_path ();
- e_data_cal_view_register_gdbus_object (view, e_gdbus_cal_stub_get_connection (op->cal->priv->gdbus_object), path, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((view != NULL) && (error == NULL)) ||
+ ((view == NULL) && (error != NULL)));
- if (error) {
- g_object_unref (view);
+ if (error != NULL) {
g_free (op->d.sexp);
e_data_cal_respond_get_view (op->cal, op->id, EDC_ERROR_EX (OtherError, error->message), NULL);
g_error_free (error);
- g_free (path);
-
+ g_free (object_path);
break;
}
e_cal_backend_add_view (backend, view);
- e_data_cal_respond_get_view (op->cal, op->id, EDC_ERROR (Success), path);
+ e_data_cal_respond_get_view (op->cal, op->id, EDC_ERROR (Success), object_path);
- g_free (path);
+ g_free (object_path);
}
g_free (op->d.sexp);
break;
diff --git a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
index 4fff930..5c15a73 100644
--- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
+++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
@@ -339,8 +339,9 @@ e_data_cal_factory_get_type
<FILE>e-data-cal-view</FILE>
<TITLE>EDataCalView</TITLE>
e_data_cal_view_new
-e_data_cal_view_register_gdbus_object
e_data_cal_view_get_backend
+e_data_cal_view_get_connection
+e_data_cal_view_get_object_path
e_data_cal_view_get_sexp
e_data_cal_view_object_matches
e_data_cal_view_component_matches
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]