summaryrefslogtreecommitdiff
path: root/src/libtracker-common/tracker-dbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtracker-common/tracker-dbus.c')
-rw-r--r--src/libtracker-common/tracker-dbus.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index e8c43d202..5907d29fa 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -497,3 +497,45 @@ tracker_g_dbus_request_begin (GDBusMethodInvocation *invocation,
return request;
}
+
+gboolean
+tracker_dbus_request_name (GDBusConnection *connection,
+ const gchar *name,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ GVariant *reply;
+ gint rval;
+
+ reply = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "RequestName",
+ g_variant_new ("(su)",
+ name,
+ 0x4 /* DBUS_NAME_FLAG_DO_NOT_QUEUE */),
+ G_VARIANT_TYPE ("(u)"),
+ 0, -1, NULL, &inner_error);
+ if (inner_error) {
+ g_propagate_prefixed_error (error, inner_error,
+ "Could not acquire name:'%s'. ",
+ name);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(u)", &rval);
+ g_variant_unref (reply);
+
+ if (rval != 1 /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */) {
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_ADDRESS_IN_USE,
+ "D-Bus service name:'%s' is already taken, "
+ "perhaps the application is already running?",
+ name);
+ return FALSE;
+ }
+
+ return TRUE;
+}