|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From aae2b488d084cf2af9a552a55e1d9cc614f2a12a Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: David Herrmann <dh.herrmann@gmail.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Sun, 24 Aug 2014 18:55:58 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] bus: split bus_map_all_properties into multiple helpers
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
The bus_map_all_properties() helper calls
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
org.freedesktop.DBus.Properties.GetAll() on a given target and parses the
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
result according to a given property-table. This simplifies dealing with
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
DBus.Properties significantly. However, the function is blocking and thus
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
not really useful in many situations.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
This patch extracts the core of this function and adds two new helpers
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
which directly take dbus-messages as arguments. This way, you can issue
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
asynchronous requests and parse the result via these helpers:
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
bus_message_map_all_properties():
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
This is the same as bus_map_all_properties() but takes the result
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
message from a GetAll() request as argument. You can thus issue an
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
asynchronous GetAll() request and then use this helper once you got
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
the result.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
bus_message_map_properties_changed():
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
This function takes a signal-message that was retrieved via a
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
PropertiesChanged signal and then parses it like if you retrieved
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
it via GetAll(). Furthermore, this function returns the number of
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
matched properties that got invalidated by the PropertiesChanged
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
signal, but didn't carry the new value. This way, the caller can
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
issue a new GetAll() request and then parse the result.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
The old function bus_map_all_properties() is functionally unchanged, but
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
now uses bus_message_map_all_properties() internally.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd/sd-bus/bus-util.c | 93 +++++++++++++++++++++++++++++++---------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd/sd-bus/bus-util.h | 8 ++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
2 files changed, 80 insertions(+), 21 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index c97bf7d99d..aed3889b12 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/libsystemd/sd-bus/bus-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/libsystemd/sd-bus/bus-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -974,32 +974,17 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int bus_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- const char *destination,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- const char *path,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- void *userdata) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int bus_message_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_bus_message *m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(bus);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert(destination);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert(path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(m);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(map);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = sd_bus_call_method(
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- destination,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- path,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "org.freedesktop.DBus.Properties",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "GetAll",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- &error,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- &m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "s", "");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1052,7 +1037,73 @@ int bus_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return sd_bus_message_exit_container(m);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int bus_message_map_properties_changed(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_bus_message *m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char *member;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ int r, invalidated, i;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(bus);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(m);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(map);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* skip interface, but allow callers to do that themselves */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_bus_message_skip(m, "s");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = bus_message_map_all_properties(bus, m, map, userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ invalidated = 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ while ((r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &member)) > 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ for (i = 0; map[i].member; i++)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (streq(map[i].member, member)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ ++invalidated;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ break;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_bus_message_exit_container(m);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return invalidated;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int bus_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char *destination,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char *path,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(bus);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(destination);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(map);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_bus_call_method(
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ destination,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ path,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "org.freedesktop.DBus.Properties",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "GetAll",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ &error,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ &m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "s", "");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return bus_message_map_all_properties(bus, m, map, userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/libsystemd/sd-bus/bus-util.h b/src/libsystemd/sd-bus/bus-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index faf1775809..696daa1f03 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/libsystemd/sd-bus/bus-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/libsystemd/sd-bus/bus-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -46,6 +46,14 @@ struct bus_properties_map {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int bus_message_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_bus_message *m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int bus_message_map_properties_changed(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_bus_message *m,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const struct bus_properties_map *map,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int bus_map_all_properties(sd_bus *bus,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
const char *destination,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
const char *path,
|