From 707e5e52804a8f041f0d2f822f0bcf7062ad24ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 4 Jul 2010 04:37:03 +0200 Subject: [PATCH] dbus: complete coverage of timer units --- src/dbus-timer.c | 38 +++++++++++++++++++++++++++++++++++--- src/systemctl.c | 22 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/dbus-timer.c b/src/dbus-timer.c index 68bd8a44..af0ae72f 100644 --- a/src/dbus-timer.c +++ b/src/dbus-timer.c @@ -27,8 +27,9 @@ #define BUS_TIMER_INTERFACE \ " \n" \ - " \n" \ - " \n" \ + " \n" \ + " \n" \ + " \n" #define INTROSPECTION \ DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ @@ -41,10 +42,41 @@ const char bus_timer_interface[] = BUS_TIMER_INTERFACE; +static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *property, void *data) { + Timer *p = data; + DBusMessageIter sub, sub2; + TimerValue *k; + + assert(m); + assert(i); + assert(property); + assert(p); + + if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(stt)", &sub)) + return -ENOMEM; + + LIST_FOREACH(value, k, p->values) { + const char *t = timer_base_to_string(k->base); + + if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) || + !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &t) || + !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->value) || + !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &k->next_elapse) || + !dbus_message_iter_close_container(&sub, &sub2)) + return -ENOMEM; + } + + if (!dbus_message_iter_close_container(i, &sub)) + return -ENOMEM; + + return 0; +} + DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { const BusProperty properties[] = { BUS_UNIT_PROPERTIES, - { "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", &u->timer.unit->meta.id }, + { "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", u->timer.unit->meta.id }, + { "org.freedesktop.systemd1.Timer", "Timers", bus_timer_append_timers, "a(stt)", u }, { NULL, NULL, NULL, NULL, NULL } }; diff --git a/src/systemctl.c b/src/systemctl.c index 4620315a..dddd6893 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -1024,7 +1024,7 @@ static int print_property(const char *name, DBusMessageIter *iter) { /* Yes, heuristics! But we can change this check * should it turn out to not be sufficient */ - if (strstr(name, "Timestamp")) { + if (strstr(name, "Timestamp") || strstr(name, "Elapse")) { char timestamp[FORMAT_TIMESTAMP_MAX], *t; if ((t = format_timestamp(timestamp, sizeof(timestamp), u)) || arg_all) @@ -1129,6 +1129,26 @@ static int print_property(const char *name, DBusMessageIter *iter) { dbus_message_iter_next(&sub); } + return 0; + } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "Timers")) { + DBusMessageIter sub, sub2; + + dbus_message_iter_recurse(iter, &sub); + + while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRUCT) { + const char *base; + uint64_t value, next_elapse; + + dbus_message_iter_recurse(&sub, &sub2); + + if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &base, true) >= 0 && + bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT64, &value, true) >= 0 && + bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT64, &next_elapse, false) >= 0) + printf("%s=%llu\n", base, (unsigned long long) value); + + dbus_message_iter_next(&sub); + } + return 0; } -- 2.39.5