summaryrefslogtreecommitdiff
path: root/gdbus/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdbus/client.c')
-rwxr-xr-x[-rw-r--r--]gdbus/client.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/gdbus/client.c b/gdbus/client.c
index eb68a0f8..48711ae8 100644..100755
--- 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;
@@ -1107,7 +1108,11 @@ static void get_managed_objects(GDBusClient *client)
{
DBusMessage *msg;
- if (!client->proxy_added && !client->proxy_removed) {
+ if (!client->connected)
+ return;
+
+ if ((!client->proxy_added && !client->proxy_removed) ||
+ !client->root_path) {
refresh_properties(client);
return;
}
@@ -1115,9 +1120,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;
@@ -1142,13 +1148,13 @@ static void service_connect(DBusConnection *conn, void *user_data)
g_dbus_client_ref(client);
+ client->connected = TRUE;
+
if (client->connect_func)
client->connect_func(conn, client->connect_data);
get_managed_objects(client);
- client->connected = TRUE;
-
g_dbus_client_unref(client);
}
@@ -1156,13 +1162,13 @@ static void service_disconnect(DBusConnection *conn, void *user_data)
{
GDBusClient *client = user_data;
+ client->connected = FALSE;
+
g_list_free_full(client->proxy_list, proxy_free);
client->proxy_list = NULL;
- if (client->disconn_func) {
+ if (client->disconn_func)
client->disconn_func(conn, client->disconn_data);
- client->connected = FALSE;
- }
}
static DBusHandlerResult message_filter(DBusConnection *connection,
@@ -1196,10 +1202,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)
return NULL;
client = g_try_new0(GDBusClient, 1);
@@ -1215,6 +1229,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);
@@ -1224,14 +1239,18 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
service_connect,
service_disconnect,
client, NULL);
+
+ if (!root_path)
+ return g_dbus_client_ref(client);
+
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,
@@ -1305,6 +1324,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);
}
@@ -1371,7 +1391,8 @@ gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
client->property_changed = property_changed;
client->user_data = user_data;
- get_managed_objects(client);
+ if (proxy_added || proxy_removed || property_changed)
+ get_managed_objects(client);
return TRUE;
}