14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#ifndef POWERD_MEDIATOR_
18
#define POWERD_MEDIATOR_
17
#ifndef USC_POWERD_MEDIATOR_H_
18
#define USC_POWERD_MEDIATOR_H_
20
20
#include "screen_hardware.h"
22
#include <mir_toolkit/common.h>
29
#include <condition_variable>
32
class QDBusServiceWatcher;
35
* A Proxy to powerd. Note this class is not thread-safe,
36
* synchronization should be done externally.
38
class PowerdMediator : public QObject, public usc::ScreenHardware
22
#include "dbus_connection_handle.h"
23
#include "dbus_event_loop.h"
27
class DBusMessageHandle;
29
class PowerdMediator : public ScreenHardware
32
PowerdMediator(std::string const& bus_addr);
45
35
void set_dim_backlight() override;
46
36
void set_normal_backlight() override;
47
37
void turn_off_backlight() override;
38
void change_backlight_values(int dim_brightness, int normal_brightness) override;
48
40
void allow_suspend() override;
49
41
void disable_suspend() override;
51
void change_backlight_values(int dim_brightness, int normal_brightness) override;
52
43
void enable_auto_brightness(bool flag) override;
54
44
bool auto_brightness_supported() override;
45
void set_brightness(int brightness) override;
55
46
int min_brightness() override;
56
47
int max_brightness() override;
58
void set_brightness(int brightness) override;
61
void powerd_registered();
62
void powerd_state_changed(int state);
49
bool is_system_suspended();
52
enum class BacklightState
79
void change_backlight_state(BacklightState state, bool force_change = false);
67
enum class ForceDisableSuspend { no, yes };
68
enum class ForceBacklightState { no, yes };
70
static ::DBusHandlerResult handle_dbus_message_thunk(
71
::DBusConnection* connection, ::DBusMessage* message, void* user_data);
73
::DBusHandlerResult handle_dbus_message(
74
::DBusConnection* connection, ::DBusMessage* message, void* user_data);
75
void init_powerd_state(ForceDisableSuspend force_disable_suspend);
80
76
void init_brightness_params();
81
bool request_suspend_blocker();
82
void wait_for_state(SystemState state);
85
int normal_brightness;
86
int current_brightness;
77
void change_backlight_state(
78
BacklightState new_state, ForceBacklightState force_backlight_state);
79
bool is_valid_brightness(int brightness);
80
bool request_suspend_block();
81
void wait_for_sys_state(SysState state);
82
void update_sys_state(SysState state);
83
void update_current_brightness_for_state(BacklightState state);
84
void invoke(char const* method, int first_arg_type, ...);
85
usc::DBusMessageHandle invoke_with_reply(char const* method, int first_arg_type, ...);
87
usc::DBusConnectionHandle connection;
88
usc::DBusEventLoop dbus_event_loop;
89
std::thread dbus_loop_thread;
92
bool pending_suspend_block_request;
87
94
int min_brightness_;
88
95
int max_brightness_;
96
int normal_brightness_;
97
int current_brightness;
98
BacklightState backlight_state;
89
99
bool auto_brightness_supported_;
90
100
bool auto_brightness_requested;
91
BacklightState backlight_state;
93
QString suspend_block_cookie;
94
bool pending_suspend_blocker_request;
96
std::unique_ptr<QDBusInterface> powerd_interface;
97
std::unique_ptr<QDBusServiceWatcher> service_watcher;
99
SystemState system_state;
101
std::mutex system_state_mutex;
102
std::condition_variable state_change;
101
std::string suspend_block_cookie;
102
std::mutex sys_state_mutex;
104
std::condition_variable sys_state_changed;