~alan-griffiths/unity-system-compositor/use-WindowMangager-NOT-ShellWrapper

« back to all changes in this revision

Viewing changes to src/unity_screen_service.h

Introduce UnityScreenService and tests.

Approved by PS Jenkins bot, Kevin DuBois.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef USC_UNITY_SCREEN_SERVICE_H_
 
20
#define USC_UNITY_SCREEN_SERVICE_H_
 
21
 
 
22
#include "dbus_event_loop.h"
 
23
#include "dbus_connection_handle.h"
 
24
 
 
25
#include <mir_toolkit/common.h>
 
26
 
 
27
#include <cstdint>
 
28
#include <memory>
 
29
#include <thread>
 
30
#include <atomic>
 
31
#include <mutex>
 
32
#include <unordered_map>
 
33
 
 
34
enum class PowerStateChangeReason;
 
35
 
 
36
namespace usc
 
37
{
 
38
class Screen;
 
39
class WorkerThread;
 
40
 
 
41
class UnityScreenService
 
42
{
 
43
public:
 
44
    UnityScreenService(
 
45
        std::string const& bus_addr,
 
46
        std::shared_ptr<usc::Screen> const& screen);
 
47
    ~UnityScreenService();
 
48
 
 
49
private:
 
50
    void dbus_loop();
 
51
    void stop_loop();
 
52
    static ::DBusHandlerResult handle_dbus_message_thunk(
 
53
        DBusConnection* connection, DBusMessage* message, void* user_data);
 
54
    ::DBusHandlerResult handle_dbus_message(
 
55
        DBusConnection* connection, DBusMessage* message, void* user_data);
 
56
 
 
57
    void dbus_setUserBrightness(int32_t brightness);
 
58
    void dbus_userAutobrightnessEnable(dbus_bool_t enable);
 
59
    void dbus_setInactivityTimeouts(int32_t poweroff_timeout, int32_t dimmer_timeout);
 
60
    void dbus_setTouchVisualizationEnabled(dbus_bool_t enable);
 
61
    bool dbus_setScreenPowerMode(std::string const& mode, int32_t reason);
 
62
    int32_t dbus_keepDisplayOn(std::string const& sender);
 
63
    void dbus_removeDisplayOnRequest(std::string const& sender, int32_t id);
 
64
    void dbus_NameOwnerChanged(
 
65
        std::string const& name,
 
66
        std::string const& old_owner,
 
67
        std::string const& new_owner);
 
68
    void dbus_emit_DisplayPowerStateChange(
 
69
        MirPowerMode power_mode, PowerStateChangeReason reason);
 
70
 
 
71
    DBusConnectionHandle const connection;
 
72
    std::shared_ptr<usc::Screen> const screen;
 
73
 
 
74
    DBusEventLoop dbus_event_loop;
 
75
    std::thread dbus_loop_thread;
 
76
    std::mutex keep_display_on_mutex;
 
77
    std::unordered_multimap<std::string,int32_t> keep_display_on_ids;
 
78
    int32_t request_id;
 
79
};
 
80
 
 
81
}
 
82
 
 
83
#endif