[systemd-commits] 3 commits - src/libsystemd-bus src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Nov 7 19:30:45 CET 2013
src/libsystemd-bus/bus-convenience.c | 75 ++++++++++++++++++++++++++++++++++
src/libsystemd-bus/bus-message.c | 2
src/libsystemd-bus/bus-util.c | 29 +++++--------
src/libsystemd-bus/libsystemd-bus.sym | 2
src/systemd/sd-bus.h | 6 +-
5 files changed, 94 insertions(+), 20 deletions(-)
New commits:
commit 63be1989c77864c7f9845bee1fbd0a2946b0b1b6
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 7 19:28:54 2013 +0100
bus: add APIs to easily query string and strv properties
diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
index 0ccc259..4dc65b9 100644
--- a/src/libsystemd-bus/bus-convenience.c
+++ b/src/libsystemd-bus/bus-convenience.c
@@ -305,6 +305,81 @@ _public_ int sd_bus_get_property_trivial(
return 0;
}
+_public_ int sd_bus_get_property_string(
+ sd_bus *bus,
+ const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member,
+ sd_bus_error *error,
+ char **ret) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ const char *s;
+ char *n;
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
+ assert_return(member_name_is_valid(member), -EINVAL);
+ assert_return(ret, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_enter_container(reply, 'v', "s");
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_basic(reply, 's', &s);
+ if (r < 0)
+ return r;
+
+ n = strdup(s);
+ if (!n)
+ return -ENOMEM;
+
+ *ret = n;
+ return 0;
+}
+
+_public_ int sd_bus_get_property_strv(
+ sd_bus *bus,
+ const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member,
+ sd_bus_error *error,
+ char ***ret) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
+ assert_return(member_name_is_valid(member), -EINVAL);
+ assert_return(ret, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_enter_container(reply, 'v', NULL);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_strv(reply, ret);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
_public_ int sd_bus_set_property(
sd_bus *bus,
const char *destination,
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 5eecfa1..4924cf1 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -142,6 +142,8 @@ global:
sd_bus_call_method;
sd_bus_get_property;
sd_bus_get_property_trivial;
+ sd_bus_get_property_string;
+ sd_bus_get_property_strv;
sd_bus_set_property;
sd_bus_reply_method_return;
sd_bus_reply_method_error;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index e626407..f843c77 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -197,7 +197,7 @@ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all);
int sd_bus_message_read(sd_bus_message *m, const char *types, ...);
int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p);
int sd_bus_message_read_array(sd_bus_message *m, char type, const void **ptr, size_t *size);
-int sd_bus_message_read_strv(sd_bus_message *m, char ***l);
+int sd_bus_message_read_strv(sd_bus_message *m, char ***l); /* free the result! */
int sd_bus_message_skip(sd_bus_message *m, const char *types);
int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *contents);
int sd_bus_message_exit_container(sd_bus_message *m);
@@ -211,6 +211,8 @@ int sd_bus_message_rewind(sd_bus_message *m, int complete);
int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type);
int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char type, void *ptr);
+int sd_bus_get_property_string(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char **ret); /* free the result! */
+int sd_bus_get_property_strv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char ***ret); /* free the result! */
int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...);
int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);
@@ -234,7 +236,7 @@ int sd_bus_get_unique_name(sd_bus *bus, const char **unique);
int sd_bus_request_name(sd_bus *bus, const char *name, int flags);
int sd_bus_release_name(sd_bus *bus, const char *name);
int sd_bus_list_names(sd_bus *bus, char ***l);
-int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner);
+int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner); /* free the result! */
int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid);
int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid);
int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
commit 1405bef3f1f204fdee001e1d002a8e91a56ef0d3
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date: Thu Nov 7 13:49:02 2013 +0900
bus: mark sd_bus_message_at_end public
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index b6972ac..42c764c 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -2430,7 +2430,7 @@ static bool message_end_of_array(sd_bus_message *m, size_t index) {
return index >= c->begin + BUS_MESSAGE_BSWAP32(m, *c->array_size);
}
-int sd_bus_message_at_end(sd_bus_message *m, int complete) {
+_public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
commit 261afec5ae96297b567c3735dc2cbd8bcf57d0c4
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date: Thu Nov 7 13:49:00 2013 +0900
bus: fix bus_print_property with strv
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index bf8fb40..2b1cd0b 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -545,33 +545,28 @@ int bus_print_property(const char *name, sd_bus_message *property, bool all) {
case SD_BUS_TYPE_ARRAY:
if (streq(contents, "s")) {
- bool space = false;
- char tp;
- const char *cnt;
+ bool first = true;
+ const char *str;
r = sd_bus_message_enter_container(property, SD_BUS_TYPE_ARRAY, contents);
if (r < 0)
return r;
- r = sd_bus_message_peek_type(property, &tp, &cnt);
+ while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) {
+ if (first)
+ printf("%s=", name);
+
+ printf("%s%s", first ? "" : " ", str);
+
+ first = false;
+ }
if (r < 0)
return r;
- if (all || cnt) {
- const char *str;
-
+ if (first && all)
printf("%s=", name);
-
- while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) >= 0) {
- printf("%s%s", space ? " " : "", str);
-
- space = true;
- }
- if (r < 0)
- return r;
-
+ if (!first || all)
puts("");
- }
r = sd_bus_message_exit_container(property);
if (r < 0)
More information about the systemd-commits
mailing list