diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2013-08-25 14:59:43 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2013-08-25 14:59:43 +0200 |
commit | 2280c7079b13ff8ddb64e9ecccac12d447bfbc2a (patch) | |
tree | effebec8a67aaa24505bdd3636ec2930dea34057 /tdecore/tdehw/hwlibdaemons | |
parent | a5ba7ad71203a7ff1b3a716e7171e919a2e2e5bb (diff) | |
download | tdelibs-2280c7079b13ff8ddb64e9ecccac12d447bfbc2a.tar.gz tdelibs-2280c7079b13ff8ddb64e9ecccac12d447bfbc2a.zip |
Add tdehwlib-daemon power management backend to TDE hardware library
Diffstat (limited to 'tdecore/tdehw/hwlibdaemons')
-rw-r--r-- | tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf | 4 | ||||
-rw-r--r-- | tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c | 55 |
2 files changed, 59 insertions, 0 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf b/tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf index a649b969f..f8537010f 100644 --- a/tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf +++ b/tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf @@ -20,6 +20,8 @@ send_interface="org.freedesktop.DBus.Properties"/> <allow send_destination="org.trinitydesktop.hardwarecontrol.Brightness" send_interface="org.freedesktop.DBus.Properties"/> + <allow send_destination="org.trinitydesktop.hardwarecontrol.Power" + send_interface="org.freedesktop.DBus.Properties"/> <allow send_destination="org.trinitydesktop.hardwarecontrol" send_interface="org.trinitydesktop.hardwarecontrol"/> @@ -27,6 +29,8 @@ send_interface="org.trinitydesktop.hardwarecontrol.CPUGovernor"/> <allow send_destination="org.trinitydesktop.hardwarecontrol" send_interface="org.trinitydesktop.hardwarecontrol.Brightness"/> + <allow send_destination="org.trinitydesktop.hardwarecontrol" + send_interface="org.trinitydesktop.hardwarecontrol.Power"/> </policy> <policy context="default"> diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c index f7e707522..4cdbcea9b 100644 --- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c +++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c @@ -249,6 +249,43 @@ void reply_SetBrightness(DBusMessage* msg, DBusConnection* conn) { free(safepath); } +void reply_CanSetPower(DBusMessage* msg, DBusConnection* conn, char* state) { + + // check if path is writable + int writable = false; + int rval = access ("/sys/power/state", W_OK); + if (rval == 0) { + writable = true; + } + + // check if method is supported + int method = false; + if (writable) { + FILE *node = fopen("/sys/power/state", "r"); + if (node != NULL) { + char *line = NULL; + size_t len = 0; + ssize_t read = getline(&line, &len, node); + if (line) { + method = strstr(line, state) != NULL; + free(line); + } + if (fclose(node) == EOF) { + // Error! + } + } + } + + // send reply + reply_Bool(msg, conn, writable && method); +} + +void reply_SetPower(DBusMessage* msg, DBusConnection* conn, char* state) { + + // set power state + reply_SetGivenPath(msg, conn, "/sys/power/state", state); +} + void listen() { DBusMessage* msg; DBusMessage* reply; @@ -309,6 +346,24 @@ void listen() { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Brightness", "SetBrightness")) { reply_SetBrightness(msg, conn); } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) { + reply_CanSetPower(msg, conn, "standby"); + } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) { + reply_SetPower(msg, conn, "standby"); + } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) { + reply_CanSetPower(msg, conn, "mem"); + } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) { + reply_SetPower(msg, conn, "mem"); + } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) { + reply_CanSetPower(msg, conn, "disk"); + } + else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) { + reply_SetPower(msg, conn, "disk"); + } else { fprintf(stderr, "[tde_dbus_hardwarecontrol] Unknown method '%s' called on interface '%s', ignoring\n", dbus_message_get_member(msg), dbus_message_get_interface(msg)); } |