xbmc/xbmc — pull request #2971 by mus65 (2013-07-14 12:46:11+00:00)
Title: [Linux] systemd/UPower power management improvements

This patch improves the power management functionality
on Linux systems running systemd and optionally UPower.

The SystemdUPowerSyscall class does not inherit
from the UPowerSyscall class anymore. The little
functionality needed by UPower is implemented separately
in the rewritten class. I originally extended the existing
class, but this resulted in pretty messy code.

Advantages:
- The power management functionality provided by systemd/logind
now works even when UPower is not available on the system. Previously
nothing would work without UPower, even though UPower provided nothing
but the battery level. The complete suspend/poweroff etc.
functionality is provided by logind itself and does not rely on
UPower anymore. The class itself checks whether UPower is available,
and if not, avoids any battery related operations.

- As mentioned, the suspend functionality by UPower is not used anymore.
This is also important because this functionality is being deprecated:
see http://lists.freedesktop.org/archives/devkit-devel/2013-January/001339.html

- The OnSleep()/OnWake() callbacks now actually work. This was at least
broken on systemd systems since the corresponding UPower signals
were never even emitted. This is now properly handled via
logind inhibitor locks, so the system doesn't suspend until
XBMC is finished with whatever it is doing with the callback.
Although the fact that no one noticed this makes me wonder how
useful these callbacks actually are?!
see also http://www.freedesktop.org/wiki/Software/systemd/inhibit/

- The code is imho cleaner since I don't keep a complete copy of the
UPower devices within the class. Instead the Battery Level is
re-read via D-Bus everytime UPower emits a DeviceChanged signal.
UPower seems to emit this signal every 30 seconds while idle. I originally only
re-read the data everytime the BatteryLevel() function is called since
this doesn't seem to happen that often. However, I don't know if there
are cases in which this function may be called very often or how
much overhead D-Bus would actually cause in this case. Either way,
this could easily be changed.

I made no changes to the other implementations, so this should not have
any effects on non-systemd, or to be exact, non-logind systems.