[tracker] tracker-writeback: Make dispatcher GInitable
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-writeback: Make dispatcher GInitable
- Date: Tue, 1 Mar 2011 11:42:13 +0000 (UTC)
commit b780ce145fa33a0a24683e2882e419dc9967169b
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Mar 1 12:27:03 2011 +0100
tracker-writeback: Make dispatcher GInitable
.../tracker-writeback-dispatcher.c | 178 ++++++++++++--------
.../tracker-writeback-dispatcher.h | 13 +-
2 files changed, 112 insertions(+), 79 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 916ebd9..c57a496 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -59,50 +59,21 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-
-static void tracker_writeback_dispatcher_finalize (GObject *object);
-static void tracker_writeback_dispatcher_constructed (GObject *object);
-
-static void tracker_writeback_dispatcher_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void tracker_writeback_dispatcher_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-
-G_DEFINE_TYPE (TrackerWritebackDispatcher, tracker_writeback_dispatcher, G_TYPE_OBJECT)
-
-static void
-tracker_writeback_dispatcher_class_init (TrackerWritebackDispatcherClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = tracker_writeback_dispatcher_finalize;
- object_class->constructed = tracker_writeback_dispatcher_constructed;
- object_class->get_property = tracker_writeback_dispatcher_get_property;
- object_class->set_property = tracker_writeback_dispatcher_set_property;
-
- g_object_class_install_property (object_class,
- PROP_MAIN_CONTEXT,
- g_param_spec_pointer ("context",
- "Main context",
- "Main context to run the DBus service on",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- signals[WRITEBACK] =
- g_signal_new ("writeback",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (TrackerWritebackDispatcherClass, writeback),
- NULL, NULL,
- tracker_marshal_VOID__INT_BOXED,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_ARRAY);
-
- g_type_class_add_private (object_class, sizeof (TrackerWritebackDispatcherPrivate));
-}
+static void tracker_writeback_dispatcher_finalize (GObject *object);
+
+static void tracker_writeback_dispatcher_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void tracker_writeback_dispatcher_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void tracker_writeback_dispatcher_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (TrackerWritebackDispatcher, tracker_writeback_dispatcher, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ tracker_writeback_dispatcher_initable_iface_init));
static void
handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
@@ -187,8 +158,9 @@ message_filter (DBusConnection *connection,
}
static DBusConnection *
-setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
- GMainContext *context)
+setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
+ GMainContext *context,
+ GError **n_error)
{
DBusConnection *connection;
DBusError error;
@@ -200,8 +172,10 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
connection = dbus_bus_get_private (DBUS_BUS_SESSION, &error);
if (dbus_error_is_set (&error)) {
- g_critical ("Could not connect to the D-Bus session bus, %s",
- error.message);
+ g_set_error_literal (n_error,
+ TRACKER_DBUS_ERROR,
+ TRACKER_DBUS_ERROR_ASSERTION_FAILED,
+ error.message);
dbus_error_free (&error);
return NULL;
}
@@ -215,8 +189,10 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
&error);
if (dbus_error_is_set (&error)) {
- g_critical ("Could not acquire name:'%s', %s",
- TRACKER_WRITEBACK_DBUS_NAME, error.message);
+ g_set_error_literal (n_error,
+ TRACKER_DBUS_ERROR,
+ TRACKER_DBUS_ERROR_ASSERTION_FAILED,
+ error.message);
dbus_error_free (&error);
dbus_connection_close (connection);
dbus_connection_unref (connection);
@@ -225,9 +201,12 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- g_critical ("D-Bus service name:'%s' is already taken, "
- "perhaps the application is already running?",
- TRACKER_WRITEBACK_DBUS_NAME);
+ g_set_error_literal (n_error,
+ TRACKER_DBUS_ERROR,
+ TRACKER_DBUS_ERROR_ASSERTION_FAILED,
+ "D-Bus service name:'"TRACKER_WRITEBACK_DBUS_NAME"' is already taken, "
+ "perhaps the application is already running?");
+
dbus_connection_close (connection);
dbus_connection_unref (connection);
@@ -236,7 +215,11 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
/* Add message filter function */
if (!dbus_connection_add_filter (connection, message_filter, dispatcher, NULL)) {
- g_critical ("Could not add message filter");
+ g_set_error_literal (n_error,
+ TRACKER_DBUS_ERROR,
+ TRACKER_DBUS_ERROR_ASSERTION_FAILED,
+ "Could not add message filter");
+
dbus_connection_close (connection);
dbus_connection_unref (connection);
@@ -247,7 +230,10 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
dbus_bus_add_match (connection, DBUS_MATCH_STR, &error);
if (dbus_error_is_set (&error)) {
- g_critical ("Could not add match rules, %s", error.message);
+ g_set_error_literal (n_error,
+ TRACKER_DBUS_ERROR,
+ TRACKER_DBUS_ERROR_ASSERTION_FAILED,
+ error.message);
dbus_error_free (&error);
dbus_connection_close (connection);
dbus_connection_unref (connection);
@@ -261,6 +247,66 @@ setup_dbus_connection (TrackerWritebackDispatcher *dispatcher,
return connection;
}
+static gboolean
+tracker_writeback_dispatcher_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ TrackerWritebackDispatcherPrivate *priv;
+ TrackerWritebackDispatcher *dispatcher;
+ DBusConnection *connection;
+ GError *internal_error = NULL;
+
+ dispatcher = TRACKER_WRITEBACK_DISPATCHER (initable);
+ priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (dispatcher);
+
+ connection = setup_dbus_connection (dispatcher, priv->context,
+ &internal_error);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
+ } else {
+ priv->connection = connection;
+ }
+
+ return TRUE;
+}
+
+static void
+tracker_writeback_dispatcher_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = tracker_writeback_dispatcher_initable_init;
+}
+
+static void
+tracker_writeback_dispatcher_class_init (TrackerWritebackDispatcherClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_writeback_dispatcher_finalize;
+ object_class->get_property = tracker_writeback_dispatcher_get_property;
+ object_class->set_property = tracker_writeback_dispatcher_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_MAIN_CONTEXT,
+ g_param_spec_pointer ("context",
+ "Main context",
+ "Main context to run the DBus service on",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ signals[WRITEBACK] =
+ g_signal_new ("writeback",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerWritebackDispatcherClass, writeback),
+ NULL, NULL,
+ tracker_marshal_VOID__INT_BOXED,
+ G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_ARRAY);
+
+ g_type_class_add_private (object_class, sizeof (TrackerWritebackDispatcherPrivate));
+}
+
static void
tracker_writeback_dispatcher_init (TrackerWritebackDispatcher *dispatcher)
{
@@ -288,21 +334,6 @@ tracker_writeback_dispatcher_finalize (GObject *object)
G_OBJECT_CLASS (tracker_writeback_dispatcher_parent_class)->finalize (object);
}
-static void
-tracker_writeback_dispatcher_constructed (GObject *object)
-{
- TrackerWritebackDispatcherPrivate *priv;
- TrackerWritebackDispatcher *dispatcher;
- DBusConnection *connection;
-
- dispatcher = TRACKER_WRITEBACK_DISPATCHER (object);
- priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (dispatcher);
-
- connection = setup_dbus_connection (dispatcher, priv->context);
- g_assert (connection != NULL);
-
- priv->connection = connection;
-}
static void
tracker_writeback_dispatcher_get_property (GObject *object,
@@ -363,7 +394,8 @@ tracker_writeback_dispatcher_set_property (GObject *object,
TrackerWritebackDispatcher *
tracker_writeback_dispatcher_new (GMainContext *context)
{
- return g_object_new (TRACKER_TYPE_WRITEBACK_DISPATCHER,
- "context", context,
- NULL);
+ return g_initable_new (TRACKER_TYPE_WRITEBACK_DISPATCHER,
+ NULL, NULL,
+ "context", context,
+ NULL);
}
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.h b/src/tracker-writeback/tracker-writeback-dispatcher.h
index f98a948..633e3b2 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.h
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.h
@@ -26,12 +26,13 @@
G_BEGIN_DECLS
-#define TRACKER_TYPE_WRITEBACK_DISPATCHER (tracker_writeback_dispatcher_get_type())
-#define TRACKER_WRITEBACK_DISPATCHER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcher))
-#define TRACKER_WRITEBACK_DISPATCHER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
-#define TRACKER_IS_WRITEBACK_DISPATCHER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER))
-#define TRACKER_IS_WRITEBACK_DISPATCHER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_WRITEBACK_DISPATCHER))
-#define TRACKER_WRITEBACK_DISPATCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
+#define TRACKER_TYPE_WRITEBACK_DISPATCHER (tracker_writeback_dispatcher_get_type())
+#define TRACKER_WRITEBACK_DISPATCHER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcher))
+#define TRACKER_WRITEBACK_DISPATCHER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
+#define TRACKER_IS_WRITEBACK_DISPATCHER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER))
+#define TRACKER_IS_WRITEBACK_DISPATCHER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_WRITEBACK_DISPATCHER))
+#define TRACKER_WRITEBACK_DISPATCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
+#define TRACKER_WRITEBACK_DISPATCHER_GET_INITABLE_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), G_TYPE_INITABLE, GInitable))
typedef struct TrackerWritebackDispatcher TrackerWritebackDispatcher;
typedef struct TrackerWritebackDispatcherClass TrackerWritebackDispatcherClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]