From: Szymon Janc <szymon.janc@codecoup.pl>
To: ell@lists.01.org
Subject: [PATCH 6/6] examples: Extend dbus-client example
Date: Fri, 01 Dec 2017 16:06:10 +0100 [thread overview]
Message-ID: <20171201150610.9696-7-szymon.janc@codecoup.pl> (raw)
In-Reply-To: <20171201150610.9696-1-szymon.janc@codecoup.pl>
[-- Attachment #1: Type: text/plain, Size: 3791 bytes --]
This adds sample code for using D-Bus proxy interface.
---
examples/dbus-client.c | 93 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 84 insertions(+), 9 deletions(-)
diff --git a/examples/dbus-client.c b/examples/dbus-client.c
index 507a4e8..1f60643 100644
--- a/examples/dbus-client.c
+++ b/examples/dbus-client.c
@@ -60,23 +60,81 @@ static void disconnect_callback(void *user_data)
l_main_quit();
}
-static void service_appeared(struct l_dbus *dbus, void *user_data)
+static void iwd_service_appeared(struct l_dbus *dbus, void *user_data)
{
l_info("Service appeared");
}
-static void service_disappeared(struct l_dbus *dbus, void *user_data)
+static void iwd_service_disappeared(struct l_dbus *dbus, void *user_data)
{
- l_info("Service disappeared, quitting...");
- l_main_quit();
+ l_info("Service disappeared");
+}
+
+static void bluez_client_connected(struct l_dbus *dbus, void *user_data)
+{
+ l_info("client connected");
+}
+
+static void bluez_client_disconnected(struct l_dbus *dbus, void *user_data)
+{
+ l_info("client disconnected");
+}
+
+static void bluez_client_ready(struct l_dbus_client *client, void *user_data)
+{
+ l_info("client ready");
+}
+
+static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
+{
+ const char *interface = l_dbus_proxy_get_interface(proxy);
+ const char *path = l_dbus_proxy_get_path(proxy);
+
+ l_info("proxy added: %s %s", path, interface);
+
+ if (!strcmp(interface, "org.bluez.Adapter1") ||
+ !strcmp(interface, "org.bluez.Device1")) {
+ char *str;
+
+ if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str))
+ return;
+
+ l_info(" Address: %s", str);
+ }
+}
+
+static void proxy_removed(struct l_dbus_proxy *proxy, void *user_data)
+{
+ l_info("proxy removed: %s %s", l_dbus_proxy_get_path(proxy),
+ l_dbus_proxy_get_interface(proxy));
+}
+
+static void property_changed(struct l_dbus_proxy *proxy, const char *name,
+ struct l_dbus_message *msg, void *user_data)
+{
+ l_info("property changed: %s (%s %s)", name,
+ l_dbus_proxy_get_path(proxy),
+ l_dbus_proxy_get_interface(proxy));
+
+ if (!strcmp(name, "Address")) {
+ char *str;
+
+ if (!l_dbus_message_get_arguments(msg, "s", &str)) {
+ return;
+ }
+
+ l_info(" Address: %s", str);
+ }
}
int main(int argc, char *argv[])
{
+ struct l_dbus_client *client;
struct l_dbus *dbus;
struct l_signal *signal;
sigset_t mask;
- uint32_t watch_id;
+ uint32_t iwd_watch_id;
+
if (!l_main_init())
return -1;
@@ -93,14 +151,31 @@ int main(int argc, char *argv[])
l_dbus_set_ready_handler(dbus, ready_callback, dbus, NULL);
l_dbus_set_disconnect_handler(dbus, disconnect_callback, NULL, NULL);
- watch_id = l_dbus_add_service_watch(dbus, "net.connman.iwd",
- service_appeared,
- service_disappeared,
+ /* service basic watch */
+ iwd_watch_id = l_dbus_add_service_watch(dbus, "net.connman.iwd",
+ iwd_service_appeared,
+ iwd_service_disappeared,
NULL, NULL);
+ /* proxy example */
+ client = l_dbus_client_new(dbus, "org.bluez", "/org/bluez");
+
+ l_dbus_client_set_connect_handler(client, bluez_client_connected, NULL,
+ NULL);
+ l_dbus_client_set_disconnect_handler(client, bluez_client_disconnected,
+ NULL, NULL);
+
+ l_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
+ property_changed, NULL, NULL);
+
+ l_dbus_client_set_ready_handler(client, bluez_client_ready, NULL, NULL);
+
+
l_main_run();
- l_dbus_remove_watch(dbus, watch_id);
+ l_dbus_remove_watch(dbus, iwd_watch_id);
+
+ l_dbus_client_destroy(client);
l_dbus_destroy(dbus);
l_signal_remove(signal);
--
2.14.3
prev parent reply other threads:[~2017-12-01 15:06 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
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 ` Szymon Janc [this message]
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=20171201150610.9696-7-szymon.janc@codecoup.pl \
--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.