summaryrefslogtreecommitdiffstats
path: root/gdbus
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-11-26 14:27:19 +0100
committerMarcel Holtmann <marcel@holtmann.org>2008-11-26 14:27:19 +0100
commitdfd3e56a3c9755d7ffaff9c84f47f6d2f717ffab (patch)
treede6764b3cfc1f3d10f9615b169128ba29062ac98 /gdbus
parent4a7ef16ea61752ccb2ea7cd1db965b900417cfa0 (diff)
Add function for checking if a service is present
Diffstat (limited to 'gdbus')
-rw-r--r--gdbus/gdbus.h2
-rw-r--r--gdbus/mainloop.c43
2 files changed, 45 insertions, 0 deletions
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index df065613..65b4fab9 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -37,6 +37,8 @@ typedef void (* GDBusWatchFunction) (DBusConnection *connection,
DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
DBusError *error);
+gboolean g_dbus_check_service(DBusConnection *connection, const char *name);
+
gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
GDBusWatchFunction function,
void *user_data, DBusFreeFunction destroy);
diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index ba6eb0b7..d6b37189 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -275,6 +275,49 @@ DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
return conn;
}
+gboolean g_dbus_check_service(DBusConnection *connection, const char *name)
+{
+ DBusMessage *message, *reply;
+ const char **names;
+ int i, count;
+ gboolean result = FALSE;
+
+ message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "ListNames");
+ if (message == NULL) {
+ error("Can't allocate new message");
+ return FALSE;
+ }
+
+ reply = dbus_connection_send_with_reply_and_block(connection,
+ message, -1, NULL);
+
+ dbus_message_unref(message);
+
+ if (reply == NULL) {
+ error("Failed to execute method call");
+ return FALSE;
+ }
+
+ if (dbus_message_get_args(reply, NULL,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &names, &count, DBUS_TYPE_INVALID) == FALSE) {
+ error("Failed to read name list");
+ goto done;
+ }
+
+ for (i = 0; i < count; i++)
+ if (g_str_equal(names[i], name) == TRUE) {
+ result = TRUE;
+ break;
+ }
+
+done:
+ dbus_message_unref(reply);
+
+ return result;
+}
+
gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
GDBusWatchFunction function,
void *user_data, DBusFreeFunction destroy)