All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dbus-client: Introduce l_dbus_client_add_proxy
@ 2019-06-14 18:12 Tim Kourt
  0 siblings, 0 replies; only message in thread
From: Tim Kourt @ 2019-06-14 18:12 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 3652 bytes --]

Not all DBus services expose their objects trough ObjectManager,
therefore the usage of such objects through the current client
proxy API is impossible. This patch allows to manually add
a proxy object for the well-known DBus object.
---
 ell/dbus-client.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 ell/dbus-client.h |  3 +++
 2 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/ell/dbus-client.c b/ell/dbus-client.c
index d2eb70f..852cf3b 100644
--- a/ell/dbus-client.c
+++ b/ell/dbus-client.c
@@ -37,6 +37,7 @@ struct l_dbus_client {
 	unsigned int removed_watch;
 	char *service;
 	uint32_t objects_call;
+	uint32_t add_proxy_call;
 
 	l_dbus_watch_func_t connect_cb;
 	void *connect_cb_data;
@@ -647,8 +648,11 @@ LIB_EXPORT void l_dbus_client_destroy(struct l_dbus_client *client)
 		client->proxy_cb_data_destroy(client->proxy_cb_data);
 
 	if (client->objects_call)
-		l_dbus_cancel(client->dbus, client->objects_call)
-;
+		l_dbus_cancel(client->dbus, client->objects_call);
+
+	if (client->add_proxy_call)
+		l_dbus_cancel(client->dbus, client->add_proxy_call);
+
 	l_queue_destroy(client->proxies,
 				(l_queue_destroy_func_t)dbus_proxy_destroy);
 
@@ -730,3 +734,73 @@ LIB_EXPORT bool l_dbus_client_set_proxy_handlers(struct l_dbus_client *client,
 
 	return true;
 }
+
+struct add_proxy_data {
+	struct l_dbus_client *client;
+	char *path;
+	char *interafce;
+};
+
+static void add_proxy_data_destroy(void *user_data)
+{
+	struct add_proxy_data *data = user_data;
+
+	l_free(data->path);
+	l_free(data->interafce);
+	l_free(data);
+}
+
+static void add_proxy_reply(struct l_dbus_message *message, void *user_data)
+{
+	struct add_proxy_data *data = user_data;
+	struct l_dbus_message_iter properties;
+
+	data->client->add_proxy_call = 0;
+
+	if (l_dbus_message_is_error(message))
+		return;
+
+	l_dbus_message_get_arguments(message, "a{sv}", &properties);
+
+	parse_interface(data->client, data->path, data->interafce, &properties);
+}
+
+static void add_proxy_setup(struct l_dbus_message *message, void *user_data)
+{
+	struct add_proxy_data *data = user_data;
+
+	l_dbus_message_set_arguments(message, "s", data->interafce);
+}
+
+LIB_EXPORT bool l_dbus_client_add_proxy(struct l_dbus_client *client,
+							const char *path,
+							const char *interface)
+{
+	struct add_proxy_data *data;
+
+	if (unlikely(!client || !path || !interface))
+		return false;
+
+	if (find_proxy(client, path, interface))
+		return false;
+
+	data = l_new(struct add_proxy_data, 1);
+	data->client = client;
+	data->path = l_strdup(path);
+	data->interafce = l_strdup(interface);
+
+	client->add_proxy_call =
+			l_dbus_method_call(client->dbus, client->service, path,
+						L_DBUS_INTERFACE_PROPERTIES,
+						"GetAll", add_proxy_setup,
+						add_proxy_reply, data,
+						add_proxy_data_destroy);
+
+	if (!client->add_proxy_call) {
+		add_proxy_data_destroy(data);
+
+		return false;
+	}
+
+	return true;
+}
diff --git a/ell/dbus-client.h b/ell/dbus-client.h
index 699d824..939a6bf 100644
--- a/ell/dbus-client.h
+++ b/ell/dbus-client.h
@@ -72,6 +72,9 @@ bool l_dbus_client_set_proxy_handlers(struct l_dbus_client *client,
 			l_dbus_client_property_function_t property_changed,
 			void *user_data, l_dbus_destroy_func_t destroy);
 
+bool l_dbus_client_add_proxy(struct l_dbus_client *client, const char *path,
+							const char *interface);
+
 const char *l_dbus_proxy_get_path(struct l_dbus_proxy *proxy);
 
 const char *l_dbus_proxy_get_interface(struct l_dbus_proxy *proxy);
-- 
2.13.6


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-14 18:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-14 18:12 [PATCH] dbus-client: Introduce l_dbus_client_add_proxy Tim Kourt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.