[tracker] tracker-extract: Handle errors when requesting bus names
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-extract: Handle errors when requesting bus names
- Date: Tue, 25 Jan 2011 13:00:20 +0000 (UTC)
commit 89a5bb025db0ff9b3c50c3a84fd4dce3ebeedc17
Author: Jürg Billeter <j bitron ch>
Date: Tue Jan 25 13:20:03 2011 +0100
tracker-extract: Handle errors when requesting bus names
src/tracker-extract/tracker-extract.c | 39 ++++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 4a14ec7..405f69e 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -81,7 +81,6 @@ typedef struct {
GDBusConnection *d_connection;
GDBusNodeInfo *introspection_data;
guint registration_id;
- guint own_id;
} TrackerExtractPrivate;
typedef struct {
@@ -959,6 +958,8 @@ void
tracker_extract_dbus_start (TrackerExtract *extract)
{
TrackerExtractPrivate *priv;
+ GVariant *reply;
+ guint32 rval;
GError *error = NULL;
GDBusInterfaceVTable interface_vtable = {
handle_method_call,
@@ -979,11 +980,6 @@ tracker_extract_dbus_start (TrackerExtract *extract)
priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
- priv->own_id = g_bus_own_name_on_connection (priv->d_connection,
- TRACKER_EXTRACT_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
-
g_message ("Registering D-Bus object...");
g_message (" Path:'" TRACKER_EXTRACT_PATH "'");
g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (extract));
@@ -1003,6 +999,33 @@ tracker_extract_dbus_start (TrackerExtract *extract)
g_clear_error (&error);
return;
}
+
+ reply = g_dbus_connection_call_sync (priv->d_connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "RequestName",
+ g_variant_new ("(su)", TRACKER_EXTRACT_SERVICE, 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",
+ TRACKER_EXTRACT_SERVICE,
+ 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?",
+ TRACKER_EXTRACT_SERVICE);
+ return;
+ }
}
void
@@ -1012,10 +1035,6 @@ tracker_extract_dbus_stop (TrackerExtract *extract)
priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
- if (priv->own_id != 0) {
- g_bus_unown_name (priv->own_id);
- }
-
if (priv->registration_id != 0) {
g_dbus_connection_unregister_object (priv->d_connection,
priv->registration_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]