diff options
author | Arman Uguray <armansito@chromium.org> | 2015-02-27 00:16:25 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-02-27 14:40:43 +0200 |
commit | d8fdaf7544e909265e592aa92be3c91797a375c2 (patch) | |
tree | f1e2fc6577cf15f98deed11612268e5fb24cd5d6 /gdbus/client.c | |
parent | 16f61b2721d683643f0dfeb1dd2e861780e80994 (diff) | |
download | bluez-d8fdaf7544e909265e592aa92be3c91797a375c2.tar.gz |
gdbus/client: Allow specifying ObjectManager path
GDBusClient currently hard-codes "/" as the remote ObjectManager path.
This is generally incorrect, as an application can choose to expose an
ObjectManager at any well-known path. This patch fixes this by allowing
the user to pass in the ObjectManager path by introducing a new
conctructor "g_dbus_client_new_full".
Diffstat (limited to 'gdbus/client.c')
-rw-r--r-- | gdbus/client.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/gdbus/client.c b/gdbus/client.c index cd5c7678f..fe0c0dbf0 100644 --- a/gdbus/client.c +++ b/gdbus/client.c @@ -42,6 +42,7 @@ struct GDBusClient { DBusConnection *dbus_conn; char *service_name; char *base_path; + char *root_path; guint watch; guint added_watch; guint removed_watch; @@ -1118,9 +1119,10 @@ static void get_managed_objects(GDBusClient *client) if (client->get_objects_call != NULL) return; - msg = dbus_message_new_method_call(client->service_name, "/", - DBUS_INTERFACE_DBUS ".ObjectManager", - "GetManagedObjects"); + msg = dbus_message_new_method_call(client->service_name, + client->root_path, + DBUS_INTERFACE_OBJECT_MANAGER, + "GetManagedObjects"); if (msg == NULL) return; @@ -1199,10 +1201,18 @@ static DBusHandlerResult message_filter(DBusConnection *connection, GDBusClient *g_dbus_client_new(DBusConnection *connection, const char *service, const char *path) { + return g_dbus_client_new_full(connection, service, path, "/"); +} + +GDBusClient *g_dbus_client_new_full(DBusConnection *connection, + const char *service, + const char *path, + const char *root_path) +{ GDBusClient *client; unsigned int i; - if (connection == NULL) + if (!connection || !service || !root_path) return NULL; client = g_try_new0(GDBusClient, 1); @@ -1218,6 +1228,7 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, client->dbus_conn = dbus_connection_ref(connection); client->service_name = g_strdup(service); client->base_path = g_strdup(path); + client->root_path = g_strdup(root_path); client->connected = FALSE; client->match_rules = g_ptr_array_sized_new(1); @@ -1228,13 +1239,13 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, service_disconnect, client, NULL); client->added_watch = g_dbus_add_signal_watch(connection, service, - "/", + client->root_path, DBUS_INTERFACE_OBJECT_MANAGER, "InterfacesAdded", interfaces_added, client, NULL); client->removed_watch = g_dbus_add_signal_watch(connection, service, - "/", + client->root_path, DBUS_INTERFACE_OBJECT_MANAGER, "InterfacesRemoved", interfaces_removed, @@ -1308,6 +1319,7 @@ void g_dbus_client_unref(GDBusClient *client) g_free(client->service_name); g_free(client->base_path); + g_free(client->root_path); g_free(client); } |