diff options
author | Marc-Antoine Perennou <Marc-Antoine@Perennou.com> | 2013-01-31 09:50:21 +0100 |
---|---|---|
committer | Auke Kok <auke-jan.h.kok@intel.com> | 2013-02-13 14:36:01 -0800 |
commit | ddb88cc5b8c5896fc30a86397da6d7e14160801b (patch) | |
tree | 8b10e047a5985af14983d26646ea3697c68f3095 /src | |
parent | cdf3f17bfb20eac2929c8b6a582b988b790f071d (diff) |
dbus: introduce parse_unit_info
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/dbus-common.c | 28 | ||||
-rw-r--r-- | src/shared/dbus-common.h | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c index 50891a8ade..2769b2c882 100644 --- a/src/shared/dbus-common.c +++ b/src/shared/dbus-common.c @@ -988,6 +988,34 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) { return 0; } +int bus_parse_unit_info(DBusMessageIter *iter, struct unit_info *u) { + DBusMessageIter sub; + + assert(iter); + assert(u); + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRUCT) + return -EINVAL; + + dbus_message_iter_recurse(iter, &sub); + + if (bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->id, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->description, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->load_state, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->active_state, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->sub_state, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->following, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_OBJECT_PATH, &u->unit_path, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_UINT32, &u->job_id, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->job_type, true) < 0 || + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_OBJECT_PATH, &u->job_path, false) < 0) { + log_error("Failed to parse reply."); + return -EIO; + } + + return 0; +} + int bus_append_strv_iter(DBusMessageIter *iter, char **l) { DBusMessageIter sub; diff --git a/src/shared/dbus-common.h b/src/shared/dbus-common.h index 800c0ea23a..f7f614cdcd 100644 --- a/src/shared/dbus-common.h +++ b/src/shared/dbus-common.h @@ -212,6 +212,8 @@ struct unit_info { const char *job_path; }; +int bus_parse_unit_info(DBusMessageIter *iter, struct unit_info *u); + int bus_append_strv_iter(DBusMessageIter *iter, char **l); int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next); |