All of lore.kernel.org
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@codecoup.pl>
To: ell@lists.01.org
Subject: Re: [PATCH 3/6] dbus: Add support for proxy interface
Date: Tue, 05 Dec 2017 18:05:10 +0100	[thread overview]
Message-ID: <28539502.z0LgiceJkP@ix> (raw)
In-Reply-To: <d62a628a-76f9-6e13-1656-993161d17b73@gmail.com>

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

Hi Denis,

On Monday, 4 December 2017 19:40:29 CET Denis Kenzior wrote:
> Hi Szymon,
> 
> <snip>
> 
> > +static struct l_dbus_proxy *l_dbus_proxy_new(struct l_dbus_client
> > *client,
> > +					const char *path, const char *interface)
> 
> I would just call it dbus_proxy_new since it is not exported.  Same with
> l_dbus_proxy_destroy

Done.

> 
> > +{
> > +	struct l_dbus_proxy *proxy;
> > +
> > +	proxy = l_new(struct l_dbus_proxy, 1);
> 
> can condense these to a single line...

OK.

> 
> > +
> > +	proxy->properties_watch = l_dbus_add_signal_watch(client->dbus,
> > +						client->service, path,
> > +						L_DBUS_INTERFACE_PROPERTIES,
> > +						"PropertiesChanged",
> > +						L_DBUS_MATCH_ARGUMENT(0),
> > +						interface, L_DBUS_MATCH_NONE,
> > +						properties_changed_callback,
> > +						proxy);
> > +	if (!proxy->properties_watch) {
> > +		l_free(proxy);
> > +		return NULL;
> > +	}
> > +
> > +	proxy->client = client;
> > +	proxy->interface = l_strdup(interface);
> > +	proxy->path = l_strdup(path);
> > +	proxy->properties = l_queue_new();
> > +
> > +	l_queue_push_tail(client->proxies, proxy);
> > +
> > +	return proxy;
> > +}
> > +
> > +static bool is_ignorable(const char *interface)
> > +{
> > +	static const struct {
> > +		const char *interface;
> > +	} interfaces_to_ignore[] = {
> > +		{ L_DBUS_INTERFACE_OBJECT_MANAGER },
> > +		{ L_DBUS_INTERFACE_INTROSPECTABLE },
> > +		{ L_DBUS_INTERFACE_PROPERTIES },
> > +	};
> > +	size_t i;
> > +
> > +	for (i = 0; i < L_ARRAY_SIZE(interfaces_to_ignore); i++)
> > +		if (!strcmp(interfaces_to_ignore[i].interface, interface))
> > +			return true;
> > +
> > +	return false;
> > +}
> > +
> > +static struct l_dbus_proxy *find_proxy(struct l_dbus_client *client,
> > +					const char *path, const char *interface)
> > +{
> > +	const struct l_queue_entry *entry;
> > +
> > +	for (entry = l_queue_get_entries(client->proxies); entry;
> > +							entry = entry->next) {
> > +		struct l_dbus_proxy *proxy = entry->data;
> > +
> > +		if (!strcmp(proxy->interface, interface) &&
> > +						!strcmp(proxy->path, path))
> > +			return proxy;
> > +	}
> > +
> > +	return NULL;
> > +}
> > +
> > +static void parse_interface(struct l_dbus_client *client, const char
> > *path, +					const char *interface,
> > +					struct l_dbus_message_iter *properties)
> > +{
> > +	struct l_dbus_proxy *proxy;
> > +
> > +	if (is_ignorable(interface))
> > +		return;
> > +
> > +	proxy = find_proxy(client, path, interface);
> > +	if (!proxy) {
> > +		proxy = l_dbus_proxy_new(client, path, interface);
> > +	}
> 
> No need for {}

Fixed.

> 
> > +
> > +	if (!proxy)
> > +		return;
> > +
> > +	proxy_update_properties(proxy, properties);
> > +
> > +	if (!proxy->ready) {
> > +		proxy->ready = true;
> > +
> > +		if (client->proxy_added_cb)
> > +			client->proxy_added_cb(proxy, client->proxy_cb_data);
> > +	}
> > +}
> > +
> 
> <snip>
> 
> > +
> > +static void service_appeared_callback(struct l_dbus *dbus, void
> > *user_data) +{
> > +	struct l_dbus_client *client = user_data;
> > +
> > +	/* TODO should we allow to set different root? */
> > +	client->objects_call = l_dbus_method_call(dbus, client->service, "/",
> > +						L_DBUS_INTERFACE_OBJECT_MANAGER,
> > +						"GetManagedObjects", NULL,
> > +						get_managed_objects_reply,
> > +						client, NULL);
> > +
> > +	if (client->connect_cb)
> > +		client->connect_cb(client->dbus, client->connect_cb_data);
> > +}
> > +
> > +static void service_disappeared_callback(struct l_dbus *dbus, void
> > *user_data) +{
> > +	struct l_dbus_client *client = user_data;
> > +
> > +	if (client->disconnect_cb)
> > +		client->disconnect_cb(client->dbus, client->disconnect_cb_data);
> > +
> > +	l_queue_clear(client->proxies,
> > +				(l_queue_destroy_func_t)l_dbus_proxy_destroy);
> > +}
> > +
> > +LIB_EXPORT struct l_dbus_client *l_dbus_client_new(struct l_dbus *dbus,
> > +					const char *service, const char *path)
> > +{
> > +	struct l_dbus_client *client;
> > +
> > +	client = l_new(struct l_dbus_client, 1);
> > +
> 
> Can condense these to a single line

OK.

> 
> > +	client->dbus = dbus;
> > +
> > +	client->watch = l_dbus_add_service_watch(dbus, service,
> > +						service_appeared_callback,
> > +						service_disappeared_callback,
> > +						client, NULL);
> > +
> > +	if (!client->watch) {
> > +		l_free(client);
> > +		return NULL;
> > +	}
> > +
> > +	client->service = l_strdup(service);
> > +	client->path = l_strdup(path);
> 
> What is the purpose of this member actually?  We're not using it for the
> ObjectManager root, nor are we using it for anything else.  I also don't
> get its purpose in gdbus either.  Can we simply drop it?

Yeap, I think I initially had getter for it that turned out to be useless but 
forgot to remove member from client. Fixed.

> 
> > +	client->proxies = l_queue_new();
> > +
> > +	return client;
> > +}
> > +
> > +LIB_EXPORT void l_dbus_client_destroy(struct l_dbus_client *client)
> > +{
> > +	if (unlikely(!client))
> > +		return;
> > +
> > +	if (client->watch)
> > +		l_dbus_remove_signal_watch(client->dbus, client->watch);
> > +
> > +	if (client->added_watch)
> > +		l_dbus_remove_signal_watch(client->dbus, client->added_watch);
> > +
> > +	if (client->removed_watch)
> > +		l_dbus_remove_signal_watch(client->dbus, client->removed_watch);
> > +
> > +	if (client->connect_cb_data_destroy)
> > +		client->connect_cb_data_destroy(client->connect_cb_data);
> > +
> > +	if (client->disconnect_cb_data_destroy)
> > +		client->disconnect_cb_data_destroy(client->disconnect_cb_data);
> > +
> > +	if (client->ready_cb_data_destroy)
> > +		client->ready_cb_data_destroy(client->ready_cb_data);
> > +
> > +	if (client->proxy_cb_data_destroy)
> > +		client->proxy_cb_data_destroy(client->proxy_cb_data);
> > +
> > +	if (client->objects_call)
> > +		l_dbus_cancel(client->dbus, client->objects_call)
> > +;
> > +	l_queue_destroy(client->proxies,
> > +				(l_queue_destroy_func_t)l_dbus_proxy_destroy);
> > +
> > +	l_free(client->service);
> > +	l_free(client->path);
> > +	l_free(client);
> > +}
> > +
> > +LIB_EXPORT bool l_dbus_client_set_connect_handler(struct l_dbus_client
> > *client, +						l_dbus_watch_func_t function,
> > +						void *user_data,
> > +						l_dbus_destroy_func_t destroy)
> > +{
> > +	if (unlikely(!client))
> > +		return false;
> > +
> > +	client->connect_cb = function;
> > +	client->connect_cb_data = user_data;
> > +	client->connect_cb_data_destroy = destroy;
> 
> No biggie, but maybe we should call destroy function here in case it is
> already set.

OK.

> 
> > +
> > +	return true;
> > +}
> > +
> > +LIB_EXPORT bool l_dbus_client_set_disconnect_handler(struct l_dbus_client
> > *client, +						l_dbus_watch_func_t function,
> > +						void *user_data,
> > +						l_dbus_destroy_func_t destroy)
> > +{
> > +	if (unlikely(!client))
> > +		return false;
> > +
> > +	client->disconnect_cb = function;
> > +	client->disconnect_cb_data = user_data;
> > +	client->disconnect_cb_data_destroy = destroy;
> 
> as above
> 
> > +
> > +	return true;
> > +}
> > +
> > +LIB_EXPORT bool l_dbus_client_set_ready_handler(struct l_dbus_client
> > *client, +					l_dbus_client_ready_func_t function,
> > +					void *user_data,
> > +					l_dbus_destroy_func_t destroy)
> > +{
> > +	if (unlikely(!client))
> > +		return false;
> > +
> > +	client->ready_cb = function;
> > +	client->ready_cb_data = user_data;
> > +	client->ready_cb_data_destroy = destroy;
> 
> as above
> 
> > +
> > +	return true;
> > +}
> > +
> > +LIB_EXPORT bool l_dbus_client_set_proxy_handlers(struct l_dbus_client
> > *client, +			l_dbus_client_proxy_func_t proxy_added,
> > +			l_dbus_client_proxy_func_t proxy_removed,
> > +			l_dbus_client_property_function_t property_changed,
> > +			void *user_data, l_dbus_destroy_func_t destroy)
> > +{
> > +	if (unlikely(!client))
> > +		return false;
> > +
> > +	client->proxy_added_cb = proxy_added;
> > +	client->proxy_removed_cb = proxy_removed;
> > +	client->properties_changed_cb = property_changed;
> > +	client->proxy_cb_data = user_data;
> > +	client->proxy_cb_data_destroy = destroy;
> 
> as above
> 
> > +
> > +	return true;
> > +}
> 
> <snip>
> 
> Regards,
> -Denis


-- 
pozdrawiam
Szymon Janc

  reply	other threads:[~2017-12-05 17:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 15:06 [PATCH 0/6] D-Bus client and proxy API Szymon Janc
2017-12-01 15:06 ` [PATCH 1/6] dbus: Add l_dbus_message_builder_append_from_valist Szymon Janc
2017-12-04 18:25   ` Denis Kenzior
2017-12-01 15:06 ` [PATCH 2/6] dbus: Use l_dbus_message_builder_append_from_valist in append_arguments Szymon Janc
2017-12-04 18:25   ` Denis Kenzior
2017-12-01 15:06 ` [PATCH 3/6] dbus: Add support for proxy interface Szymon Janc
2017-12-04 18:40   ` Denis Kenzior
2017-12-05 17:05     ` Szymon Janc [this message]
2017-12-01 15:06 ` [PATCH 4/6] dbus: Add support for setting properties on D-Bus " Szymon Janc
2017-12-01 15:06 ` [PATCH 5/6] dbus: Add convenient API for calling method on " Szymon Janc
2017-12-01 15:06 ` [PATCH 6/6] examples: Extend dbus-client example Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28539502.z0LgiceJkP@ix \
    --to=szymon.janc@codecoup.pl \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.