Merge lp:~thomas-voss/media-hub/introduce-battery-observer-interface into lp:media-hub
- introduce-battery-observer-interface
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Ricardo Mendoza |
Approved revision: | 114 |
Merged at revision: | 120 |
Proposed branch: | lp:~thomas-voss/media-hub/introduce-battery-observer-interface |
Merge into: | lp:media-hub |
Prerequisite: | lp:~thomas-voss/media-hub/introduce-power-controller-interface |
Diff against target: |
378 lines (+213/-90) 5 files modified
src/core/media/CMakeLists.txt (+1/-0) src/core/media/indicator_power_service.h (+0/-74) src/core/media/power/battery_observer.cpp (+127/-0) src/core/media/power/battery_observer.h (+69/-0) src/core/media/service_implementation.cpp (+16/-16) |
To merge this branch: | bzr merge lp:~thomas-voss/media-hub/introduce-battery-observer-interface |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Jim Hodapp (community) | code | Approve | |
Review via email:
|
Commit message
Introduce an interface media::
The core reacts to low/very low battery levels by pausing all multimedia playback sessions and
resumes them whenever the user has been notified of the critical battery level.
Provide an implementation of media::
Adjust media::
Description of the change
Introduce an interface media::
The core reacts to low/very low battery levels by pausing all multimedia playback sessions and
resumes them whenever the user has been notified of the critical battery level.
Provide an implementation of media::
Adjust media::
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
- 107. By Thomas Voß
-
Remerge prereq branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:107
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jim Hodapp (jhodapp) wrote : | # |
This looks great, I really like this particular class abstraction.
- 108. By Thomas Voß
-
[ Jim Hodapp ]
* Resubmitting with prerequisite branch (LP: #1331041)
[ Justin McPherson ]
* Resubmitting with prerequisite branch (LP: #1331041)
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:108
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 109. By Thomas Voß
-
Merge prerequisite branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:109
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 110. By Thomas Voß
-
[ Jim Hodapp ]
* Error reporting all the way up to the app level from the playbin
pipeline.
[ Ubuntu daily release ]
* New rebuild forced
[ Jim Hodapp ]
* Don't auto-resume playback of videos after a phone call ends. (LP:
#1411273)
[ Ubuntu daily release ]
* New rebuild forced
[ Ricardo Salveti de Araujo ]
* service_implementation: adding debug for call started/ended signals.
Make sure account and connection are available when setting up
account manager (patch from Gustavo Boiko). call_monitor: don't
check caps when hooking up on/off signals, until bug 1409125 is
fixed. Enable parallel building . (LP: #1409125)
[ Jim Hodapp ]
* Pause playback when recording begins. (LP: #1398047)
[ Ricardo Salveti de Araujo ]
* call_monitor.cpp: waiting for bridge to be up, and also protecting
the on_change call (LP: #1408137)
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:110
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 111. By Thomas Voß
-
Merge prereq branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:111
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 112. By Thomas Voß
-
Merge prereq branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:112
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 113. By Thomas Voß
-
Merge prereq branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:113
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 114. By Thomas Voß
-
* debian/control:
- Removing pre-depends that are not required
- Bumping standards-version to 3.9.6
[ Ricardo Salveti de Araujo ]
* Migrating tests to use ogg instead of mp3/avi removed:
tests/h264.avi tests/test.mp3 added: tests/test-audio-1. ogg
tests/test-video. ogg tests/test.mp3 renamed: tests/test.ogg =>
tests/test-audio. ogg
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:114
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'src/core/media/CMakeLists.txt' |
2 | --- src/core/media/CMakeLists.txt 2015-03-12 11:43:33 +0000 |
3 | +++ src/core/media/CMakeLists.txt 2015-03-12 11:43:33 +0000 |
4 | @@ -91,6 +91,7 @@ |
5 | cover_art_resolver.cpp |
6 | engine.cpp |
7 | |
8 | + power/battery_observer.cpp |
9 | power/state_controller.cpp |
10 | |
11 | recorder_observer.cpp |
12 | |
13 | === removed file 'src/core/media/indicator_power_service.h' |
14 | --- src/core/media/indicator_power_service.h 2014-09-05 18:59:48 +0000 |
15 | +++ src/core/media/indicator_power_service.h 1970-01-01 00:00:00 +0000 |
16 | @@ -1,74 +0,0 @@ |
17 | -/* |
18 | - * Copyright (C) 2014 Canonical Ltd |
19 | - * |
20 | - * This program is free software: you can redistribute it and/or modify |
21 | - * it under the terms of the GNU Lesser General Public License version 3 as |
22 | - * published by the Free Software Foundation. |
23 | - * |
24 | - * This program is distributed in the hope that it will be useful, |
25 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | - * GNU Lesser General Public License for more details. |
28 | - * |
29 | - * You should have received a copy of the GNU Lesser General Public License |
30 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | - * |
32 | - * Author: Jim Hodapp <jim.hodapp@canonical.com> |
33 | - */ |
34 | - |
35 | -#include <core/dbus/dbus.h> |
36 | -#include <core/dbus/fixture.h> |
37 | -#include <core/dbus/object.h> |
38 | -#include <core/dbus/property.h> |
39 | -#include <core/dbus/service.h> |
40 | -#include <core/dbus/interfaces/properties.h> |
41 | -#include <core/dbus/types/stl/tuple.h> |
42 | -#include <core/dbus/types/stl/vector.h> |
43 | - |
44 | -#include <core/dbus/asio/executor.h> |
45 | - |
46 | -#include <string> |
47 | - |
48 | -namespace core |
49 | -{ |
50 | - |
51 | -struct IndicatorPower |
52 | -{ |
53 | - static std::string& name() |
54 | - { |
55 | - static std::string s = "com.canonical.indicator.power.Battery"; |
56 | - return s; |
57 | - } |
58 | - |
59 | - struct PowerLevel |
60 | - { |
61 | - static std::string name() |
62 | - { |
63 | - static std::string s = "PowerLevel"; |
64 | - return s; |
65 | - } |
66 | - |
67 | - typedef IndicatorPower Interface; |
68 | - // Possible values: "ok", "low", "very_low", "critical" |
69 | - typedef std::string ValueType; |
70 | - static const bool readable = true; |
71 | - static const bool writable = false; |
72 | - }; |
73 | - |
74 | - struct IsWarning |
75 | - { |
76 | - static std::string name() |
77 | - { |
78 | - static std::string s = "IsWarning"; |
79 | - return s; |
80 | - } |
81 | - |
82 | - typedef IndicatorPower Interface; |
83 | - typedef bool ValueType; |
84 | - static const bool readable = true; |
85 | - static const bool writable = false; |
86 | - }; |
87 | - |
88 | -}; // IndicatorPower |
89 | - |
90 | -} |
91 | |
92 | === added file 'src/core/media/power/battery_observer.cpp' |
93 | --- src/core/media/power/battery_observer.cpp 1970-01-01 00:00:00 +0000 |
94 | +++ src/core/media/power/battery_observer.cpp 2015-03-12 11:43:33 +0000 |
95 | @@ -0,0 +1,127 @@ |
96 | +/* |
97 | + * Copyright © 2014 Canonical Ltd. |
98 | + * |
99 | + * This program is free software: you can redistribute it and/or modify it |
100 | + * under the terms of the GNU Lesser General Public License version 3, |
101 | + * as published by the Free Software Foundation. |
102 | + * |
103 | + * This program is distributed in the hope that it will be useful, |
104 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
105 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
106 | + * GNU Lesser General Public License for more details. |
107 | + * |
108 | + * You should have received a copy of the GNU Lesser General Public License |
109 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
110 | + * |
111 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
112 | + */ |
113 | + |
114 | +#include <core/media/power/battery_observer.h> |
115 | + |
116 | +#include <core/dbus/macros.h> |
117 | +#include <core/dbus/object.h> |
118 | +#include <core/dbus/property.h> |
119 | + |
120 | +namespace media = core::ubuntu::media; |
121 | + |
122 | +namespace com { namespace canonical { namespace indicator { namespace power { |
123 | +struct Battery |
124 | +{ |
125 | + static std::string& name() |
126 | + { |
127 | + static std::string s = "com.canonical.indicator.power.Battery"; |
128 | + return s; |
129 | + } |
130 | + |
131 | + static const core::dbus::types::ObjectPath& path() |
132 | + { |
133 | + static core::dbus::types::ObjectPath p{"/com/canonical/indicator/power/Battery"}; |
134 | + return p; |
135 | + } |
136 | + |
137 | + // Possible values: "ok", "low", "very_low", "critical" |
138 | + DBUS_CPP_READABLE_PROPERTY_DEF(PowerLevel, Battery, std::string) |
139 | + DBUS_CPP_READABLE_PROPERTY_DEF(IsWarning, Battery, bool) |
140 | +}; // IndicatorPower |
141 | +}}}} |
142 | + |
143 | +namespace |
144 | +{ |
145 | +namespace impl |
146 | +{ |
147 | +struct BatteryObserver : public media::power::BatteryObserver |
148 | +{ |
149 | + static core::ubuntu::media::power::Level power_level_from_string(const std::string& s) |
150 | + { |
151 | + static const std::map<std::string, core::ubuntu::media::power::Level> lut = |
152 | + { |
153 | + {"ok", core::ubuntu::media::power::Level::ok}, |
154 | + {"low", core::ubuntu::media::power::Level::low}, |
155 | + {"very_low", core::ubuntu::media::power::Level::very_low}, |
156 | + {"critical", core::ubuntu::media::power::Level::critical} |
157 | + }; |
158 | + |
159 | + if (lut.count(s) == 0) |
160 | + return core::ubuntu::media::power::Level::unknown; |
161 | + |
162 | + return lut.at(s); |
163 | + } |
164 | + |
165 | + BatteryObserver(const core::dbus::Object::Ptr& object) |
166 | + : object{object}, |
167 | + properties |
168 | + { |
169 | + core::Property<core::ubuntu::media::power::Level>{core::ubuntu::media::power::Level::unknown}, |
170 | + object->get_property<com::canonical::indicator::power::Battery::PowerLevel>(), |
171 | + object->get_property<com::canonical::indicator::power::Battery::IsWarning>(), |
172 | + }, |
173 | + connections |
174 | + { |
175 | + properties.power_level->changed().connect([this](const std::string& value) |
176 | + { |
177 | + properties.typed_power_level = BatteryObserver::power_level_from_string(value); |
178 | + }) |
179 | + } |
180 | + { |
181 | + } |
182 | + |
183 | + const core::Property<core::ubuntu::media::power::Level>& level() const override |
184 | + { |
185 | + return properties.typed_power_level; |
186 | + } |
187 | + |
188 | + const core::Property<bool>& is_warning_active() const override |
189 | + { |
190 | + return *properties.is_warning; |
191 | + } |
192 | + |
193 | + // The object representing the remote indicator instance. |
194 | + core::dbus::Object::Ptr object; |
195 | + // All properties go here. |
196 | + struct |
197 | + { |
198 | + // We have to translate from the raw strings coming in via the bus to |
199 | + // the strongly typed enumeration exposed via the interface. |
200 | + core::Property<core::ubuntu::media::power::Level> typed_power_level; |
201 | + std::shared_ptr<core::dbus::Property<com::canonical::indicator::power::Battery::PowerLevel>> power_level; |
202 | + |
203 | + std::shared_ptr<core::dbus::Property<com::canonical::indicator::power::Battery::IsWarning>> is_warning; |
204 | + } properties; |
205 | + // Our event connections |
206 | + struct |
207 | + { |
208 | + core::ScopedConnection power_level; |
209 | + } connections; |
210 | + |
211 | +}; |
212 | +} |
213 | +} |
214 | + |
215 | +media::power::BatteryObserver::Ptr media::power::make_platform_default_battery_observer(media::helper::ExternalServices& es) |
216 | +{ |
217 | + auto service = core::dbus::Service::use_service<com::canonical::indicator::power::Battery>(es.session); |
218 | + auto object = service->object_for_path(com::canonical::indicator::power::Battery::path()); |
219 | + |
220 | + return std::make_shared<impl::BatteryObserver>(object); |
221 | +} |
222 | + |
223 | |
224 | === added file 'src/core/media/power/battery_observer.h' |
225 | --- src/core/media/power/battery_observer.h 1970-01-01 00:00:00 +0000 |
226 | +++ src/core/media/power/battery_observer.h 2015-03-12 11:43:33 +0000 |
227 | @@ -0,0 +1,69 @@ |
228 | +/* |
229 | + * Copyright © 2014 Canonical Ltd. |
230 | + * |
231 | + * This program is free software: you can redistribute it and/or modify it |
232 | + * under the terms of the GNU Lesser General Public License version 3, |
233 | + * as published by the Free Software Foundation. |
234 | + * |
235 | + * This program is distributed in the hope that it will be useful, |
236 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
237 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
238 | + * GNU Lesser General Public License for more details. |
239 | + * |
240 | + * You should have received a copy of the GNU Lesser General Public License |
241 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
242 | + * |
243 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
244 | + */ |
245 | +#ifndef CORE_UBUNTU_MEDIA_POWER_STATE_OBSERVER_H_ |
246 | +#define CORE_UBUNTU_MEDIA_POWER_STATE_OBSERVER_H_ |
247 | + |
248 | +#include <core/media/external_services.h> |
249 | + |
250 | +#include <core/property.h> |
251 | + |
252 | +#include <memory> |
253 | + |
254 | +namespace core |
255 | +{ |
256 | +namespace ubuntu |
257 | +{ |
258 | +namespace media |
259 | +{ |
260 | +namespace power |
261 | +{ |
262 | +// Enumerates known power levels. |
263 | +enum class Level |
264 | +{ |
265 | + unknown, |
266 | + ok, |
267 | + low, |
268 | + very_low, |
269 | + critical |
270 | +}; |
271 | + |
272 | +// Interface that enables observation of the system power state. |
273 | +struct BatteryObserver |
274 | +{ |
275 | + // To safe us some typing. |
276 | + typedef std::shared_ptr<BatteryObserver> Ptr; |
277 | + |
278 | + BatteryObserver() = default; |
279 | + virtual ~BatteryObserver() = default; |
280 | + |
281 | + // A getable/observable property reporting the current power-level |
282 | + // of the system. |
283 | + virtual const core::Property<Level>& level() const = 0; |
284 | + // A getable/observable property indicating whether a power-level |
285 | + // warning is currently presented to the user. |
286 | + virtual const core::Property<bool>& is_warning_active() const = 0; |
287 | +}; |
288 | + |
289 | +// Creates a BatteryObserver instance that connects to the platform default |
290 | +// services to observe battery levels. |
291 | +core::ubuntu::media::power::BatteryObserver::Ptr make_platform_default_battery_observer(core::ubuntu::media::helper::ExternalServices&); |
292 | +} |
293 | +} |
294 | +} |
295 | +} |
296 | +#endif // CORE_UBUNTU_MEDIA_POWER_STATE_OBSERVER_H_ |
297 | |
298 | === modified file 'src/core/media/service_implementation.cpp' |
299 | --- src/core/media/service_implementation.cpp 2015-03-12 11:43:33 +0000 |
300 | +++ src/core/media/service_implementation.cpp 2015-03-12 11:43:33 +0000 |
301 | @@ -23,10 +23,11 @@ |
302 | #include "service_implementation.h" |
303 | |
304 | #include "client_death_observer.h" |
305 | -#include "indicator_power_service.h" |
306 | #include "call-monitor/call_monitor.h" |
307 | #include "player_configuration.h" |
308 | #include "player_implementation.h" |
309 | +#include "power/battery_observer.h" |
310 | +#include "power/state_controller.h" |
311 | #include "recorder_observer.h" |
312 | |
313 | #include <boost/asio.hpp> |
314 | @@ -51,6 +52,7 @@ |
315 | Private(const ServiceImplementation::Configuration& configuration) |
316 | : configuration(configuration), |
317 | resume_key(std::numeric_limits<std::uint32_t>::max()), |
318 | + battery_observer(media::power::make_platform_default_battery_observer(configuration.external_services)), |
319 | power_state_controller(media::power::make_platform_default_state_controller(configuration.external_services)), |
320 | display_state_lock(power_state_controller->display_state_lock()), |
321 | client_death_observer(media::platform_default_client_death_observer()), |
322 | @@ -122,14 +124,7 @@ |
323 | return false; |
324 | }); |
325 | })); |
326 | - |
327 | - // Connect the property change signal that will allow media-hub to take appropriate action |
328 | - // when the battery level reaches critical |
329 | - auto stub_service = dbus::Service::use_service(configuration.external_services.session, "com.canonical.indicator.power"); |
330 | - indicator_power_session = stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/indicator/power/Battery")); |
331 | - power_level = indicator_power_session->get_property<core::IndicatorPower::PowerLevel>(); |
332 | - is_warning = indicator_power_session->get_property<core::IndicatorPower::IsWarning>(); |
333 | - |
334 | + |
335 | recorder_observer->recording_state().changed().connect([this](media::RecordingState state) |
336 | { |
337 | media_recording_state_changed(state); |
338 | @@ -411,9 +406,7 @@ |
339 | // This holds the key of the multimedia role Player instance that was paused |
340 | // when the battery level reached 10% or 5% |
341 | media::Player::PlayerKey resume_key; |
342 | - std::shared_ptr<dbus::Object> indicator_power_session; |
343 | - std::shared_ptr<core::dbus::Property<core::IndicatorPower::PowerLevel>> power_level; |
344 | - std::shared_ptr<core::dbus::Property<core::IndicatorPower::IsWarning>> is_warning; |
345 | + media::power::BatteryObserver::Ptr battery_observer; |
346 | media::power::StateController::Ptr power_state_controller; |
347 | media::power::StateController::Lock<media::power::DisplayState>::Ptr display_state_lock; |
348 | media::ClientDeathObserver::Ptr client_death_observer; |
349 | @@ -440,19 +433,26 @@ |
350 | |
351 | media::ServiceImplementation::ServiceImplementation(const Configuration& configuration) : d(new Private(configuration)) |
352 | { |
353 | - d->power_level->changed().connect([this](const core::IndicatorPower::PowerLevel::ValueType &level) |
354 | + d->battery_observer->level().changed().connect([this](const media::power::Level& level) |
355 | { |
356 | // When the battery level hits 10% or 5%, pause all multimedia sessions. |
357 | // Playback will resume when the user clears the presented notification. |
358 | - if (level == "low" || level == "very_low") |
359 | + switch (level) |
360 | + { |
361 | + case media::power::Level::low: |
362 | + case media::power::Level::very_low: |
363 | pause_all_multimedia_sessions(); |
364 | + break; |
365 | + default: |
366 | + break; |
367 | + } |
368 | }); |
369 | |
370 | - d->is_warning->changed().connect([this](const core::IndicatorPower::IsWarning::ValueType ¬ifying) |
371 | + d->battery_observer->is_warning_active().changed().connect([this](bool active) |
372 | { |
373 | // If the low battery level notification is no longer being displayed, |
374 | // resume what the user was previously playing |
375 | - if (!notifying) |
376 | + if (!active) |
377 | resume_multimedia_session(); |
378 | }); |
379 |
FAILED: Continuous integration, rev:106 jenkins. qa.ubuntu. com/job/ media-hub- ci/182/ jenkins. qa.ubuntu. com/job/ media-hub- vivid-amd64- ci/22/console jenkins. qa.ubuntu. com/job/ media-hub- vivid-armhf- ci/22/console jenkins. qa.ubuntu. com/job/ media-hub- vivid-i386- ci/22/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/media- hub-ci/ 182/rebuild
http://