[tracker] libtracker-miner: Handle errors when requesting bus names
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-miner: Handle errors when requesting bus names
- Date: Tue, 25 Jan 2011 13:00:05 +0000 (UTC)
commit e910af26a0b77b25c971a1510bbf86b79543e485
Author: Jürg Billeter <j bitron ch>
Date: Tue Jan 25 12:37:27 2011 +0100
libtracker-miner: Handle errors when requesting bus names
src/libtracker-miner/tracker-miner-object.c | 39 ++++++++++++++++++++-------
src/libtracker-miner/tracker-miner-web.c | 39 ++++++++++++++++++++-------
2 files changed, 58 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 348d22c..4245e34 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -105,7 +105,6 @@ struct _TrackerMinerPrivate {
GDBusNodeInfo *introspection_data;
guint watch_name_id;
guint registration_id;
- guint own_id;
gchar *full_name;
gchar *full_path;
};
@@ -683,10 +682,6 @@ miner_finalize (GObject *object)
g_bus_unwatch_name (miner->private->watch_name_id);
}
- if (miner->private->own_id != 0) {
- g_bus_unown_name (miner->private->own_id);
- }
-
if (miner->private->registration_id != 0) {
g_dbus_connection_unregister_object (miner->private->d_connection,
miner->private->registration_id);
@@ -991,6 +986,8 @@ 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,
@@ -1019,11 +1016,6 @@ miner_constructed (GObject *object)
}
full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX, name, NULL);
-
- miner->private->own_id = g_bus_own_name_on_connection (miner->private->d_connection,
- full_name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
miner->private->full_name = full_name;
/* Register the service name for the miner */
@@ -1050,6 +1042,33 @@ miner_constructed (GObject *object)
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;
diff --git a/src/libtracker-miner/tracker-miner-web.c b/src/libtracker-miner/tracker-miner-web.c
index 70fb9fa..6c3d29e 100644
--- a/src/libtracker-miner/tracker-miner-web.c
+++ b/src/libtracker-miner/tracker-miner-web.c
@@ -58,7 +58,6 @@ struct TrackerMinerWebPrivate {
GDBusConnection *d_connection;
GDBusNodeInfo *introspection_data;
guint registration_id;
- guint own_id;
gchar *full_name;
gchar *full_path;
};
@@ -155,10 +154,6 @@ miner_web_finalize (GObject *object)
priv = TRACKER_MINER_WEB_GET_PRIVATE (object);
- 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);
@@ -399,6 +394,8 @@ miner_web_constructed (GObject *miner)
{
TrackerMinerWebPrivate *priv;
gchar *name, *full_path, *full_name;
+ GVariant *reply;
+ guint32 rval;
GError *error = NULL;
GDBusInterfaceVTable interface_vtable = {
handle_method_call,
@@ -428,11 +425,6 @@ miner_web_constructed (GObject *miner)
}
full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX, name, NULL);
-
- priv->own_id = g_bus_own_name_on_connection (priv->d_connection,
- full_name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
priv->full_name = full_name;
/* Register the service name for the miner */
@@ -459,6 +451,33 @@ miner_web_constructed (GObject *miner)
return;
}
+ reply = g_dbus_connection_call_sync (priv->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);
priv->full_path = full_path;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]