summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2018-11-06 23:40:14 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-02-06 23:37:10 +0900
commit975d1ed9c79d8693447120c92fea47d5af624476 (patch)
tree18343c3d9fd8dc8086494ddc35446cdd0bd43f82
parent0656a7511d0ef8f76d1e25a6d39dcc7c1b44de6c (diff)
downloadtdelibs-975d1ed9c79d8693447120c92fea47d5af624476.tar.gz
tdelibs-975d1ed9c79d8693447120c92fea47d5af624476.zip
Fixed support for freeze/standby/suspend/hybrid suspend/hibernate in
tdehw lib. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c236
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp24
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp142
-rw-r--r--tdecore/tdehw/tderootsystemdevice.h36
4 files changed, 221 insertions, 217 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
index aed9984e..a0b6870b 100644
--- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
+++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
@@ -254,148 +254,142 @@ 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;
+void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char* disk, char* mem) {
+ // check if required files are writable
+ bool files_writable = (access("/sys/power/state", W_OK) == 0);
+ if (disk)
+ {
+ files_writable &= (access("/sys/power/disk", W_OK) == 0);
+ }
+ if (mem)
+ {
+ files_writable &= (access("/sys/power/mem_sleep", W_OK) == 0);
+ }
+ if (!files_writable)
+ {
+ reply_Bool(msg, conn, false); // send reply
}
// check if method is supported
- int method = false;
- if (writable) {
- FILE *node = fopen("/sys/power/state", "r");
- if (node != NULL) {
+ bool result = false;
+ // state
+ FILE *state_node = fopen("/sys/power/state", "r");
+ if (state_node) {
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t read = getline(&line, &len, state_node);
+ if (read > 0 && line) {
+ result = (strstr(line, state) != NULL);
+ free(line);
+ }
+ fclose(state_node);
+ }
+ if (!result)
+ {
+ reply_Bool(msg, conn, false); // send reply
+ }
+
+ // disk
+ if (disk)
+ {
+ FILE *disk_node = fopen("/sys/power/disk", "r");
+ if (disk_node) {
char *line = NULL;
size_t len = 0;
- ssize_t read = getline(&line, &len, node);
+ ssize_t read = getline(&line, &len, disk_node);
if (read > 0 && line) {
- method = strstr(line, state) != NULL;
+ result &= (strstr(line, disk) != NULL);
free(line);
}
- if (fclose(node) == EOF) {
- // Error!
- }
+ fclose(disk_node);
}
}
-
- // 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 reply_CanSetHibernation(DBusMessage* msg, DBusConnection* conn, char* state, char* disk) {
-
- // check if path is writable
- bool state_writable = false;
- int rval = access ("/sys/power/state", W_OK);
- if (rval == 0) {
- state_writable = true;
- }
- bool disk_writable = false;
- rval = access ("/sys/power/disk", W_OK);
- if (rval == 0) {
- disk_writable = true;
+ if (!result)
+ {
+ reply_Bool(msg, conn, false); // send reply
}
- // check if method is supported
- bool method1 = false, method2 = false;
- if (state_writable && disk_writable) {
- FILE *statenode = fopen("/sys/power/state", "r");
- if (statenode != NULL) {
- char *line = NULL;
- size_t len = 0;
- ssize_t read = getline(&line, &len, statenode);
- if (read > 0 && line) {
- method1 = (strstr(line, state) != NULL);
- free(line);
- }
- if (fclose(statenode) == EOF) {
- // Error!
- }
- }
- FILE *disknode = fopen("/sys/power/disk", "r");
- if (disknode != NULL) {
+ // mem_sleep
+ if (mem)
+ {
+ FILE *mem_node = fopen("/sys/power/mem_sleep", "r");
+ if (mem_node) {
char *line = NULL;
size_t len = 0;
- ssize_t read = getline(&line, &len, disknode);
+ ssize_t read = getline(&line, &len, mem_node);
if (read > 0 && line) {
- method2 = (strstr(line, disk) != NULL);
+ result &= (strstr(line, mem) != NULL);
free(line);
}
- if (fclose(disknode) == EOF) {
- // Error!
- }
+ fclose(mem_node);
}
}
- // send reply
- reply_Bool(msg, conn, state_writable && disk_writable && method1 && method2);
+ reply_Bool(msg, conn, result); // send reply
}
-void reply_SetHibernation(DBusMessage* msg, DBusConnection* conn, char* state, char* disk) {
- // set hibernation state
- DBusMessage* reply;
- DBusMessageIter args;
- const char* member = dbus_message_get_member(msg);
- dbus_uint32_t serial = 0;
- bool written1 = false, written2 = false;
-
- // check if path is writable
- int state_writable = false;
- int rval = access ("/sys/power/state", W_OK);
- if (rval == 0) {
- state_writable = true;
+void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char* disk, char* mem) {
+ // check if required files are writable
+ bool files_writable = (access("/sys/power/state", W_OK) == 0);
+ if (disk)
+ {
+ files_writable &= (access("/sys/power/disk", W_OK) == 0);
}
- int disk_writable = false;
- rval = access ("/sys/power/disk", W_OK);
- if (rval == 0) {
- disk_writable = true;
- }
-
- if (state_writable && disk_writable) {
- FILE *disknode = fopen("/sys/power/disk", "w");
- if (disknode != NULL) {
- if (fputs(disk, disknode) != EOF) {
- written1 = true;
- }
- if (fclose(disknode) == EOF) {
- // Error!
+ if (mem)
+ {
+ files_writable &= (access("/sys/power/mem_sleep", W_OK) == 0);
+ }
+ if (!files_writable)
+ {
+ reply_Bool(msg, conn, false); // send reply
+ }
+
+ // set suspend mode
+ bool result = files_writable;
+ if (files_writable)
+ {
+ // disk
+ if (disk)
+ {
+ FILE *disk_node = fopen("/sys/power/disk", "w");
+ if (disk_node) {
+ result &= (fputs(disk, disk_node) != EOF);
+ fclose(disk_node);
}
}
- if (written1)
+
+ // mem_sleep
+ if (mem)
{
- FILE *statenode = fopen("/sys/power/state", "w");
- if (statenode != NULL) {
- if (fputs(state, statenode) != EOF) {
- written2 = true;
- }
- if (fclose(statenode) == EOF) {
- // Error!
- }
+ FILE *mem_node = fopen("/sys/power/mem_sleep", "w");
+ if (mem_node) {
+ result &= (fputs(mem, mem_node) != EOF);
+ fclose(mem_node);
}
}
+
+ // state
+ FILE *state_node = fopen("/sys/power/state", "w");
+ if (state_node) {
+ result &= (fputs(state, state_node) != EOF);
+ fclose(state_node);
+ }
}
// create a reply from the message
- reply = dbus_message_new_method_return(msg);
+ DBusMessage *reply = dbus_message_new_method_return(msg);
+ const char* member = dbus_message_get_member(msg);
// add the arguments to the reply
- bool written = written1 && written2;
+ DBusMessageIter args;
dbus_message_iter_init_append(reply, &args);
- if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &written)) {
+ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &result)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_message_iter_append_basic failed\n", member);
return;
}
// send the reply && flush the connection
+ dbus_uint32_t serial = 0;
if (!dbus_connection_send(conn, reply, &serial)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_connection_send failed\n", member);
return;
@@ -786,35 +780,35 @@ 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", "CanFreeze")) {
- reply_CanSetPower(msg, conn, "freeze");
+ reply_CanSetSuspend(msg, conn, "freeze", NULL, NULL);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
- reply_SetPower(msg, conn, "freeze");
+ reply_SetSuspend(msg, conn, "freeze", NULL, NULL);
}
- 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", "CanStandby")) {
+ reply_CanSetSuspend(msg, conn, "standby", NULL, NULL);
}
- 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", "Standby")) {
+ reply_SetSuspend(msg, conn, "standby", NULL, NULL);
}
- else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
- reply_CanSetHibernation(msg, conn, "disk", "platform");
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
+ reply_CanSetSuspend(msg, conn, "mem", NULL, "deep");
}
- else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
- reply_SetHibernation(msg, conn, "disk", "platform");
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) {
+ reply_SetSuspend(msg, conn, "mem", NULL, "deep");
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) {
- reply_CanSetHibernation(msg, conn, "disk", "suspend");
+ reply_CanSetSuspend(msg, conn, "disk", "suspend", NULL);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) {
- reply_SetHibernation(msg, conn, "disk", "suspend");
+ reply_SetSuspend(msg, conn, "disk", "suspend", NULL);
+ }
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
+ reply_CanSetSuspend(msg, conn, "disk", "shutdown", NULL);
+ }
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
+ reply_SetSuspend(msg, conn, "disk", "shutdown", NULL);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
reply_CanSetHibernationMethod(msg, conn);
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 1d8a4280..c636e088 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -3352,8 +3352,9 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
TQFileInfo *dirfi;
TDESystemPowerStateList powerstates;
TDESystemHibernationMethodList hibernationmethods;
- TDESystemHibernationMethod::TDESystemHibernationMethod hibernationmethod =
+ TDESystemHibernationMethod::TDESystemHibernationMethod hibernationmethod =
TDESystemHibernationMethod::Unsupported;
+ TDESystemSuspendModeList suspendmodes;
while ( (dirfi = valuesdirit.current()) != 0 ) {
nodename = dirfi->fileName();
TQFile file( valuesnodename + nodename );
@@ -3372,7 +3373,7 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
powerstates.append(TDESystemPowerState::Freeze);
}
if (line.contains("mem")) {
- powerstates.append(TDESystemPowerState::Suspend);
+ powerstates.append(TDESystemPowerState::Mem);
}
if (line.contains("disk")) {
powerstates.append(TDESystemPowerState::Disk);
@@ -3421,6 +3422,17 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
hibernationmethod = TDESystemHibernationMethod::Test;
}
}
+ if (nodename == "mem_sleep") {
+ if (line.contains("s2idle")) {
+ suspendmodes.append(TDESystemSuspendMode::SuspendToIdle);
+ }
+ if (line.contains("shallow")) {
+ suspendmodes.append(TDESystemSuspendMode::Standby);
+ }
+ if (line.contains("deep")) {
+ suspendmodes.append(TDESystemSuspendMode::SuspendToRAM);
+ }
+ }
if (nodename == "image_size") {
rdevice->internalSetDiskSpaceNeededForHibernation(line.toULong());
}
@@ -3428,11 +3440,17 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
}
++valuesdirit;
}
+ // Suspend-to-RAM requires a combination of 'mem' and 'deep' in two different files
+ if (powerstates.contains(TDESystemPowerState::Mem) &&
+ suspendmodes.contains(TDESystemSuspendMode::SuspendToRAM)) {
+ powerstates.append(TDESystemPowerState::Suspend);
+ powerstates.remove(TDESystemPowerState::Mem);
+ }
// Hibernation and Hybrid Suspend are not real power states, being just two different
// ways of suspending to disk. Since they are very common and it is very convenient to
// treat them as power states, we do so, as other power frameworks also do.
if (powerstates.contains(TDESystemPowerState::Disk) &&
- hibernationmethods.contains(TDESystemHibernationMethod::Platform)) {
+ hibernationmethods.contains(TDESystemHibernationMethod::Shutdown)) {
powerstates.append(TDESystemPowerState::Hibernate);
}
if (powerstates.contains(TDESystemPowerState::Disk) &&
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index b9a0bef9..1e097ca9 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -63,18 +63,10 @@ void TDERootSystemDevice::internalSetPowerStates(TDESystemPowerStateList ps) {
m_powerStates = ps;
}
-TDESystemHibernationMethodList TDERootSystemDevice::hibernationMethods() {
- return m_hibernationMethods;
-}
-
void TDERootSystemDevice::internalSetHibernationMethods(TDESystemHibernationMethodList hm) {
m_hibernationMethods = hm;
}
-TDESystemHibernationMethod::TDESystemHibernationMethod TDERootSystemDevice::hibernationMethod() {
- return m_hibernationMethod;
-}
-
void TDERootSystemDevice::internalSetHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
m_hibernationMethod = hm;
}
@@ -115,11 +107,11 @@ bool TDERootSystemDevice::canSetHibernationMethod() {
return FALSE;
}
-bool TDERootSystemDevice::canStandby() {
+bool TDERootSystemDevice::canFreeze() {
TQString statenode = "/sys/power/state";
int rval = access (statenode.ascii(), W_OK);
if (rval == 0) {
- if (powerStates().contains(TDESystemPowerState::Standby)) {
+ if (powerStates().contains(TDESystemPowerState::Freeze)) {
return TRUE;
}
else {
@@ -131,12 +123,12 @@ bool TDERootSystemDevice::canStandby() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can standby?
+ // can freeze?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanStandby");
+ "CanFreeze");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -148,11 +140,11 @@ bool TDERootSystemDevice::canStandby() {
return FALSE;
}
-bool TDERootSystemDevice::canFreeze() {
+bool TDERootSystemDevice::canStandby() {
TQString statenode = "/sys/power/state";
int rval = access (statenode.ascii(), W_OK);
if (rval == 0) {
- if (powerStates().contains(TDESystemPowerState::Freeze)) {
+ if (powerStates().contains(TDESystemPowerState::Standby)) {
return TRUE;
}
else {
@@ -164,12 +156,12 @@ bool TDERootSystemDevice::canFreeze() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can freeze?
+ // can standby?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanFreeze");
+ "CanStandby");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -294,13 +286,13 @@ bool TDERootSystemDevice::canSuspend() {
return FALSE;
}
-bool TDERootSystemDevice::canHibernate() {
+bool TDERootSystemDevice::canHybridSuspend() {
TQString statenode = "/sys/power/state";
TQString disknode = "/sys/power/disk";
int state_rval = access (statenode.ascii(), W_OK);
int disk_rval = access (disknode.ascii(), W_OK);
if (state_rval == 0 && disk_rval == 0) {
- if (powerStates().contains(TDESystemPowerState::Hibernate)) {
+ if (powerStates().contains(TDESystemPowerState::HybridSuspend)) {
return TRUE;
}
else {
@@ -312,12 +304,12 @@ bool TDERootSystemDevice::canHibernate() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can hibernate?
+ // can hybrid suspend?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
- "CanHibernate");
+ "CanHybridSleep");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return (reply[0].toString() == "yes");
@@ -326,41 +318,8 @@ bool TDERootSystemDevice::canHibernate() {
}
#endif // WITH_LOGINDPOWER
-#ifdef WITH_UPOWER
- {
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- TQT_DBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", dbusConn);
- if (upowerProperties.canSend()) {
- // can hibernate?
- TQValueList<TQT_DBusData> params;
- params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate");
- TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params);
- if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
- return reply[0].toVariant().value.toBool();
- }
- }
- }
- }
-#endif// WITH_UPOWER
-
-#ifdef WITH_DEVKITPOWER
- {
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- TQT_DBusProxy devkitpowerProperties("org.freedesktop.DeviceKit.Power", "/org/freedesktop/DeviceKit/Power", "org.freedesktop.DBus.Properties", dbusConn);
- if (devkitpowerProperties.canSend()) {
- // can hibernate?
- TQValueList<TQT_DBusData> params;
- params << TQT_DBusData::fromString(devkitpowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate");
- TQT_DBusMessage reply = devkitpowerProperties.sendWithReply("Get", params);
- if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
- return reply[0].toVariant().value.toBool();
- }
- }
- }
- }
-#endif// WITH_DEVKITPOWER
+ // No support "hybrid suspend" in org.freedesktop.UPower
+ // No support "hybrid suspend" in org.freedesktop.DeviceKit.Power
#ifdef WITH_HAL
{
@@ -368,17 +327,11 @@ bool TDERootSystemDevice::canHibernate() {
if (dbusConn.isConnected()) {
TQT_DBusProxy halProperties("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device", dbusConn);
if (halProperties.canSend()) {
- // can hibernate?
+ // can hybrid suspend?
TQValueList<TQT_DBusData> params;
TQT_DBusMessage reply;
params.clear();
- params << TQT_DBusData::fromString("power_management.can_hibernate");
- reply = halProperties.sendWithReply("GetPropertyBoolean", params);
- if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
- return reply[0].toBool();
- }
- params.clear();
- params << TQT_DBusData::fromString("power_management.can_suspend_to_disk");
+ params << TQT_DBusData::fromString("power_management.can_suspend_hybrid");
reply = halProperties.sendWithReply("GetPropertyBoolean", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -392,12 +345,12 @@ bool TDERootSystemDevice::canHibernate() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can hibernate?
+ // can hybrid suspend?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanHibernate");
+ "CanHybridSuspend");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -409,13 +362,13 @@ bool TDERootSystemDevice::canHibernate() {
return FALSE;
}
-bool TDERootSystemDevice::canHybridSuspend() {
+bool TDERootSystemDevice::canHibernate() {
TQString statenode = "/sys/power/state";
TQString disknode = "/sys/power/disk";
int state_rval = access (statenode.ascii(), W_OK);
int disk_rval = access (disknode.ascii(), W_OK);
if (state_rval == 0 && disk_rval == 0) {
- if (powerStates().contains(TDESystemPowerState::HybridSuspend)) {
+ if (powerStates().contains(TDESystemPowerState::Hibernate)) {
return TRUE;
}
else {
@@ -427,12 +380,12 @@ bool TDERootSystemDevice::canHybridSuspend() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can hybrid suspend?
+ // can hibernate?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
- "CanHybridSleep");
+ "CanHibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return (reply[0].toString() == "yes");
@@ -441,8 +394,41 @@ bool TDERootSystemDevice::canHybridSuspend() {
}
#endif // WITH_LOGINDPOWER
- // No support "hybrid suspend" in org.freedesktop.UPower
- // No support "hybrid suspend" in org.freedesktop.DeviceKit.Power
+#ifdef WITH_UPOWER
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQT_DBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", dbusConn);
+ if (upowerProperties.canSend()) {
+ // can hibernate?
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate");
+ TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toVariant().value.toBool();
+ }
+ }
+ }
+ }
+#endif// WITH_UPOWER
+
+#ifdef WITH_DEVKITPOWER
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQT_DBusProxy devkitpowerProperties("org.freedesktop.DeviceKit.Power", "/org/freedesktop/DeviceKit/Power", "org.freedesktop.DBus.Properties", dbusConn);
+ if (devkitpowerProperties.canSend()) {
+ // can hibernate?
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromString(devkitpowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate");
+ TQT_DBusMessage reply = devkitpowerProperties.sendWithReply("Get", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toVariant().value.toBool();
+ }
+ }
+ }
+ }
+#endif// WITH_DEVKITPOWER
#ifdef WITH_HAL
{
@@ -450,11 +436,17 @@ bool TDERootSystemDevice::canHybridSuspend() {
if (dbusConn.isConnected()) {
TQT_DBusProxy halProperties("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device", dbusConn);
if (halProperties.canSend()) {
- // can hybrid suspend?
+ // can hibernate?
TQValueList<TQT_DBusData> params;
TQT_DBusMessage reply;
params.clear();
- params << TQT_DBusData::fromString("power_management.can_suspend_hybrid");
+ params << TQT_DBusData::fromString("power_management.can_hibernate");
+ reply = halProperties.sendWithReply("GetPropertyBoolean", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toBool();
+ }
+ params.clear();
+ params << TQT_DBusData::fromString("power_management.can_suspend_to_disk");
reply = halProperties.sendWithReply("GetPropertyBoolean", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -468,12 +460,12 @@ bool TDERootSystemDevice::canHybridSuspend() {
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can hybrid suspend?
+ // can hibernate?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanHybridSuspend");
+ "CanHibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
diff --git a/tdecore/tdehw/tderootsystemdevice.h b/tdecore/tdehw/tderootsystemdevice.h
index 2e866e65..e74d2dcf 100644
--- a/tdecore/tdehw/tderootsystemdevice.h
+++ b/tdecore/tdehw/tderootsystemdevice.h
@@ -43,10 +43,19 @@ enum TDESystemPowerState {
PowerOff,
Reboot,
HybridSuspend,
+ Mem, // Used temporarily to detect suspend-to-RAM capability
Disk // Used temporarily to detect hibernation and hybrid suspend capability
};
};
+namespace TDESystemSuspendMode {
+enum TDESystemSuspendMode {
+ SuspendToIdle, // a.k.a. Freeze
+ Standby,
+ SuspendToRAM // a.k.a. Suspend
+};
+};
+
namespace TDESystemHibernationMethod {
enum TDESystemHibernationMethod {
Unsupported,
@@ -60,6 +69,7 @@ enum TDESystemHibernationMethod {
};
typedef TQValueList<TDESystemPowerState::TDESystemPowerState> TDESystemPowerStateList;
+typedef TQValueList<TDESystemSuspendMode::TDESystemSuspendMode> TDESystemSuspendModeList;
typedef TQValueList<TDESystemHibernationMethod::TDESystemHibernationMethod> TDESystemHibernationMethodList;
class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
@@ -87,16 +97,6 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
TDESystemPowerStateList powerStates();
/**
- * @return a TDESystemHibernationMethodList with all available hibernation methods
- */
- TDESystemHibernationMethodList hibernationMethods();
-
- /**
- * @return a TDESystemHibernationMethod::TDESystemHibernationMethod with the current hibernation method
- */
- TDESystemHibernationMethod::TDESystemHibernationMethod hibernationMethod();
-
- /**
* @return an unsigned long with the number of bytes required to hibernate
*/
unsigned long diskSpaceNeededForHibernation();
@@ -107,14 +107,14 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
bool canSetHibernationMethod();
/**
- * @return TRUE if hardware and permissions allow the system to enter standby, FALSE if not
+ * @return TRUE if hardware and permissions allow the system to enter freeze state, FALSE if not
*/
- bool canStandby();
+ bool canFreeze();
/**
- * @return TRUE if hardware and permissions allow the system to enter freeze state, FALSE if not
+ * @return TRUE if hardware and permissions allow the system to enter standby, FALSE if not
*/
- bool canFreeze();
+ bool canStandby();
/**
* @return TRUE if hardware and permissions allow the system to be suspended, FALSE if not
@@ -122,14 +122,14 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
bool canSuspend();
/**
- * @return TRUE if hardware and permissions allow the system to be hibernated, FALSE if not
+ * @return TRUE if hardware and permissions allow the system to be hybrid suspended, FALSE if not
*/
- bool canHibernate();
+ bool canHybridSuspend();
/**
- * @return TRUE if hardware and permissions allow the system to be hybrid suspended, FALSE if not
+ * @return TRUE if hardware and permissions allow the system to be hibernated, FALSE if not
*/
- bool canHybridSuspend();
+ bool canHibernate();
/**
* @return TRUE if permissions allow the system to be powered down, FALSE if not