summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2018-12-17 02:23:05 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-02-06 23:37:12 +0900
commit841ae5477c24b9740296e4e3cfde211800d92528 (patch)
tree76f48981466bbdc9e5584e21fbf4b691d3ee946c
parent210f8e9691cf9b84504ba2a15676fb1e18ed094e (diff)
downloadtdelibs-841ae5477c24b9740296e4e3cfde211800d92528.tar.gz
tdelibs-841ae5477c24b9740296e4e3cfde211800d92528.zip
Fixed support for logind power state calls.
Fixed bug in tdehw daemon power state code introduced in previous commit. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c85
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp123
2 files changed, 88 insertions, 120 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
index 1975a2d2..f17e9dea 100644
--- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
+++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
@@ -254,7 +254,7 @@ void reply_SetBrightness(DBusMessage* msg, DBusConnection* conn) {
free(safepath);
}
-bool check_CanSetSuspend(char* state, char* disk, char* mem) {
+bool CanSetPowerState(const char* state, const char* disk, const char* mem) {
// check if required files are writable
bool files_writable = (access("/sys/power/state", W_OK) == 0);
if (disk)
@@ -327,7 +327,7 @@ bool check_CanSetSuspend(char* state, char* disk, char* mem) {
return result;
}
-bool do_SetSuspend(char* state, char* disk, char* mem) {
+bool SetPowerState(const char* state, const char* disk, const char* mem) {
// check if required files are writable
bool files_writable = (access("/sys/power/state", W_OK) == 0);
if (disk)
@@ -373,31 +373,6 @@ bool do_SetSuspend(char* state, char* disk, char* mem) {
return result;
}
-void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, bool result) {
- // create a reply from the message
- DBusMessage *reply = dbus_message_new_method_return(msg);
- const char* member = dbus_message_get_member(msg);
-
- // add the arguments to the reply
- DBusMessageIter args;
- dbus_message_iter_init_append(reply, &args);
- 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;
- }
- dbus_connection_flush(conn);
-
- // free the reply
- dbus_message_unref(reply);
-}
-
void reply_CanSetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
// check if path is writable
reply_CanSetGivenPath(msg, conn, "/sys/power/disk");
@@ -778,69 +753,69 @@ void listen() {
reply_SetBrightness(msg, conn);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
- bool result = check_CanSetSuspend("freeze", NULL, NULL) || check_CanSetSuspend("mem", NULL, "s2idle");
+ bool result = CanSetPowerState("freeze", NULL, NULL) || CanSetPowerState("mem", NULL, "s2idle");
reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
bool result = false;
- if (check_CanSetSuspend("freeze", NULL, NULL)) {
- result = do_SetSuspend("freeze", NULL, NULL);
+ if (CanSetPowerState("freeze", NULL, NULL)) {
+ result = SetPowerState("freeze", NULL, NULL);
}
- else if (check_CanSetSuspend("mem", NULL, "s2idle")) {
- result = do_SetSuspend("mem", NULL, "s2idle");
+ else if (CanSetPowerState("mem", NULL, "s2idle")) {
+ result = SetPowerState("mem", NULL, "s2idle");
}
- reply_SetSuspend(msg, conn, result);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) {
- bool result = check_CanSetSuspend("standby", NULL, NULL) || check_CanSetSuspend("mem", NULL, "shallow");
+ bool result = CanSetPowerState("standby", NULL, NULL) || CanSetPowerState("mem", NULL, "shallow");
reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) {
bool result = false;
- if (check_CanSetSuspend("standby", NULL, NULL)) {
- result = do_SetSuspend("standby", NULL, NULL);
+ if (CanSetPowerState("standby", NULL, NULL)) {
+ result = SetPowerState("standby", NULL, NULL);
}
- else if (check_CanSetSuspend("mem", NULL, "shallow")) {
- result = do_SetSuspend("mem", NULL, "shallow");
+ else if (CanSetPowerState("mem", NULL, "shallow")) {
+ result = SetPowerState("mem", NULL, "shallow");
}
- reply_SetSuspend(msg, conn, result);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
- bool result = (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
- check_CanSetSuspend("mem", NULL, "deep");
+ bool result = (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
+ CanSetPowerState("mem", NULL, "deep");
reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) {
bool result = false;
- if (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) {
- result = do_SetSuspend("mem", NULL, NULL);
+ if (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) {
+ result = SetPowerState("mem", NULL, NULL);
}
- else if (check_CanSetSuspend("mem", NULL, "deep")) {
- result = do_SetSuspend("mem", NULL, "deep");
+ else if (CanSetPowerState("mem", NULL, "deep")) {
+ result = SetPowerState("mem", NULL, "deep");
}
- reply_SetSuspend(msg, conn, result);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) {
- bool result = check_CanSetSuspend("disk", "suspend", NULL);
+ bool result = CanSetPowerState("disk", "suspend", NULL);
reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) {
- bool result = do_SetSuspend("disk", "suspend", NULL);
- reply_SetSuspend(msg, conn, result);
+ bool result = SetPowerState("disk", "suspend", NULL);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
- bool result = check_CanSetSuspend("disk", "shutdown", NULL) || check_CanSetSuspend("disk", "platform", NULL);
+ bool result = CanSetPowerState("disk", "shutdown", NULL) || CanSetPowerState("disk", "platform", NULL);
reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
bool result = false;
- if (check_CanSetSuspend("disk", "shutdown", NULL)) {
- result = do_SetSuspend("disk", "shutdown", NULL);
+ if (CanSetPowerState("disk", "shutdown", NULL)) {
+ result = SetPowerState("disk", "shutdown", NULL);
}
- else if (check_CanSetSuspend("disk", "platform", NULL)) {
- result = do_SetSuspend("disk", "platform", NULL);
+ else if (CanSetPowerState("disk", "platform", NULL)) {
+ result = SetPowerState("disk", "platform", NULL);
}
- reply_SetSuspend(msg, conn, result);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
reply_CanSetHibernationMethod(msg, conn);
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index 0b25d8cb..63a16d74 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -644,7 +644,7 @@ void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESy
}
}
-bool check_CanSetSuspend(char* state, char* disk, char* mem) {
+bool CanSetSuspend(const char* state, const char* disk, const char* mem) {
// check if required files are writable
bool files_writable = (access("/sys/power/state", W_OK) == 0);
if (disk)
@@ -723,41 +723,32 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
(ps == TDESystemPowerState::HybridSuspend)) {
#ifdef WITH_LOGINDPOWER
{
- // No support for "freeze" in org.freedesktop.login1
+ // No support for "freeze" and "standby" in org.freedesktop.login1
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
- if (ps == TDESystemPowerState::Suspend) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Suspend");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
+ TQT_DBusProxy logindProxy("org.freedesktop.login1", "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager", dbusConn);
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromBool(true);
+ if (logindProxy.canSend()) {
+ if (ps == TDESystemPowerState::Suspend) {
+ TQT_DBusMessage reply = logindProxy.sendWithReply("Suspend", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
}
- }
- else if (ps == TDESystemPowerState::Hibernate) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Hibernate");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
+ else if (ps == TDESystemPowerState::HybridSuspend) {
+ TQT_DBusMessage reply = logindProxy.sendWithReply("HybridSleep", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
}
- }
- else if (ps == TDESystemPowerState::HybridSuspend) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "HybridSleep");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
+ else if (ps == TDESystemPowerState::Hibernate) {
+ TQT_DBusMessage reply = logindProxy.sendWithReply("Hibernate", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
}
}
}
@@ -766,7 +757,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
#ifdef WITH_UPOWER
{
- // No support for "freeze" and "hybrid suspend" in org.freedesktop.UPower
+ // No support for "freeze", "standby" and "hybrid suspend" in org.freedesktop.UPower
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
@@ -798,7 +789,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
#ifdef WITH_DEVKITPOWER
{
- // No support for "freeze" and "hybrid suspend" in org.freedesktop.DeviceKit.Power
+ // No support for "freeze", "standby" and "hybrid suspend" in org.freedesktop.DeviceKit.Power
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
@@ -830,7 +821,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
#ifdef WITH_HAL
{
- // No support for "freeze" in org.freedesktop.Hal
+ // No support for "freeze" and "standby" in org.freedesktop.Hal
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
@@ -847,17 +838,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true;
}
}
- else if (ps == TDESystemPowerState::Hibernate) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.Hal",
- "/org/freedesktop/Hal/devices/computer",
- "org.freedesktop.Hal.Device.SystemPowerManagement",
- "Hibernate");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
- }
- }
else if (ps == TDESystemPowerState::HybridSuspend) {
TQT_DBusProxy halPowerManagement(
"org.freedesktop.Hal",
@@ -871,6 +851,17 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true;
}
}
+ else if (ps == TDESystemPowerState::Hibernate) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.freedesktop.Hal",
+ "/org/freedesktop/Hal/devices/computer",
+ "org.freedesktop.Hal.Device.SystemPowerManagement",
+ "Hibernate");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
}
}
#endif // WITH_HAL
@@ -952,7 +943,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
bool diskWriteOk = false;
bool memWriteOk = false;
if (ps == TDESystemPowerState::Freeze) {
- if (check_CanSetSuspend("freeze", NULL, NULL)) {
+ if (CanSetSuspend("freeze", NULL, NULL)) {
stateCommand = "freeze";
}
else {
@@ -961,7 +952,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
}
else if (ps == TDESystemPowerState::Standby) {
- if (check_CanSetSuspend("standby", NULL, NULL)) {
+ if (CanSetSuspend("standby", NULL, NULL)) {
stateCommand = "standby";
}
else {
@@ -971,7 +962,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
else if (ps == TDESystemPowerState::Suspend) {
stateCommand = "mem";
- if (check_CanSetSuspend("mem", NULL, "deep")) {
+ if (CanSetSuspend("mem", NULL, "deep")) {
diskCommand = "deep";
}
}
@@ -981,7 +972,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
else if (ps == TDESystemPowerState::Hibernate) {
stateCommand = "disk";
- if (check_CanSetSuspend("disk", "shutdown", NULL)) {
+ if (CanSetSuspend("disk", "shutdown", NULL)) {
diskCommand = "shutdown";
}
else {
@@ -1027,14 +1018,15 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "PowerOff");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
+ TQT_DBusProxy logindProxy("org.freedesktop.login1", "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager", dbusConn);
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromBool(true);
+ if (logindProxy.canSend()) {
+ TQT_DBusMessage reply = logindProxy.sendWithReply("PowerOff", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
}
}
}
@@ -1096,14 +1088,15 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Reboot");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
+ TQT_DBusProxy logindProxy("org.freedesktop.login1", "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager", dbusConn);
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromBool(true);
+ if (logindProxy.canSend()) {
+ TQT_DBusMessage reply = logindProxy.sendWithReply("Reboot", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
}
}
}