[tracker/miner-fs-initable-iface: 2/8] libtracker-miner: Make TrackerMiner object initable
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-initable-iface: 2/8] libtracker-miner: Make TrackerMiner object initable
- Date: Tue, 1 Feb 2011 11:37:46 +0000 (UTC)
commit d98e8eb3f011441cbfcbad704c7ecb6871557814
Author: Aleksander Morgado <aleksander lanedo com>
Date: Mon Jan 31 20:22:56 2011 +0100
libtracker-miner: Make TrackerMiner object initable
src/libtracker-miner/tracker-miner-object.c | 295 +++++++++++++++------------
src/libtracker-miner/tracker-miner-object.h | 2 +
2 files changed, 170 insertions(+), 127 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 4245e34..2ea1bdf 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -134,21 +134,56 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-static void miner_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void miner_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void miner_finalize (GObject *object);
-static void miner_constructed (GObject *object);
-static void pause_data_destroy (gpointer data);
-static PauseData *pause_data_new (const gchar *application,
- const gchar *reason);
-
-G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
+static void miner_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void miner_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void miner_finalize (GObject *object);
+static void miner_initable_iface_init (GInitableIface *iface);
+static gboolean miner_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error);
+static void pause_data_destroy (gpointer data);
+static PauseData *pause_data_new (const gchar *application,
+ const gchar *reason);
+static void handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
+static GVariant *handle_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data);
+static gboolean handle_set_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GVariant *value,
+ GError **error,
+ gpointer user_data);
+static void on_tracker_store_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data);
+static void on_tracker_store_disappeared (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data);
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TrackerMiner, tracker_miner, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ miner_initable_iface_init));
static void
tracker_miner_class_init (TrackerMinerClass *klass)
@@ -158,7 +193,6 @@ tracker_miner_class_init (TrackerMinerClass *klass)
object_class->set_property = miner_set_property;
object_class->get_property = miner_get_property;
object_class->finalize = miner_finalize;
- object_class->constructed = miner_constructed;
/**
* TrackerMiner::started:
@@ -296,21 +330,129 @@ tracker_miner_class_init (TrackerMinerClass *klass)
}
static void
-tracker_miner_init (TrackerMiner *miner)
+miner_initable_iface_init (GInitableIface *iface)
{
- TrackerMinerPrivate *priv;
- GError *error = NULL;
+ iface->init = miner_initable_init;
+}
- miner->private = priv = TRACKER_MINER_GET_PRIVATE (miner);
+static gboolean
+miner_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ TrackerMiner *miner = TRACKER_MINER (initable);
+ GError *inner_error = NULL;
+ GVariant *reply;
+ guint32 rval;
+ GDBusInterfaceVTable interface_vtable = {
+ handle_method_call,
+ handle_get_property,
+ handle_set_property
+ };
+
+ /* Try to get SPARQL connection... */
+ miner->private->connection = tracker_sparql_connection_get (NULL, error);
+ if (!miner->private->connection) {
+ return FALSE;
+ }
+
+ /* Try to get DBus connection... */
+ miner->private->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (!miner->private->d_connection) {
+ return FALSE;
+ }
+
+ /* Setup introspection data */
+ miner->private->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+
+ /* Check miner has a proper name */
+ if (!miner->private->name) {
+ g_set_error (error,
+ TRACKER_MINER_ERROR,
+ 0,
+ "Miner '%s' should have been given a name, bailing out",
+ G_OBJECT_TYPE_NAME (miner));
+ return FALSE;
+ }
+
+ /* Setup full name */
+ miner->private->full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX,
+ miner->private->name,
+ NULL);
+
+ /* Register the service name for the miner */
+ miner->private->full_path = g_strconcat (TRACKER_MINER_DBUS_PATH_PREFIX,
+ miner->private->name,
+ NULL);
+
+ g_message ("Registering D-Bus object...");
+ g_message (" Path:'%s'", miner->private->full_path);
+ g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (miner));
+
+ miner->private->registration_id =
+ g_dbus_connection_register_object (miner->private->d_connection,
+ miner->private->full_path,
+ miner->private->introspection_data->interfaces[0],
+ &interface_vtable,
+ miner,
+ NULL,
+ &inner_error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ g_prefix_error (error,
+ "Could not register the D-Bus object '%s'. ",
+ miner->private->full_path);
+ return FALSE;
+ }
- priv->connection = tracker_sparql_connection_get (NULL, &error);
+ reply = g_dbus_connection_call_sync (miner->private->d_connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "RequestName",
+ g_variant_new ("(su)",
+ miner->private->full_name,
+ 0x4 /* DBUS_NAME_FLAG_DO_NOT_QUEUE */),
+ G_VARIANT_TYPE ("(u)"),
+ 0, -1, NULL, &inner_error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ g_prefix_error (error,
+ "Could not acquire name:'%s'. ",
+ miner->private->full_name);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(u)", &rval);
+ g_variant_unref (reply);
- /* If we couldn't get a proper SPARQL connection, log error and abort */
- if (!priv->connection) {
- g_error ("Couldn't get a proper SPARQL connection (%s), exiting...",
- error ? error->message : "Unknown error");
+ if (rval != 1 /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */) {
+ g_set_error (error,
+ TRACKER_MINER_ERROR,
+ 0,
+ "D-Bus service name:'%s' is already taken, "
+ "perhaps the application is already running?",
+ miner->private->full_name);
+ return FALSE;
}
+ miner->private->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+ TRACKER_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_tracker_store_appeared,
+ on_tracker_store_disappeared,
+ miner,
+ NULL);
+
+ return TRUE;
+}
+
+static void
+tracker_miner_init (TrackerMiner *miner)
+{
+ TrackerMinerPrivate *priv;
+ miner->private = priv = TRACKER_MINER_GET_PRIVATE (miner);
+
priv->pauses = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
@@ -375,7 +517,7 @@ miner_set_property (GObject *object,
* we set it last.
*
* Only notify 1% changes
- */
+ */
if (new_progress == miner->private->progress) {
/* Same, do nothing */
break;
@@ -980,104 +1122,3 @@ on_tracker_store_disappeared (GDBusConnection *connection,
}
}
}
-
-static void
-miner_constructed (GObject *object)
-{
- TrackerMiner *miner;
- gchar *name, *full_path, *full_name;
- GVariant *reply;
- guint32 rval;
- GError *error = NULL;
- GDBusInterfaceVTable interface_vtable = {
- handle_method_call,
- handle_get_property,
- handle_set_property
- };
-
- miner = TRACKER_MINER (object);
- miner->private->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!miner->private->d_connection) {
- g_critical ("Could not connect to the D-Bus session bus, %s",
- error ? error->message : "no error given.");
- g_clear_error (&error);
- return;
- }
-
- miner->private->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
-
- g_object_get (miner, "name", &name, NULL);
-
- if (!name) {
- g_critical ("Miner '%s' should have been given a name, bailing out",
- G_OBJECT_TYPE_NAME (miner));
- g_assert_not_reached ();
- }
-
- full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX, name, NULL);
- miner->private->full_name = full_name;
-
- /* Register the service name for the miner */
- full_path = g_strconcat (TRACKER_MINER_DBUS_PATH_PREFIX, name, NULL);
-
- g_message ("Registering D-Bus object...");
- g_message (" Path:'%s'", full_path);
- g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (miner));
-
- miner->private->registration_id =
- g_dbus_connection_register_object (miner->private->d_connection,
- full_path,
- miner->private->introspection_data->interfaces[0],
- &interface_vtable,
- miner,
- NULL,
- &error);
-
- if (error) {
- g_critical ("Could not register the D-Bus object %s, %s",
- full_path,
- error ? error->message : "no error given.");
- g_clear_error (&error);
- return;
- }
-
- reply = g_dbus_connection_call_sync (miner->private->d_connection,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "RequestName",
- g_variant_new ("(su)", full_name, 0x4 /* DBUS_NAME_FLAG_DO_NOT_QUEUE */),
- G_VARIANT_TYPE ("(u)"),
- 0, -1, NULL, &error);
-
- if (error) {
- g_critical ("Could not acquire name:'%s', %s",
- full_name,
- error->message);
- g_clear_error (&error);
- return;
- }
-
- g_variant_get (reply, "(u)", &rval);
- g_variant_unref (reply);
-
- if (rval != 1 /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */) {
- g_critical ("D-Bus service name:'%s' is already taken, "
- "perhaps the application is already running?",
- full_name);
- return;
- }
-
- g_free (name);
-
- miner->private->full_path = full_path;
-
- miner->private->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
- TRACKER_SERVICE,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- on_tracker_store_appeared,
- on_tracker_store_disappeared,
- miner,
- NULL);
-}
diff --git a/src/libtracker-miner/tracker-miner-object.h b/src/libtracker-miner/tracker-miner-object.h
index 08cc57f..e90df05 100644
--- a/src/libtracker-miner/tracker-miner-object.h
+++ b/src/libtracker-miner/tracker-miner-object.h
@@ -38,6 +38,8 @@ G_BEGIN_DECLS
#define TRACKER_IS_MINER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_MINER))
#define TRACKER_MINER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER, TrackerMinerClass))
+#define TRACKER_MINER_GET_INITABLE_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), G_TYPE_INITABLE, GInitable))
+
#define TRACKER_MINER_ERROR_DOMAIN "TrackerMiner"
#define TRACKER_MINER_ERROR tracker_miner_error_quark()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]