summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/org.trinitydesktop.hardwarecontrol.conf4
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c55
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp101
3 files changed, 156 insertions, 4 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));
}
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index 422ff50de..86a92340c 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -30,13 +30,13 @@
#include "config.h"
-#if defined(WITH_UPOWER) || defined(WITH_CONSOLEKIT)
+#if defined(WITH_TDEHWLIB_DAEMONS) || defined(WITH_UPOWER) || defined(WITH_DEVKITPOWER) || defined(WITH_HAL) || defined(WITH_CONSOLEKIT)
#include <tqdbusdata.h>
#include <tqdbusmessage.h>
#include <tqdbusproxy.h>
#include <tqdbusvariant.h>
#include <tqdbusconnection.h>
-#endif // defined(WITH_UPOWER) || defined(WITH_CONSOLEKIT)
+#endif // defined(WITH_TDEHWLIB_DAEMONS) || defined(WITH_UPOWER) || defined(WITH_DEVKITPOWER) || defined(WITH_HAL) || defined(WITH_CONSOLEKIT)
TDERootSystemDevice::TDERootSystemDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
m_hibernationSpace = -1;
@@ -107,9 +107,24 @@ bool TDERootSystemDevice::canStandby() {
return FALSE;
}
}
- else {
- return FALSE;
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can standby?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanStandby");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toBool();
+ }
+ }
}
+#endif // WITH_TDEHWLIB_DAEMONS
}
bool TDERootSystemDevice::canSuspend() {
@@ -186,6 +201,24 @@ bool TDERootSystemDevice::canSuspend() {
}
#endif // WITH_HAL
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can suspend?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanSuspend");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toBool();
+ }
+ }
+ }
+#endif // WITH_TDEHWLIB_DAEMONS
+
return FALSE;
}
@@ -263,6 +296,24 @@ bool TDERootSystemDevice::canHibernate() {
}
#endif // WITH_HAL
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can hibernate?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanHibernate");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toBool();
+ }
+ }
+ }
+#endif // WITH_TDEHWLIB_DAEMONS
+
return FALSE;
}
@@ -492,6 +543,48 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
#endif // WITH_HAL
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn;
+ dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if ( dbusConn.isConnected() ) {
+ if (ps == TDESystemPowerState::Standby) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Standby");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ else if (ps == TDESystemPowerState::Suspend) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Suspend");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ else if (ps == TDESystemPowerState::Hibernate) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Hibernate");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ }
+ }
+#endif // WITH_TDEHWLIB_DAEMONS
+
return false;
}
else if (ps == TDESystemPowerState::PowerOff) {