summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2013-09-29 01:39:40 +0200
committerSlávek Banko <[email protected]>2013-09-29 01:42:48 +0200
commitd8d925203ed90f3c1ca93145e9364cfb854d2789 (patch)
tree4bab0e8460093a626d3f28b50cb9c53560249950
parentea75e7f6173f214c197abd580b53b5ef09e49856 (diff)
downloadtdelibs-d8d925203ed90f3c1ca93145e9364cfb854d2789.tar.gz
tdelibs-d8d925203ed90f3c1ca93145e9364cfb854d2789.zip
Add SetHibernationMethod to tdehwlib-daemon
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c46
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp57
2 files changed, 100 insertions, 3 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
index 6b3a5dc30..d00f06eb5 100644
--- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
+++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
@@ -286,6 +286,37 @@ void reply_SetPower(DBusMessage* msg, DBusConnection* conn, char* state) {
reply_SetGivenPath(msg, conn, "/sys/power/state", state);
}
+void reply_CanSetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
+
+ // check if path is writable
+ reply_CanSetGivenPath(msg, conn, "/sys/power/disk");
+}
+
+void reply_SetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
+ DBusMessageIter args;
+ const char* member = dbus_message_get_member(msg);
+ char* method = NULL;
+
+ // read the arguments
+ if (!dbus_message_iter_init(msg, &args)) {
+ fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member);
+ }
+ else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
+ fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not string\n", member);
+ }
+ else {
+ dbus_message_iter_get_basic(&args, &method);
+ }
+
+ // set hibernation method
+ if (method) {
+ reply_SetGivenPath(msg, conn, "/sys/power/disk", method);
+ }
+ else {
+ reply_Bool(msg, conn, false);
+ }
+}
+
void signal_NameAcquired(DBusMessage* msg) {
DBusMessageIter args;
char *name = NULL;
@@ -301,7 +332,7 @@ void reply_Introspect(DBusMessage* msg, DBusConnection* conn) {
DBusMessage* reply;
DBusMessageIter args;
dbus_uint32_t serial = 0;
- size_t size = 2048;
+ size_t size = 4096;
const char* member = dbus_message_get_member(msg);
const char *path = dbus_message_get_path(msg);
char *data = malloc(size);
@@ -374,6 +405,13 @@ void reply_Introspect(DBusMessage* msg, DBusConnection* conn) {
" <method name=\"Hibernate\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n"
+ " <method name=\"CanSetHibernationMethod\">\n"
+ " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
+ " </method>\n"
+ " <method name=\"SetHibernationMethod\">\n"
+ " <arg name=\"method\" direction=\"in\" type=\"s\" />\n"
+ " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
+ " </method>\n"
" </interface>\n",
size-strlen(data));
}
@@ -511,6 +549,12 @@ void listen() {
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
reply_SetPower(msg, conn, "disk");
}
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
+ reply_CanSetHibernationMethod(msg, conn);
+ }
+ else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "SetHibernationMethod")) {
+ reply_SetHibernationMethod(msg, conn);
+ }
else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired")) {
signal_NameAcquired(msg);
}
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index 488c60e2b..b62f07ddd 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -103,9 +103,26 @@ bool TDERootSystemDevice::canSetHibernationMethod() {
if (rval == 0) {
return TRUE;
}
- else {
- return FALSE;
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can set hibernation method?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanSetHibernationMethod");
+ 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::canStandby() {
@@ -495,7 +512,43 @@ void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESy
TQTextStream stream( &file );
stream << hibernationCommand;
file.close();
+ return;
}
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Power", dbusConn);
+ if (hardwareControl.canSend()) {
+ // set hibernation method
+ TQValueList<TQT_DBusData> params;
+ TQString hibernationCommand;
+ if (hm == TDESystemHibernationMethod::Platform) {
+ hibernationCommand = "platform";
+ }
+ if (hm == TDESystemHibernationMethod::Shutdown) {
+ hibernationCommand = "shutdown";
+ }
+ if (hm == TDESystemHibernationMethod::Reboot) {
+ hibernationCommand = "reboot";
+ }
+ if (hm == TDESystemHibernationMethod::TestProc) {
+ hibernationCommand = "testproc";
+ }
+ if (hm == TDESystemHibernationMethod::Test) {
+ hibernationCommand = "test";
+ }
+ params << TQT_DBusData::fromString(hibernationCommand);
+ TQT_DBusMessage reply = hardwareControl.sendWithReply("SetHibernationMethod", params);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return;
+ }
+ }
+ }
+ }
+#endif // WITH_TDEHWLIB_DAEMONS
+
}
bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) {