[tracker/extractor-controller-thread-0.10: 4/4] tracker-extract: Handle errors when owning the bus name.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/extractor-controller-thread-0.10: 4/4] tracker-extract: Handle errors when owning the bus name.
- Date: Tue, 12 Apr 2011 10:23:12 +0000 (UTC)
commit 5109e57f929e5dd660f2ce0f3cbc763087b07bde
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Apr 8 13:19:05 2011 +0200
tracker-extract: Handle errors when owning the bus name.
src/tracker-extract/tracker-controller.c | 87 ++++++++++++++++++++++++------
1 files changed, 71 insertions(+), 16 deletions(-)
---
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index 91f62eb..03366bb 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -42,6 +42,7 @@ struct TrackerControllerPrivate {
GDBusConnection *connection;
GDBusNodeInfo *introspection_data;
guint registration_id;
+ guint bus_name_id;
GList *ongoing_tasks;
@@ -602,6 +603,59 @@ handle_method_call (GDBusConnection *connection,
}
}
+static void
+controller_notify_main_thread (TrackerController *controller,
+ GError *error)
+{
+ TrackerControllerPrivate *priv;
+
+ priv = controller->priv;
+
+ g_mutex_lock (priv->initialization_mutex);
+
+ priv->initialized = TRUE;
+ priv->initialization_error = error;
+
+ /* Notify about the initialization */
+ g_cond_signal (priv->initialization_cond);
+
+ g_mutex_unlock (priv->initialization_mutex);
+}
+
+static void
+bus_name_acquired_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ controller_notify_main_thread (TRACKER_CONTROLLER (user_data), NULL);
+}
+
+static void
+bus_name_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ TrackerController *controller;
+ TrackerControllerPrivate *priv;
+
+ controller = user_data;
+ priv = controller->priv;
+
+ if (!priv->initialized) {
+ GError *error;
+
+ error = g_error_new_literal (TRACKER_DBUS_ERROR, 0,
+ "Could not acquire bus name, "
+ "perhaps it's already taken?");
+ controller_notify_main_thread (controller, error);
+ } else {
+ /* We're already in control of the program
+ * lifetime, so just quit the mainloop
+ */
+ g_main_loop_quit (priv->main_loop);
+ }
+}
+
static gboolean
tracker_controller_dbus_start (TrackerController *controller,
GError **error)
@@ -635,10 +689,13 @@ tracker_controller_dbus_start (TrackerController *controller,
g_message (" Path:'" TRACKER_EXTRACT_PATH "'");
g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (controller));
- g_bus_own_name_on_connection (priv->connection,
- TRACKER_EXTRACT_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
+ priv->bus_name_id =
+ g_bus_own_name_on_connection (priv->connection,
+ TRACKER_EXTRACT_SERVICE,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ bus_name_acquired_cb,
+ bus_name_vanished_cb,
+ controller, NULL);
priv->registration_id =
g_dbus_connection_register_object (priv->connection,
@@ -671,6 +728,10 @@ tracker_controller_dbus_stop (TrackerController *controller)
priv->registration_id);
}
+ if (priv->bus_name_id != 0) {
+ g_bus_unown_name (priv->bus_name_id);
+ }
+
if (priv->introspection_data) {
g_dbus_node_info_unref (priv->introspection_data);
}
@@ -697,7 +758,7 @@ tracker_controller_thread_func (gpointer user_data)
{
TrackerController *controller;
TrackerControllerPrivate *priv;
- gboolean success;
+ GError *error = NULL;
g_message ("Controller thread '%p' created, dispatching...", g_thread_self ());
@@ -707,18 +768,12 @@ tracker_controller_thread_func (gpointer user_data)
reset_shutdown_timeout (controller);
- success = tracker_controller_dbus_start (controller, &priv->initialization_error);
- priv->initialized = TRUE;
-
- /* Notify about the initialization */
- g_mutex_lock (priv->initialization_mutex);
- g_cond_signal (priv->initialization_cond);
- g_mutex_unlock (priv->initialization_mutex);
-
- if (!success) {
- /* Return here, the main thread will
- * be notified about the error and exit
+ if (!tracker_controller_dbus_start (controller, &error)) {
+ /* Error has been filled in, so we return
+ * in this thread. The main thread will be
+ * notified about the error and exit.
*/
+ controller_notify_main_thread (controller, error);
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]