summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2013-09-22 14:57:33 +0200
committerSlávek Banko <slavek.banko@axis.cz>2013-09-22 14:57:33 +0200
commit645e8c58a752ed221388d916b1981483cc6d8811 (patch)
treee98eecd84bb98eca6b431429a976edcb3ad0e182 /tdecore/tdehw
parent101d86a3fc74e30690ed16a74dff105b1f6bb309 (diff)
downloadtdelibs-645e8c58a752ed221388d916b1981483cc6d8811.tar.gz
tdelibs-645e8c58a752ed221388d916b1981483cc6d8811.zip
Add support for freeze suspend state
Diffstat (limited to 'tdecore/tdehw')
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c14
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp59
-rw-r--r--tdecore/tdehw/tderootsystemdevice.h8
3 files changed, 76 insertions, 5 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
index 24a391a3c..6b3a5dc30 100644
--- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
+++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
@@ -356,6 +356,12 @@ void reply_Introspect(DBusMessage* msg, DBusConnection* conn) {
" <method name=\"Standby\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n"
+ " <method name=\"CanFreeze\">\n"
+ " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
+ " </method>\n"
+ " <method name=\"Freeze\">\n"
+ " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
+ " </method>\n"
" <method name=\"CanSuspend\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n"
@@ -487,6 +493,12 @@ void listen() {
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", "CanFreeze")) {
+ reply_CanSetPower(msg, conn, "freeze");
+ }
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
+ reply_SetPower(msg, conn, "freeze");
+ }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
reply_CanSetPower(msg, conn, "mem");
}
@@ -508,7 +520,7 @@ void listen() {
else {
error_UnknownMessage(msg, conn);
}
-
+
// free the message
dbus_message_unref(msg);
}
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index 774bc091a..488c60e2b 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -147,6 +147,45 @@ bool TDERootSystemDevice::canStandby() {
return FALSE;
}
+bool TDERootSystemDevice::canFreeze() {
+ // Network file systems mounted on $HOME typically cause nasty suspend/resume failures
+ // See Bug 1615 for details
+ if (isNetworkFileSystem(TDEStorageDevice::determineFileSystemType(TDEGlobal::dirs()->localtdedir()))) {
+ return FALSE;
+ }
+
+ TQString statenode = "/sys/power/state";
+ int rval = access (statenode.ascii(), W_OK);
+ if (rval == 0) {
+ if (powerStates().contains(TDESystemPowerState::Freeze)) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+ }
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can freeze?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanFreeze");
+ 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;
+}
+
bool TDERootSystemDevice::canSuspend() {
// Network file systems mounted on $HOME typically cause nasty suspend/resume failures
// See Bug 1615 for details
@@ -352,7 +391,7 @@ bool TDERootSystemDevice::canHibernate() {
bool TDERootSystemDevice::canPowerOff() {
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
-
+
config->setGroup("General" );
bool maysd = false;
#ifdef WITH_CONSOLEKIT
@@ -394,7 +433,7 @@ bool TDERootSystemDevice::canPowerOff() {
bool TDERootSystemDevice::canReboot() {
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
-
+
config->setGroup("General" );
bool mayrb = false;
#ifdef WITH_CONSOLEKIT
@@ -460,7 +499,7 @@ void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESy
}
bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) {
- if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) {
+ if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Freeze) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) {
TQString statenode = "/sys/power/state";
TQFile file( statenode );
if ( file.open( IO_WriteOnly ) ) {
@@ -468,6 +507,9 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
if (ps == TDESystemPowerState::Standby) {
powerCommand = "standby";
}
+ if (ps == TDESystemPowerState::Freeze) {
+ powerCommand = "freeze";
+ }
if (ps == TDESystemPowerState::Suspend) {
powerCommand = "mem";
}
@@ -591,6 +633,17 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true;
}
}
+ else if (ps == TDESystemPowerState::Freeze) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Freeze");
+ 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",
diff --git a/tdecore/tdehw/tderootsystemdevice.h b/tdecore/tdehw/tderootsystemdevice.h
index 1c94fe1eb..7809fb09c 100644
--- a/tdecore/tdehw/tderootsystemdevice.h
+++ b/tdecore/tdehw/tderootsystemdevice.h
@@ -37,6 +37,7 @@ namespace TDESystemPowerState {
enum TDESystemPowerState {
Active,
Standby,
+ Freeze,
Suspend,
Hibernate,
PowerOff,
@@ -66,7 +67,7 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
* @param Device type
*/
TDERootSystemDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
-
+
/**
* Destructor.
*/
@@ -108,6 +109,11 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
bool canStandby();
/**
+ * @return TRUE if hardware and permissions allow the system to enter freeze state, FALSE if not
+ */
+ bool canFreeze();
+
+ /**
* @return TRUE if hardware and permissions allow the system to be suspended, FALSE if not
*/
bool canSuspend();