Improved detection of available options for

freeze/standby/suspend/hybrid suspend/hibernate when udev is not
available.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
feat/fix-suspend-code
Michele Calgaro 6 years ago
parent cebadfa114
commit 0c6b1db799
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -123,9 +123,6 @@ bool TDERootSystemDevice::canFreeze() {
if (powerStates().contains(TDESystemPowerState::Freeze)) { if (powerStates().contains(TDESystemPowerState::Freeze)) {
return TRUE; return TRUE;
} }
else {
return FALSE;
}
} }
#ifdef WITH_TDEHWLIB_DAEMONS #ifdef WITH_TDEHWLIB_DAEMONS
@ -156,9 +153,6 @@ bool TDERootSystemDevice::canStandby() {
if (powerStates().contains(TDESystemPowerState::Standby)) { if (powerStates().contains(TDESystemPowerState::Standby)) {
return TRUE; return TRUE;
} }
else {
return FALSE;
}
} }
#ifdef WITH_TDEHWLIB_DAEMONS #ifdef WITH_TDEHWLIB_DAEMONS
@ -189,10 +183,25 @@ bool TDERootSystemDevice::canSuspend() {
if (powerStates().contains(TDESystemPowerState::Suspend)) { if (powerStates().contains(TDESystemPowerState::Suspend)) {
return TRUE; return TRUE;
} }
else { }
return FALSE;
#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
#ifdef WITH_LOGINDPOWER #ifdef WITH_LOGINDPOWER
{ {
@ -274,16 +283,30 @@ bool TDERootSystemDevice::canSuspend() {
} }
#endif // WITH_HAL #endif // WITH_HAL
return FALSE;
}
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::HybridSuspend)) {
return TRUE;
}
}
#ifdef WITH_TDEHWLIB_DAEMONS #ifdef WITH_TDEHWLIB_DAEMONS
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
// can suspend? // can hybrid suspend?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall( TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol", "org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol", "/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power", "org.trinitydesktop.hardwarecontrol.Power",
"CanSuspend"); "CanHybridSuspend");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool(); return reply[0].toBool();
@ -292,23 +315,6 @@ bool TDERootSystemDevice::canSuspend() {
} }
#endif // WITH_TDEHWLIB_DAEMONS #endif // WITH_TDEHWLIB_DAEMONS
return FALSE;
}
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::HybridSuspend)) {
return TRUE;
}
else {
return FALSE;
}
}
#ifdef WITH_LOGINDPOWER #ifdef WITH_LOGINDPOWER
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@ -350,16 +356,30 @@ bool TDERootSystemDevice::canHybridSuspend() {
} }
#endif // WITH_HAL #endif // WITH_HAL
return FALSE;
}
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::Hibernate)) {
return TRUE;
}
}
#ifdef WITH_TDEHWLIB_DAEMONS #ifdef WITH_TDEHWLIB_DAEMONS
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
// can hybrid suspend? // can hibernate?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall( TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol", "org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol", "/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power", "org.trinitydesktop.hardwarecontrol.Power",
"CanHybridSuspend"); "CanHibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool(); return reply[0].toBool();
@ -368,23 +388,6 @@ bool TDERootSystemDevice::canHybridSuspend() {
} }
#endif // WITH_TDEHWLIB_DAEMONS #endif // WITH_TDEHWLIB_DAEMONS
return FALSE;
}
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::Hibernate)) {
return TRUE;
}
else {
return FALSE;
}
}
#ifdef WITH_LOGINDPOWER #ifdef WITH_LOGINDPOWER
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@ -465,24 +468,6 @@ bool TDERootSystemDevice::canHibernate() {
} }
#endif // WITH_HAL #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; return FALSE;
} }
@ -744,6 +729,9 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
TQString stateCommand = TQString::null; TQString stateCommand = TQString::null;
TQString diskCommand = TQString::null; TQString diskCommand = TQString::null;
TQString memCommand = TQString::null; TQString memCommand = TQString::null;
bool stateWriteOk = false;
bool diskWriteOk = false;
bool memWriteOk = false;
if (ps == TDESystemPowerState::Freeze) { if (ps == TDESystemPowerState::Freeze) {
if (check_CanSetSuspend("freeze", NULL, NULL)) { if (check_CanSetSuspend("freeze", NULL, NULL)) {
stateCommand = "freeze"; stateCommand = "freeze";
@ -782,22 +770,94 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
} }
} }
memWriteOk = (memCommand == TQString::null);
if (memCommand != TQString::null && memfile.open( IO_WriteOnly )) { if (memCommand != TQString::null && memfile.open( IO_WriteOnly )) {
memWriteOk = true;
TQTextStream memstream( &memfile ); TQTextStream memstream( &memfile );
memstream << memCommand; memstream << memCommand;
memfile.close(); memfile.close();
} }
if (diskCommand != TQString::null && diskfile.open( IO_WriteOnly )) { if (memWriteOk) {
TQTextStream diskstream( &diskfile ); diskWriteOk = (diskCommand == TQString::null);
diskstream << diskCommand; if (diskCommand != TQString::null && diskfile.open( IO_WriteOnly )) {
diskfile.close(); diskWriteOk = true;
TQTextStream diskstream( &diskfile );
diskstream << diskCommand;
diskfile.close();
}
if (diskWriteOk) {
if (stateCommand != TQString::null && statefile.open( IO_WriteOnly )) {
TQTextStream statestream( &statefile );
statestream << stateCommand;
statefile.close();
return true;
}
}
} }
if (stateCommand != TQString::null && statefile.open( IO_WriteOnly )) {
TQTextStream statestream( &statefile ); #ifdef WITH_TDEHWLIB_DAEMONS
statestream << stateCommand; {
statefile.close(); TQT_DBusConnection dbusConn;
return true; dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
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::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::HybridSuspend) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
"HybridSuspend");
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
#ifdef WITH_LOGINDPOWER #ifdef WITH_LOGINDPOWER
{ {
@ -953,70 +1013,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
} }
#endif // WITH_HAL #endif // WITH_HAL
#ifdef WITH_TDEHWLIB_DAEMONS
{
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
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::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::HybridSuspend) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
"HybridSuspend");
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; return false;
} }
else if (ps == TDESystemPowerState::PowerOff) { else if (ps == TDESystemPowerState::PowerOff) {

Loading…
Cancel
Save