return r;
LIST_FOREACH(value, v, t->values) {
- _cleanup_free_ char *buf = NULL;
- const char *s;
- size_t l;
+ _cleanup_free_ char *usec = NULL;
if (v->base == TIMER_CALENDAR)
continue;
- s = timer_base_to_string(v->base);
- assert(endswith(s, "Sec"));
-
- /* s/Sec/USec/ */
- l = strlen(s);
- buf = new(char, l+2);
- if (!buf)
+ usec = timer_base_to_usec_string(v->base);
+ if (!usec)
return -ENOMEM;
- memcpy(buf, s, l-3);
- memcpy(buf+l-3, "USec", 5);
-
- r = sd_bus_message_append(reply, "(stt)", buf, v->value, v->next_elapse);
+ r = sd_bus_message_append(reply, "(stt)", usec, v->value, v->next_elapse);
if (r < 0)
return r;
}
assert(bus);
assert(reply);
- return sd_bus_message_append(reply, "t",
- (uint64_t) usec_shift_clock(t->next_elapse_monotonic_or_boottime,
- TIMER_MONOTONIC_CLOCK(t), CLOCK_MONOTONIC));
+ return sd_bus_message_append(reply, "t", timer_next_elapse_monotonic(t));
}
const sd_bus_vtable bus_timer_vtable[] = {
return 2; /* Return the number of pairs added to the env block */
}
+uint64_t timer_next_elapse_monotonic(const Timer *t) {
+ assert(t);
+
+ return (uint64_t) usec_shift_clock(t->next_elapse_monotonic_or_boottime,
+ TIMER_MONOTONIC_CLOCK(t), CLOCK_MONOTONIC);
+}
+
static const char* const timer_base_table[_TIMER_BASE_MAX] = {
[TIMER_ACTIVE] = "OnActiveSec",
[TIMER_BOOT] = "OnBootSec",
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
+char* timer_base_to_usec_string(TimerBase i) {
+ _cleanup_free_ char *buf = NULL;
+ const char *s;
+ size_t l;
+
+ s = timer_base_to_string(i);
+
+ if (endswith(s, "Sec")) {
+ /* s/Sec/USec/ */
+ l = strlen(s);
+ buf = new(char, l+2);
+ if (!buf)
+ return NULL;
+
+ memcpy(buf, s, l-3);
+ memcpy(buf+l-3, "USec", 5);
+ } else {
+ buf = strdup(s);
+ if (!buf)
+ return NULL;
+ }
+
+ return TAKE_PTR(buf);
+}
+
static const char* const timer_result_table[_TIMER_RESULT_MAX] = {
[TIMER_SUCCESS] = "success",
[TIMER_FAILURE_RESOURCES] = "resources",
#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
+uint64_t timer_next_elapse_monotonic(const Timer *t);
+
void timer_free_values(Timer *t);
extern const UnitVTable timer_vtable;
const char *timer_base_to_string(TimerBase i) _const_;
TimerBase timer_base_from_string(const char *s) _pure_;
+char* timer_base_to_usec_string(TimerBase i);
+
const char* timer_result_to_string(TimerResult i) _const_;
TimerResult timer_result_from_string(const char *s) _pure_;