~unity-system-compositor-team/unity-system-compositor/trunk

« back to all changes in this revision

Viewing changes to src/powerd_mediator.h

  • Committer: Tarmac
  • Author(s): Alexandros Frantzis
  • Date: 2015-04-28 06:59:14 UTC
  • mfrom: (203.2.7 powerd-mediator)
  • Revision ID: tarmac-20150428065914-y1hs68oib8m0nzpy
Reimplement PowerdMediator without Qt. Fixes: https://bugs.launchpad.net/bugs/1389187.

Approved by Alberto Aguirre, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright © 2014-2015 Canonical Ltd.
 
2
 * Copyright © 2015 Canonical Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License version 3 as
14
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 */
16
16
 
17
 
#ifndef POWERD_MEDIATOR_
18
 
#define POWERD_MEDIATOR_
 
17
#ifndef USC_POWERD_MEDIATOR_H_
 
18
#define USC_POWERD_MEDIATOR_H_
19
19
 
20
20
#include "screen_hardware.h"
21
21
 
22
 
#include <mir_toolkit/common.h>
23
 
 
24
 
#include <QString>
25
 
#include <QObject>
26
 
 
27
 
#include <memory>
28
 
#include <mutex>
29
 
#include <condition_variable>
30
 
 
31
 
class QDBusInterface;
32
 
class QDBusServiceWatcher;
33
 
 
34
 
/*
35
 
 * A Proxy to powerd. Note this class is not thread-safe,
36
 
 * synchronization should be done externally.
37
 
 */
38
 
class PowerdMediator : public QObject, public usc::ScreenHardware
39
 
{
40
 
    Q_OBJECT
 
22
#include "dbus_connection_handle.h"
 
23
#include "dbus_event_loop.h"
 
24
 
 
25
namespace usc
 
26
{
 
27
class DBusMessageHandle;
 
28
 
 
29
class PowerdMediator : public ScreenHardware
 
30
{
41
31
public:
42
 
    PowerdMediator();
 
32
    PowerdMediator(std::string const& bus_addr);
43
33
    ~PowerdMediator();
44
34
 
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;
 
39
 
48
40
    void allow_suspend() override;
49
41
    void disable_suspend() override;
50
42
 
51
 
    void change_backlight_values(int dim_brightness, int normal_brightness) override;
52
43
    void enable_auto_brightness(bool flag) override;
53
 
 
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;
57
48
 
58
 
    void set_brightness(int brightness) override;
59
 
 
60
 
private Q_SLOTS:
61
 
    void powerd_registered();
62
 
    void powerd_state_changed(int state);
 
49
    bool is_system_suspended();
63
50
 
64
51
private:
65
 
    enum BacklightState
 
52
    enum class BacklightState
66
53
    {
67
54
        off,
68
55
        dim,
70
57
        automatic
71
58
    };
72
59
 
73
 
    enum SystemState
 
60
    enum class SysState
74
61
    {
75
62
        unknown = -1,
76
 
        suspended = 0,
 
63
        suspend = 0,
77
64
        active,
78
65
    };
79
 
    void change_backlight_state(BacklightState state, bool force_change = false);
 
66
 
 
67
    enum class ForceDisableSuspend { no, yes };
 
68
    enum class ForceBacklightState { no, yes };
 
69
 
 
70
    static ::DBusHandlerResult handle_dbus_message_thunk(
 
71
        ::DBusConnection* connection, ::DBusMessage* message, void* user_data);
 
72
 
 
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);
83
 
 
84
 
    int dim_brightness;
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, ...);
 
86
 
 
87
    usc::DBusConnectionHandle connection;
 
88
    usc::DBusEventLoop dbus_event_loop;
 
89
    std::thread dbus_loop_thread;
 
90
 
 
91
    std::mutex mutex;
 
92
    bool pending_suspend_block_request;
 
93
    int dim_brightness_;
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;
92
 
 
93
 
    QString suspend_block_cookie;
94
 
    bool pending_suspend_blocker_request;
95
 
 
96
 
    std::unique_ptr<QDBusInterface> powerd_interface;
97
 
    std::unique_ptr<QDBusServiceWatcher> service_watcher;
98
 
 
99
 
    SystemState system_state;
100
 
 
101
 
    std::mutex system_state_mutex;
102
 
    std::condition_variable state_change;
 
101
    std::string suspend_block_cookie;
 
102
    std::mutex sys_state_mutex;
 
103
    SysState sys_state;
 
104
    std::condition_variable sys_state_changed;
103
105
};
 
106
 
 
107
}
 
108
 
104
109
#endif