This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Power Management Inhibit in 4.8.3

Tags: None
(comma "," separated)
jgmtfi
Registered Member
Posts
3
Karma
0
OS

Power Management Inhibit in 4.8.3

Tue Jun 26, 2012 3:41 pm
I am looking for a way to temporary inhibit power management from the command line in 4.8.3. Google tells me that solutions like the following should work:

Code: Select all
qdbus org.freedesktop.PowerManagement.Inhibit /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.Inhibit 'firefox' 'Test'

When I run this command, it returns an incrementing value, leading me to believe it is keeping tack of the inhibit request... however the power management feature is not inhibited - it continues to operate normally.

The other potential solution is to toggle between power profiles as needed, however that also does not seem to work.

Code: Select all
qdbus org.kde.kded /org/kde/Solid/PowerManagement loadProfile "On Battery"

Which returns nothing, even when a undefined power management profile string is used
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
For the loadProfile D-Bus command, it takes a boolean value. I am not aware unfortunately of what it does, however it is not likely to change the profile which is loaded.

For the Inhibit issue, I will need to check with the Powerdevil sources as to the precise behaviour involved. I suspect it may be listening for D-Bus disconnections and terminating the inhibitions of applications which quit.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
jgmtfi
Registered Member
Posts
3
Karma
0
OS
bcooksley wrote:For the Inhibit issue, I will need to check with the Powerdevil sources as to the precise behaviour involved. I suspect it may be listening for D-Bus disconnections and terminating the inhibitions of applications which quit.

Funny you should mention that... I found a script yesterday at http://lists.exherbo.org/pipermail/paludis-user/2011-April/001705.html which uses python to make the inhibit call, and then sleeps until terminated... A simplified version of this is:

Code: Select all
#!/usr/bin/python

import dbus
import time
import signal, sys

if len(sys.argv) != 3 :
  sys.stderr.write('Usage: pm-inhibit.py <appname> <reason>\n')
  sys.exit(1)

bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
devobj = bus.get_object('org.freedesktop.PowerManagement', '/org/freedesktop/PowerManagement/Inhibit')
dev = dbus.Interface (devobj, "org.freedesktop.PowerManagement.Inhibit")
cookie = dev.Inhibit(sys.argv[1], sys.argv[2])

while 1 == 1 :
        time.sleep(30)

As fast as I can tell, this code works as well, as HasInhibit is set to true as long as the python script is running. Unfortunately, the inhibit is still not honored by the power management feature in 4.8.3. I'll go try to find the code for powerdevil next.

When running:
Code: Select all
nfsseed:~$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit  org.freedesktop.PowerManagement.Inhibit.HasInhibit
true

When terminated:
Code: Select all
nfsseed:~$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit  org.freedesktop.PowerManagement.Inhibit.HasInhibit
false
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I have checked the PowerDevil code. As it turns out - it takes a limited definition of inhibition - only actions which interrupt are prohibited.

Any action involving the screen needs to be inhibited via a different method.
Please see qdbus org.kde.kded /org/kde/Solid/PowerManagement/PolicyAgent

To fully inhibit everything, you need to make three calls to addInhibit, passing a different value as the integer each time. Their values need to be: 1 (InterruptSession), 2 (ChangeProfile) and 4 (ChangeScreenSettings). 3 does not exist.

The two QString values are appname and reason as you have done above.
Something like the following should work in Python I imagine:

Code: Select all
devobj = bus.get_object('org.kde.kded', '/org/kde/Solid/PowerManagement/PolicyAgent')
dev = dbus.Interface (devobj, "org.kde.Solid.PowerManagement.PolicyAgent")
cookie1 = dev.AddInhibition(1, sys.argv[1], sys.argv[2])
cookie2 = dev.AddInhibition(2, sys.argv[1], sys.argv[2])
cookie3 = dev.AddInhibition(4, sys.argv[1], sys.argv[2])


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
jgmtfi
Registered Member
Posts
3
Karma
0
OS
bcooksley wrote:I have checked the PowerDevil code. As it turns out - it takes a limited definition of inhibition - only actions which interrupt are prohibited.

While I am unclear on the reasoning behind the underlying approach shown above, this solution worked! I am grateful for your assistance. I did get a chance to look though the powerdevil code briefly and it was clear that it would take some time to figure out as I am new to KDE and QT. I will pass this info on to the mythtv community as well in case it helps someone else out.

For those reading this thread, note that you have to run the above scripts in a terminal with access to the display you wish to control. I found that I needed to

(a) as the user running the KDE session, execute a "xhost +" call to allow access to the session (you can limit access to localhost only if you like).
(b) needed to run script with DISPLAY prefix
(c) the script needs to run until the inhibit is no longer required

For mythtv, I will probably use the system event triggers to leave a flag which another script will looked for, and in turn inhibit the power management.
Code: Select all
#!/usr/bin/python

import dbus
import time
import signal, sys

if len(sys.argv) != 3 :
  sys.stderr.write('Usage: pm-inhibit.py <appname> <reason>\n')
  sys.exit(1)

bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
devobj = bus.get_object('org.kde.kded', '/org/kde/Solid/PowerManagement/PolicyAgent')
dev = dbus.Interface (devobj, "org.kde.Solid.PowerManagement.PolicyAgent")
cookie1 = dev.AddInhibition(1, sys.argv[1], sys.argv[2])
cookie2 = dev.AddInhibition(2, sys.argv[1], sys.argv[2])
cookie3 = dev.AddInhibition(4, sys.argv[1], sys.argv[2])

while 1 == 1 :
        time.sleep(30)

Invoke with
Code: Select all
DISPLAY=:0 ./script.py mythtv running


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], Sogou [Bot]