From a185c5aa2d8bef98716f8cf160da263c17e588b2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 17 Jun 2011 15:59:18 +0200 Subject: logind: implement idle hint logic --- src/logind-session-dbus.c | 75 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'src/logind-session-dbus.c') diff --git a/src/logind-session-dbus.c b/src/logind-session-dbus.c index 539384b7d4..8b5b3ad51f 100644 --- a/src/logind-session-dbus.c +++ b/src/logind-session-dbus.c @@ -20,6 +20,7 @@ ***/ #include +#include #include "logind.h" #include "logind-session.h" @@ -156,6 +157,39 @@ static int bus_session_append_active(DBusMessageIter *i, const char *property, v return 0; } +static int bus_session_append_idle_hint(DBusMessageIter *i, const char *property, void *data) { + Session *s = data; + bool b; + + assert(i); + assert(property); + assert(s); + + b = session_get_idle_hint(s, NULL); + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b)) + return -ENOMEM; + + return 0; +} + +static int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) { + Session *s = data; + dual_timestamp t; + uint64_t u; + + assert(i); + assert(property); + assert(s); + + session_get_idle_hint(s, &t); + u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic; + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u)) + return -ENOMEM; + + return 0; +} + static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_type, session_type, SessionType); static int get_session_for_path(Manager *m, const char *path, Session **_s) { @@ -189,24 +223,29 @@ static DBusHandlerResult session_message_dispatch( DBusMessage *message) { const BusProperty properties[] = { - { "org.freedesktop.login1.Session", "Id", bus_property_append_string, "s", s->id }, - { "org.freedesktop.login1.Session", "User", bus_session_append_user, "(uo)", s }, - { "org.freedesktop.login1.Session", "Name", bus_property_append_string, "s", s->user->name }, - { "org.freedesktop.login1.Session", "ControlGroupPath", bus_property_append_string, "s", s->cgroup_path }, - { "org.freedesktop.login1.Session", "VTNr", bus_property_append_uint32, "u", &s->vtnr }, - { "org.freedesktop.login1.Session", "Seat", bus_session_append_seat, "(so)", s }, - { "org.freedesktop.login1.Session", "TTY", bus_property_append_string, "s", s->tty }, - { "org.freedesktop.login1.Session", "Display", bus_property_append_string, "s", s->display }, - { "org.freedesktop.login1.Session", "Remote", bus_property_append_bool, "b", &s->remote }, - { "org.freedesktop.login1.Session", "RemoteUser", bus_property_append_string, "s", s->remote_user }, - { "org.freedesktop.login1.Session", "RemoteHost", bus_property_append_string, "s", s->remote_host }, - { "org.freedesktop.login1.Session", "Leader", bus_property_append_pid, "u", &s->leader }, - { "org.freedesktop.login1.Session", "Audit", bus_property_append_uint32, "u", &s->audit_id }, - { "org.freedesktop.login1.Session", "Type", bus_session_append_type, "s", &s->type }, - { "org.freedesktop.login1.Session", "Active", bus_session_append_active, "b", s }, - { "org.freedesktop.login1.Session", "Controllers", bus_property_append_strv, "as", s->controllers }, - { "org.freedesktop.login1.Session", "ResetControllers", bus_property_append_strv, "as", s->reset_controllers }, - { "org.freedesktop.login1.Session", "KillProcesses", bus_property_append_bool, "b", &s->kill_processes }, + { "org.freedesktop.login1.Session", "Id", bus_property_append_string, "s", s->id }, + { "org.freedesktop.login1.Session", "User", bus_session_append_user, "(uo)", s }, + { "org.freedesktop.login1.Session", "Name", bus_property_append_string, "s", s->user->name }, + { "org.freedesktop.login1.Session", "Timestamp", bus_property_append_usec, "t", &s->timestamp.realtime }, + { "org.freedesktop.login1.Session", "TimestampMonotonic", bus_property_append_usec, "t", &s->timestamp.monotonic }, + { "org.freedesktop.login1.Session", "ControlGroupPath", bus_property_append_string, "s", s->cgroup_path }, + { "org.freedesktop.login1.Session", "VTNr", bus_property_append_uint32, "u", &s->vtnr }, + { "org.freedesktop.login1.Session", "Seat", bus_session_append_seat, "(so)", s }, + { "org.freedesktop.login1.Session", "TTY", bus_property_append_string, "s", s->tty }, + { "org.freedesktop.login1.Session", "Display", bus_property_append_string, "s", s->display }, + { "org.freedesktop.login1.Session", "Remote", bus_property_append_bool, "b", &s->remote }, + { "org.freedesktop.login1.Session", "RemoteUser", bus_property_append_string, "s", s->remote_user }, + { "org.freedesktop.login1.Session", "RemoteHost", bus_property_append_string, "s", s->remote_host }, + { "org.freedesktop.login1.Session", "Leader", bus_property_append_pid, "u", &s->leader }, + { "org.freedesktop.login1.Session", "Audit", bus_property_append_uint32, "u", &s->audit_id }, + { "org.freedesktop.login1.Session", "Type", bus_session_append_type, "s", &s->type }, + { "org.freedesktop.login1.Session", "Active", bus_session_append_active, "b", s }, + { "org.freedesktop.login1.Session", "Controllers", bus_property_append_strv, "as", s->controllers }, + { "org.freedesktop.login1.Session", "ResetControllers", bus_property_append_strv, "as", s->reset_controllers }, + { "org.freedesktop.login1.Session", "KillProcesses", bus_property_append_bool, "b", &s->kill_processes }, + { "org.freedesktop.login1.Session", "IdleHint", bus_session_append_idle_hint, "b", s }, + { "org.freedesktop.login1.Session", "IdleSinceHint", bus_session_append_idle_hint_since, "t", s }, + { "org.freedesktop.login1.Session", "IdleSinceHintMonotonic", bus_session_append_idle_hint_since, "t", s }, { NULL, NULL, NULL, NULL, NULL } }; -- cgit v1.2.3-54-g00ecf