1 // SystemStateChangeUPower.hh -- shutdown/suspend/hibernate using systemd-logind
2 //
3 // Copyright (C) 2014 Mateusz Jończyk <mat.jonczyk@o2.pl>
4 // All rights reserved.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 //
20 
21 #ifndef SYSTEMSTATECHANGEUPOWER_HH_
22 #define SYSTEMSTATECHANGEUPOWER_HH_
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include "DBusProxy.hh"
29 
30 #include "ISystemStateChangeMethod.hh"
31 
32 //  - upower:
33 //    - http://upower.freedesktop.org/docs/UPower.html
34 //    - methods: CanSuspend, CanHibernate,
35 //    - these are implemented since a long time ago
36 //    - http://upower.freedesktop.org/docs/KbdBacklight.html
37 //      - control of keyboard backlight, may be usable in addition to dpms
38 //    - we may use libupower, but it is unneccessary
39 
40 
41 class SystemStateChangeUPower : public ISystemStateChangeMethod
42 {
43 public:
44   SystemStateChangeUPower(GDBusConnection *connection);
45   virtual
~SystemStateChangeUPower()46   ~SystemStateChangeUPower() {};
suspend()47   virtual bool suspend() { return execute("Suspend"); }
hibernate()48   virtual bool hibernate() { return execute("Hibernate"); }
49 
canSuspend()50   virtual bool canSuspend() { return can_suspend;}
canHibernate()51   virtual bool canHibernate() { return can_hibernate;}
52 
53   static const char *dbus_name;
54 private:
55   bool check_method(const char *method_name);
56   bool check_property(const char *property_name);
57   bool execute(const char *method_name);
58 
59   bool can_suspend;
60   bool can_hibernate;
61 
62   DBusProxy proxy;
63   DBusProxy property_proxy;
64 };
65 
66 #endif /* SYSTEMSTATECHANGEUPOWER_HH_ */
67