Music Hub ..
A session-wide music playback service
state_controller.h
Go to the documentation of this file.
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18#ifndef CORE_UBUNTU_MEDIA_POWER_STATE_CONTROLLER_H_
19#define CORE_UBUNTU_MEDIA_POWER_STATE_CONTROLLER_H_
20
22
23#include <core/property.h>
24
25#include <iosfwd>
26#include <memory>
27
28namespace core
29{
30namespace ubuntu
31{
32namespace media
33{
34namespace power
35{
36// Enumerates all known power states of a display.
37enum class DisplayState
38{
39 // The display is off.
40 off = 0,
41 // The display is on.
42 on = 1
43};
44
45// Enumerates known power states of the system.
46enum class SystemState
47{
48 // Note that callers will be notified of suspend state changes
49 // but may not request this state.
50 suspend = 0,
51 // The Active state will prevent system suspend
52 active = 1,
53 // Substate of Active with disabled proximity based blanking
55};
56
57// Interface that enables observation of the system power state.
59{
60 // To save us some typing.
61 typedef std::shared_ptr<StateController> Ptr;
62
63 // When acquired, ensures that the system stays active,
64 // and decreases the reference count when released.
65 template<typename State>
66 struct Lock
67 {
68 // To save us some typing.
69 typedef std::shared_ptr<Lock> Ptr;
70
71 Lock() = default;
72 virtual ~Lock() = default;
73
74 // Informs the system that the caller would like
75 // the system to stay active.
76 virtual void request_acquire(State state) = 0;
77 // Informs the system that the caller does not
78 // require the system to stay active anymore.
79 virtual void request_release(State state) = 0;
80
81 // Emitted whenever the acquire request completes.
82 virtual const core::Signal<State>& acquired() const = 0;
83 // Emitted whenever the release request completes.
84 virtual const core::Signal<State>& released() const = 0;
85 };
86
87 StateController() = default;
88 virtual ~StateController() = default;
89
90 // Returns a power::StateController::Lock<DisplayState> instance.
92 // Returns a power::StateController::Lock<SystemState> instance.
94};
95
96// Creates a StateController instance that connects to the platform default
97// services to control system and display power states.
99
100// operator<< pretty prints the given display state to the given output stream.
101std::ostream& operator<<(std::ostream& out, DisplayState state);
102// operator<< pretty prints the given system state to the given output stream.
103std::ostream& operator<<(std::ostream& out, SystemState state);
104}
105}
106}
107}
108#endif // CORE_UBUNTU_MEDIA_POWER_STATE_CONTROLLER_H_
std::ostream & operator<<(std::ostream &out, DisplayState state)
StateController::Ptr make_platform_default_state_controller(core::ubuntu::media::helper::ExternalServices &)
Definition: player.h:34
virtual const core::Signal< State > & acquired() const =0
virtual const core::Signal< State > & released() const =0
std::shared_ptr< StateController > Ptr
virtual Lock< SystemState >::Ptr system_state_lock()=0
virtual Lock< DisplayState >::Ptr display_state_lock()=0