Merge lp:unity-system-compositor/0.3 into lp:unity-system-compositor/ubuntu
- 0.3
- Merge into ubuntu
Proposed by
Alexandros Frantzis
Status: | Merged |
---|---|
Approved by: | Alexandros Frantzis |
Approved revision: | 268 |
Merged at revision: | 227 |
Proposed branch: | lp:unity-system-compositor/0.3 |
Merge into: | lp:unity-system-compositor/ubuntu |
Diff against target: |
2303 lines (+1048/-398) 39 files modified
CMakeLists.txt (+3/-2) debian/changelog (+31/-0) spinner/eglspinner.cpp (+5/-2) src/CMakeLists.txt (+1/-0) src/dbus_connection_handle.cpp (+2/-2) src/dbus_connection_handle.h (+3/-1) src/dbus_connection_thread.cpp (+5/-11) src/dbus_connection_thread.h (+3/-7) src/dbus_event_loop.cpp (+32/-18) src/dbus_event_loop.h (+4/-2) src/mir_input_configuration.cpp (+129/-14) src/mir_input_configuration.h (+34/-11) src/powerd_mediator.cpp (+6/-6) src/powerd_mediator.h (+1/-1) src/screen_event_handler.cpp (+23/-4) src/screen_event_handler.h (+1/-0) src/server.cpp (+17/-4) src/server.h (+3/-0) src/system_compositor.cpp (+2/-0) src/system_compositor.h (+2/-0) src/unity_input_service.cpp (+11/-13) src/unity_input_service.h (+6/-3) src/unity_screen_service.cpp (+11/-9) src/unity_screen_service.h (+5/-3) tests/include/usc/test/mock_input_configuration.h (+48/-0) tests/include/usc/test/mock_screen.h (+57/-0) tests/integration-tests/CMakeLists.txt (+3/-0) tests/integration-tests/test_dbus_event_loop.cpp (+8/-8) tests/integration-tests/test_powerd_mediator.cpp (+7/-6) tests/integration-tests/test_unity_input_service.cpp (+11/-119) tests/integration-tests/test_unity_screen_service.cpp (+12/-147) tests/integration-tests/test_unity_services.cpp (+82/-0) tests/integration-tests/unity_input_dbus_client.cpp (+113/-0) tests/integration-tests/unity_input_dbus_client.h (+52/-0) tests/integration-tests/unity_screen_dbus_client.cpp (+112/-0) tests/integration-tests/unity_screen_dbus_client.h (+54/-0) tests/unit-tests/CMakeLists.txt (+1/-0) tests/unit-tests/test_mir_input_configuration.cpp (+114/-0) tests/unit-tests/test_screen_event_handler.cpp (+34/-5) |
To merge this branch: | bzr merge lp:unity-system-compositor/0.3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity System Compositor Development Team | Pending | ||
Review via email: mp+283517@code.launchpad.net |
Commit message
Release 0.3.1
Description of the change
Release 0.3.1
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2015-12-01 13:53:20 +0000 |
3 | +++ CMakeLists.txt 2016-01-21 17:48:37 +0000 |
4 | @@ -16,8 +16,8 @@ |
5 | |
6 | project(UnitySystemCompositor) |
7 | set(USC_VERSION_MAJOR 0) |
8 | -set(USC_VERSION_MINOR 2) |
9 | -set(USC_VERSION_PATCH 0) |
10 | +set(USC_VERSION_MINOR 3) |
11 | +set(USC_VERSION_PATCH 1) |
12 | set(USC_VERSION "${USC_VERSION_MAJOR}.${USC_VERSION_MINOR}.${USC_VERSION_PATCH}") |
13 | |
14 | cmake_minimum_required(VERSION 2.8) |
15 | @@ -57,6 +57,7 @@ |
16 | |
17 | if (MIR_ENABLE_TESTS) |
18 | find_package(Gtest REQUIRED) |
19 | + include_directories(${MIRCLIENT_INCLUDE_DIRS} ) |
20 | include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR}) |
21 | add_subdirectory(tests/) |
22 | endif () |
23 | |
24 | === modified file 'debian/changelog' |
25 | --- debian/changelog 2015-12-16 22:44:39 +0000 |
26 | +++ debian/changelog 2016-01-21 17:48:37 +0000 |
27 | @@ -1,3 +1,34 @@ |
28 | +unity-system-compositor (0.3.1+16.04.20160121-0ubuntu1) xenial; urgency=medium |
29 | + |
30 | + [ Alexandros Frantzis ] |
31 | + * Unblank the screen when a pointer or key event arrives. (LP: #1488413) |
32 | + |
33 | + [ Andreas Pokorny ] |
34 | + * Implement a DBus interface for setting pointer speed/acceleration. |
35 | + (LP: #1536383) |
36 | + |
37 | + -- Alexandros Frantzis <alexandros.frantzis@canonical.com> Thu, 21 Jan 2016 19:27:33 +0200 |
38 | + |
39 | +unity-system-compositor (0.2.0+16.04.20151222.1-0ubuntu1) xenial; urgency=medium |
40 | + |
41 | + [ Alexandros Frantzis ] |
42 | + * tests: Fix build failure with gcc-4.9 |
43 | + |
44 | + [ Andrea Cimitan ] |
45 | + * Updated wallpaper for spinner from unity8. |
46 | + |
47 | + [ Andreas Pokorny ] |
48 | + * Add clone method to StubdisplayConfigurations |
49 | + * Change keyboard handling to scan codes. (LP: #1514059, #1520422) |
50 | + * do not premultiply RGB images |
51 | + * follow the deprecation warning and use tobytes instead of tostring. |
52 | + |
53 | + [ Kevin DuBois ] |
54 | + * Accommodate RGB images (LP: #1528279) |
55 | + * Accommodate RGB images (LP: #1528279) |
56 | + |
57 | + -- Kevin DuBois <kevin.dubois@canonical.com> Tue, 22 Dec 2015 19:09:40 +0000 |
58 | + |
59 | unity-system-compositor (0.2.0+16.04.20151216.1-0ubuntu1) xenial; urgency=medium |
60 | |
61 | [ Alexandros Frantzis ] |
62 | |
63 | === modified file 'spinner/eglspinner.cpp' |
64 | --- spinner/eglspinner.cpp 2015-06-30 12:04:53 +0000 |
65 | +++ spinner/eglspinner.cpp 2016-01-21 17:48:37 +0000 |
66 | @@ -150,14 +150,17 @@ |
67 | void uploadTexture (GLuint id, Image& image) |
68 | { |
69 | glBindTexture(GL_TEXTURE_2D, id); |
70 | + GLint format = GL_RGBA; |
71 | + if (image.bytes_per_pixel == 3) |
72 | + format = GL_RGB; |
73 | |
74 | glTexImage2D(GL_TEXTURE_2D, |
75 | 0, |
76 | - GL_RGBA, |
77 | + format, |
78 | image.width, |
79 | image.height, |
80 | 0, |
81 | - GL_RGBA, |
82 | + format, |
83 | GL_UNSIGNED_BYTE, |
84 | image.pixel_data); |
85 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
86 | |
87 | === modified file 'src/CMakeLists.txt' |
88 | --- src/CMakeLists.txt 2015-08-29 14:38:35 +0000 |
89 | +++ src/CMakeLists.txt 2016-01-21 17:48:37 +0000 |
90 | @@ -72,6 +72,7 @@ |
91 | ${Boost_INCLUDE_DIRS} |
92 | ${GLESv2_INCLUDE_DIRS} |
93 | ${MIRSERVER_INCLUDE_DIRS} |
94 | + ${MIRCLIENT_INCLUDE_DIRS} |
95 | ${DBUS_INCLUDE_DIRS} |
96 | ) |
97 | add_definitions( |
98 | |
99 | === modified file 'src/dbus_connection_handle.cpp' |
100 | --- src/dbus_connection_handle.cpp 2015-03-18 12:20:58 +0000 |
101 | +++ src/dbus_connection_handle.cpp 2016-01-21 17:48:37 +0000 |
102 | @@ -22,12 +22,12 @@ |
103 | #include <stdexcept> |
104 | #include <boost/throw_exception.hpp> |
105 | |
106 | -usc::DBusConnectionHandle::DBusConnectionHandle(const char* address) |
107 | +usc::DBusConnectionHandle::DBusConnectionHandle(std::string const& address) |
108 | { |
109 | dbus_threads_init_default(); |
110 | ScopedDBusError error; |
111 | |
112 | - connection = dbus_connection_open_private(address, &error); |
113 | + connection = dbus_connection_open_private(address.c_str(), &error); |
114 | if (!connection || error) |
115 | { |
116 | BOOST_THROW_EXCEPTION( |
117 | |
118 | === modified file 'src/dbus_connection_handle.h' |
119 | --- src/dbus_connection_handle.h 2015-03-17 18:17:14 +0000 |
120 | +++ src/dbus_connection_handle.h 2016-01-21 17:48:37 +0000 |
121 | @@ -21,13 +21,15 @@ |
122 | |
123 | #include <dbus/dbus.h> |
124 | |
125 | +#include <string> |
126 | + |
127 | namespace usc |
128 | { |
129 | |
130 | class DBusConnectionHandle |
131 | { |
132 | public: |
133 | - DBusConnectionHandle(char const* address); |
134 | + DBusConnectionHandle(std::string const& address); |
135 | ~DBusConnectionHandle(); |
136 | |
137 | void request_name(char const* name) const; |
138 | |
139 | === modified file 'src/dbus_connection_thread.cpp' |
140 | --- src/dbus_connection_thread.cpp 2015-08-25 14:27:23 +0000 |
141 | +++ src/dbus_connection_thread.cpp 2016-01-21 17:48:37 +0000 |
142 | @@ -17,11 +17,10 @@ |
143 | */ |
144 | |
145 | #include "dbus_connection_thread.h" |
146 | +#include "dbus_event_loop.h" |
147 | #include "thread_name.h" |
148 | |
149 | -usc::DBusConnectionThread::DBusConnectionThread(std::string const& address) |
150 | - : dbus_connection{address.c_str()}, |
151 | - dbus_event_loop{dbus_connection} |
152 | +usc::DBusConnectionThread::DBusConnectionThread(std::shared_ptr<DBusEventLoop> const& loop) : dbus_event_loop(loop) |
153 | { |
154 | std::promise<void> event_loop_started; |
155 | auto event_loop_started_future = event_loop_started.get_future(); |
156 | @@ -30,7 +29,7 @@ |
157 | [this,&event_loop_started] |
158 | { |
159 | usc::set_thread_name("USC/DBus"); |
160 | - dbus_event_loop.run(event_loop_started); |
161 | + dbus_event_loop->run(event_loop_started); |
162 | }); |
163 | |
164 | event_loop_started_future.wait(); |
165 | @@ -38,16 +37,11 @@ |
166 | |
167 | usc::DBusConnectionThread::~DBusConnectionThread() |
168 | { |
169 | - dbus_event_loop.stop(); |
170 | + dbus_event_loop->stop(); |
171 | dbus_loop_thread.join(); |
172 | } |
173 | |
174 | -usc::DBusConnectionHandle const& usc::DBusConnectionThread::connection() const |
175 | -{ |
176 | - return dbus_connection; |
177 | -} |
178 | - |
179 | usc::DBusEventLoop & usc::DBusConnectionThread::loop() |
180 | { |
181 | - return dbus_event_loop; |
182 | + return *dbus_event_loop; |
183 | } |
184 | |
185 | === modified file 'src/dbus_connection_thread.h' |
186 | --- src/dbus_connection_thread.h 2015-08-25 14:27:23 +0000 |
187 | +++ src/dbus_connection_thread.h 2016-01-21 17:48:37 +0000 |
188 | @@ -19,25 +19,21 @@ |
189 | #ifndef USC_DBUS_CONNECTION_THREAD_H_ |
190 | #define USC_DBUS_CONNECTION_THREAD_H_ |
191 | |
192 | -#include "dbus_connection_handle.h" |
193 | -#include "dbus_event_loop.h" |
194 | - |
195 | #include <thread> |
196 | |
197 | namespace usc |
198 | { |
199 | |
200 | +class DBusEventLoop; |
201 | class DBusConnectionThread |
202 | { |
203 | public: |
204 | - DBusConnectionThread(std::string const& address); |
205 | + DBusConnectionThread(std::shared_ptr<DBusEventLoop> const& thread); |
206 | ~DBusConnectionThread(); |
207 | - DBusConnectionHandle const& connection() const; |
208 | DBusEventLoop & loop(); |
209 | |
210 | private: |
211 | - DBusConnectionHandle dbus_connection; |
212 | - DBusEventLoop dbus_event_loop; |
213 | + std::shared_ptr<DBusEventLoop> dbus_event_loop; |
214 | std::thread dbus_loop_thread; |
215 | }; |
216 | |
217 | |
218 | === modified file 'src/dbus_event_loop.cpp' |
219 | --- src/dbus_event_loop.cpp 2015-03-18 12:20:58 +0000 |
220 | +++ src/dbus_event_loop.cpp 2016-01-21 17:48:37 +0000 |
221 | @@ -21,6 +21,7 @@ |
222 | #endif |
223 | |
224 | #include "dbus_event_loop.h" |
225 | +#include "dbus_connection_handle.h" |
226 | |
227 | #include <algorithm> |
228 | |
229 | @@ -78,9 +79,8 @@ |
230 | |
231 | } |
232 | |
233 | -usc::DBusEventLoop::DBusEventLoop(DBusConnection* connection) |
234 | - : connection{connection}, |
235 | - running{false}, |
236 | +usc::DBusEventLoop::DBusEventLoop() |
237 | + : running{false}, |
238 | epoll_fd{epoll_create1(EPOLL_CLOEXEC)} |
239 | { |
240 | if (epoll_fd == -1) |
241 | @@ -109,9 +109,17 @@ |
242 | BOOST_THROW_EXCEPTION( |
243 | std::system_error(errno, std::system_category(), "epoll_ctl")); |
244 | } |
245 | +} |
246 | + |
247 | +void usc::DBusEventLoop::add_connection(std::shared_ptr<DBusConnectionHandle> const& connection) |
248 | +{ |
249 | + if (running) |
250 | + BOOST_THROW_EXCEPTION(std::logic_error("Connection added after dbus event loop started")); |
251 | + |
252 | + connections.push_back(connection); |
253 | |
254 | dbus_connection_set_watch_functions( |
255 | - connection, |
256 | + *connection, |
257 | DBusEventLoop::static_add_watch, |
258 | DBusEventLoop::static_remove_watch, |
259 | DBusEventLoop::static_toggle_watch, |
260 | @@ -119,7 +127,7 @@ |
261 | nullptr); |
262 | |
263 | dbus_connection_set_timeout_functions( |
264 | - connection, |
265 | + *connection, |
266 | DBusEventLoop::static_add_timeout, |
267 | DBusEventLoop::static_remove_timeout, |
268 | DBusEventLoop::static_toggle_timeout, |
269 | @@ -127,7 +135,7 @@ |
270 | nullptr); |
271 | |
272 | dbus_connection_set_wakeup_main_function( |
273 | - connection, |
274 | + *connection, |
275 | DBusEventLoop::static_wake_up_loop, |
276 | this, nullptr); |
277 | } |
278 | @@ -136,14 +144,17 @@ |
279 | { |
280 | stop(); |
281 | |
282 | - dbus_connection_set_watch_functions( |
283 | - connection, nullptr, nullptr, nullptr, nullptr, nullptr); |
284 | - |
285 | - dbus_connection_set_timeout_functions( |
286 | - connection, nullptr, nullptr, nullptr, nullptr, nullptr); |
287 | - |
288 | - dbus_connection_set_wakeup_main_function( |
289 | - connection, nullptr, nullptr, nullptr); |
290 | + for(auto connection : connections) |
291 | + { |
292 | + dbus_connection_set_watch_functions( |
293 | + *connection, nullptr, nullptr, nullptr, nullptr, nullptr); |
294 | + |
295 | + dbus_connection_set_timeout_functions( |
296 | + *connection, nullptr, nullptr, nullptr, nullptr, nullptr); |
297 | + |
298 | + dbus_connection_set_wakeup_main_function( |
299 | + *connection, nullptr, nullptr, nullptr); |
300 | + } |
301 | } |
302 | |
303 | void usc::DBusEventLoop::run(std::promise<void>& started) |
304 | @@ -187,14 +198,17 @@ |
305 | |
306 | dispatch_actions(); |
307 | |
308 | - dbus_connection_flush(connection); |
309 | + for (auto connection : connections) |
310 | + { |
311 | + dbus_connection_flush(*connection); |
312 | |
313 | - while (dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) |
314 | - continue; |
315 | + while (dbus_connection_dispatch(*connection) == DBUS_DISPATCH_DATA_REMAINS); |
316 | + } |
317 | } |
318 | |
319 | // Flush any remaining outgoing messages |
320 | - dbus_connection_flush(connection); |
321 | + for (auto connection : connections) |
322 | + dbus_connection_flush(*connection); |
323 | } |
324 | |
325 | void usc::DBusEventLoop::stop() |
326 | |
327 | === modified file 'src/dbus_event_loop.h' |
328 | --- src/dbus_event_loop.h 2015-03-18 11:56:28 +0000 |
329 | +++ src/dbus_event_loop.h 2016-01-21 17:48:37 +0000 |
330 | @@ -30,13 +30,15 @@ |
331 | |
332 | namespace usc |
333 | { |
334 | +class DBusConnectionHandle; |
335 | |
336 | class DBusEventLoop |
337 | { |
338 | public: |
339 | - DBusEventLoop(DBusConnection* connection); |
340 | + DBusEventLoop(); |
341 | ~DBusEventLoop(); |
342 | |
343 | + void add_connection(std::shared_ptr<DBusConnectionHandle> const& connection); |
344 | void run(std::promise<void>& started); |
345 | void stop(); |
346 | |
347 | @@ -70,10 +72,10 @@ |
348 | static void static_toggle_timeout(DBusTimeout* timeout, void* data); |
349 | static void static_wake_up_loop(void* data); |
350 | |
351 | - DBusConnection* const connection; |
352 | std::atomic<bool> running; |
353 | |
354 | std::mutex mutex; |
355 | + std::vector<std::shared_ptr<DBusConnectionHandle>> connections; |
356 | std::vector<DBusWatch*> watches; |
357 | std::vector<std::pair<DBusTimeout*,mir::Fd>> timeouts; |
358 | std::vector<std::function<void(void)>> actions; |
359 | |
360 | === modified file 'src/mir_input_configuration.cpp' |
361 | --- src/mir_input_configuration.cpp 2015-08-26 08:26:35 +0000 |
362 | +++ src/mir_input_configuration.cpp 2016-01-21 17:48:37 +0000 |
363 | @@ -15,58 +15,173 @@ |
364 | */ |
365 | |
366 | #include "mir_input_configuration.h" |
367 | - |
368 | -// just a stub at the moment, this implementation will be supposed to |
369 | -// observe available input devices and apply settings to it. |
370 | - |
371 | +#include "mir/input/input_device_observer.h" |
372 | +#include "mir/input/input_device_hub.h" |
373 | +#include "mir/input/pointer_configuration.h" |
374 | +#include "mir/input/touchpad_configuration.h" |
375 | +#include "mir/input/device.h" |
376 | + |
377 | +namespace mi = mir::input; |
378 | + |
379 | +namespace |
380 | +{ |
381 | +struct DeviceObserver : mi::InputDeviceObserver |
382 | +{ |
383 | + usc::MirInputConfiguration* conf; |
384 | + DeviceObserver(usc::MirInputConfiguration* conf) |
385 | + : conf{conf} |
386 | + { |
387 | + } |
388 | + |
389 | + void device_added(std::shared_ptr<mi::Device> const& device) override |
390 | + { |
391 | + conf->device_added(device); |
392 | + } |
393 | + |
394 | + void device_changed(std::shared_ptr<mi::Device> const&) override |
395 | + { |
396 | + } |
397 | + |
398 | + void device_removed(std::shared_ptr<mi::Device> const&device) override |
399 | + { |
400 | + conf->device_removed(device); |
401 | + } |
402 | + |
403 | + void changes_complete() override |
404 | + { |
405 | + } |
406 | +}; |
407 | +} |
408 | + |
409 | + |
410 | +usc::MirInputConfiguration::MirInputConfiguration(std::shared_ptr<mi::InputDeviceHub> const& device_hub) : |
411 | + observer{std::make_shared<DeviceObserver>(this)} |
412 | +{ |
413 | + device_hub->add_observer(observer); |
414 | +} |
415 | + |
416 | +void usc::MirInputConfiguration::device_removed(std::shared_ptr<mi::Device> const& dev) |
417 | +{ |
418 | + std::lock_guard<decltype(devices_lock)> lock(devices_lock); |
419 | + touchpads.erase(dev); |
420 | + mice.erase(dev); |
421 | +} |
422 | + |
423 | +void usc::MirInputConfiguration::configure_mouse(mi::Device& dev) |
424 | +{ |
425 | + dev.apply_pointer_configuration(mouse_pointer_config); |
426 | +} |
427 | + |
428 | +void usc::MirInputConfiguration::configure_touchpad(mi::Device& dev) |
429 | +{ |
430 | + dev.apply_pointer_configuration(touchpad_pointer_config); |
431 | + dev.apply_touchpad_configuration(touchpad_config); |
432 | +} |
433 | + |
434 | +void usc::MirInputConfiguration::device_added(std::shared_ptr<mi::Device> const& dev) |
435 | +{ |
436 | + std::lock_guard<decltype(devices_lock)> lock(devices_lock); |
437 | + |
438 | + if (contains(dev->capabilities(), mi::DeviceCapability::touchpad)) |
439 | + { |
440 | + touchpads.insert(dev); |
441 | + configure_touchpad(*dev); |
442 | + } |
443 | + else if (contains(dev->capabilities(), mi::DeviceCapability::pointer)) |
444 | + { |
445 | + mice.insert(dev); |
446 | + configure_mouse(*dev); |
447 | + } |
448 | +} |
449 | + |
450 | +void usc::MirInputConfiguration::update_touchpads() |
451 | +{ |
452 | + for (auto const& touchpad : touchpads) |
453 | + configure_touchpad(*touchpad); |
454 | +} |
455 | + |
456 | +void usc::MirInputConfiguration::update_mice() |
457 | +{ |
458 | + for (auto const& mouse : mice) |
459 | + configure_mouse(*mouse); |
460 | +} |
461 | |
462 | void usc::MirInputConfiguration::set_mouse_primary_button(int32_t button) |
463 | { |
464 | - mouse_primary_button = button; |
465 | + mouse_pointer_config.handedness = button == 0 ? |
466 | + mir_pointer_handedness_right : |
467 | + mir_pointer_handedness_left; |
468 | + update_mice(); |
469 | } |
470 | |
471 | void usc::MirInputConfiguration::set_mouse_cursor_speed(double speed) |
472 | { |
473 | - mouse_cursor_speed = speed; |
474 | + double clamped = speed; |
475 | + if (clamped < 0.0) |
476 | + clamped = 0.0; |
477 | + if (clamped > 1.0) |
478 | + clamped = 1.0; |
479 | + mouse_pointer_config.cursor_acceleration_bias = clamped * 2.0 - 1.0; |
480 | + update_mice(); |
481 | } |
482 | |
483 | void usc::MirInputConfiguration::set_mouse_scroll_speed(double speed) |
484 | { |
485 | - mouse_scroll_speed = speed; |
486 | + mouse_pointer_config.horizontal_scroll_scale = speed; |
487 | + mouse_pointer_config.vertical_scroll_scale = speed; |
488 | + update_mice(); |
489 | } |
490 | |
491 | void usc::MirInputConfiguration::set_touchpad_primary_button(int32_t button) |
492 | { |
493 | - touchpad_primary_button = button; |
494 | + touchpad_pointer_config.handedness = button == 0?mir_pointer_handedness_right:mir_pointer_handedness_left; |
495 | + update_touchpads(); |
496 | } |
497 | |
498 | void usc::MirInputConfiguration::set_touchpad_cursor_speed(double speed) |
499 | { |
500 | - touchpad_cursor_speed = speed; |
501 | + double clamped = speed; |
502 | + if (clamped < 0.0) |
503 | + clamped = 0.0; |
504 | + if (clamped > 1.0) |
505 | + clamped = 1.0; |
506 | + touchpad_pointer_config.cursor_acceleration_bias = clamped * 2.0 - 1.0; |
507 | + update_touchpads(); |
508 | } |
509 | |
510 | void usc::MirInputConfiguration::set_touchpad_scroll_speed(double speed) |
511 | { |
512 | - touchpad_scroll_speed = speed; |
513 | + touchpad_pointer_config.horizontal_scroll_scale = speed; |
514 | + touchpad_pointer_config.vertical_scroll_scale = speed; |
515 | + update_touchpads(); |
516 | } |
517 | |
518 | void usc::MirInputConfiguration::set_two_finger_scroll(bool enable) |
519 | { |
520 | - two_finger_scroll = enable; |
521 | + MirTouchpadScrollModes current = touchpad_config.scroll_mode; |
522 | + if (enable) |
523 | + current |= mir_touchpad_scroll_mode_two_finger_scroll; |
524 | + else |
525 | + current &= ~mir_touchpad_scroll_mode_two_finger_scroll; |
526 | + touchpad_config.scroll_mode = current; |
527 | + update_touchpads(); |
528 | } |
529 | |
530 | void usc::MirInputConfiguration::set_tap_to_click(bool enable) |
531 | { |
532 | - tap_to_click = enable; |
533 | + touchpad_config.tap_to_click = enable; |
534 | + update_touchpads(); |
535 | } |
536 | |
537 | void usc::MirInputConfiguration::set_disable_touchpad_while_typing(bool enable) |
538 | { |
539 | - disable_while_typing = enable; |
540 | + touchpad_config.disable_while_typing = enable; |
541 | + update_touchpads(); |
542 | } |
543 | |
544 | void usc::MirInputConfiguration::set_disable_touchpad_with_mouse(bool enable) |
545 | { |
546 | - disable_with_mouse = enable; |
547 | + touchpad_config.disable_with_mouse = enable; |
548 | + update_touchpads(); |
549 | } |
550 | |
551 | |
552 | === modified file 'src/mir_input_configuration.h' |
553 | --- src/mir_input_configuration.h 2015-08-26 08:26:35 +0000 |
554 | +++ src/mir_input_configuration.h 2016-01-21 17:48:37 +0000 |
555 | @@ -14,18 +14,36 @@ |
556 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
557 | */ |
558 | |
559 | - |
560 | #ifndef USC_MIR_INPUT_CONFIGRATION_H_ |
561 | #define USC_MIR_INPUT_CONFIGRATION_H_ |
562 | |
563 | #include "input_configuration.h" |
564 | |
565 | +#include "mir/input/touchpad_configuration.h" |
566 | +#include "mir/input/pointer_configuration.h" |
567 | + |
568 | +#include <memory> |
569 | +#include <thread> |
570 | +#include <mutex> |
571 | +#include <unordered_set> |
572 | + |
573 | +namespace mir |
574 | +{ |
575 | +namespace input |
576 | +{ |
577 | +class InputDeviceHub; |
578 | +class Device; |
579 | +class InputDeviceObserver; |
580 | +} |
581 | +} |
582 | + |
583 | namespace usc |
584 | { |
585 | |
586 | struct MirInputConfiguration : InputConfiguration |
587 | { |
588 | public: |
589 | + MirInputConfiguration(std::shared_ptr<mir::input::InputDeviceHub> const& device_hub); |
590 | void set_mouse_primary_button(int32_t button) override; |
591 | void set_mouse_cursor_speed(double speed) override; |
592 | void set_mouse_scroll_speed(double speed) override; |
593 | @@ -36,17 +54,22 @@ |
594 | void set_tap_to_click(bool enable) override; |
595 | void set_disable_touchpad_while_typing(bool enable) override; |
596 | void set_disable_touchpad_with_mouse(bool enable) override; |
597 | + |
598 | + void device_added(std::shared_ptr<mir::input::Device> const& device); |
599 | + void device_removed(std::shared_ptr<mir::input::Device> const& device); |
600 | private: |
601 | - int32_t mouse_primary_button{0}; |
602 | - double mouse_cursor_speed{0.5}; |
603 | - double mouse_scroll_speed{0.5}; |
604 | - int32_t touchpad_primary_button{0}; |
605 | - double touchpad_cursor_speed{0.5}; |
606 | - double touchpad_scroll_speed{0.5}; |
607 | - bool two_finger_scroll{false}; |
608 | - bool tap_to_click{false}; |
609 | - bool disable_while_typing{false}; |
610 | - bool disable_with_mouse{true}; |
611 | + void configure_mouse(mir::input::Device& dev); |
612 | + void configure_touchpad(mir::input::Device& dev); |
613 | + void update_touchpads(); |
614 | + void update_mice(); |
615 | + |
616 | + std::shared_ptr<mir::input::InputDeviceObserver> const observer; |
617 | + std::mutex devices_lock; |
618 | + std::unordered_set<std::shared_ptr<mir::input::Device>> touchpads; |
619 | + std::unordered_set<std::shared_ptr<mir::input::Device>> mice; |
620 | + mir::input::PointerConfiguration mouse_pointer_config; |
621 | + mir::input::PointerConfiguration touchpad_pointer_config; |
622 | + mir::input::TouchpadConfiguration touchpad_config; |
623 | }; |
624 | |
625 | } |
626 | |
627 | === modified file 'src/powerd_mediator.cpp' |
628 | --- src/powerd_mediator.cpp 2015-07-17 12:43:46 +0000 |
629 | +++ src/powerd_mediator.cpp 2016-01-21 17:48:37 +0000 |
630 | @@ -45,8 +45,7 @@ |
631 | } |
632 | |
633 | usc::PowerdMediator::PowerdMediator(std::string const& bus_addr) |
634 | - : connection{bus_addr.c_str()}, |
635 | - dbus_event_loop{connection}, |
636 | + : connection{std::make_shared<DBusConnectionHandle>(bus_addr.c_str())}, |
637 | pending_suspend_block_request{false}, |
638 | dim_brightness_{10}, |
639 | min_brightness_{0}, |
640 | @@ -59,17 +58,18 @@ |
641 | proximity_enabled{false}, |
642 | sys_state{SysState::unknown} |
643 | { |
644 | - connection.add_match( |
645 | + dbus_event_loop.add_connection(connection); |
646 | + connection->add_match( |
647 | "type='signal'," |
648 | "sender='com.canonical.powerd'," |
649 | "interface='com.canonical.powerd'," |
650 | "member='SysPowerStateChange'"); |
651 | - connection.add_match( |
652 | + connection->add_match( |
653 | "type='signal'," |
654 | "sender='org.freedesktop.DBus'," |
655 | "interface='org.freedesktop.DBus'," |
656 | "member='NameOwnerChanged'"); |
657 | - connection.add_filter(handle_dbus_message_thunk, this); |
658 | + connection->add_filter(handle_dbus_message_thunk, this); |
659 | |
660 | std::promise<void> event_loop_started; |
661 | auto event_loop_started_future = event_loop_started.get_future(); |
662 | @@ -477,7 +477,7 @@ |
663 | [this, &msg, &reply_promise] |
664 | { |
665 | auto const reply = dbus_connection_send_with_reply_and_block( |
666 | - connection, msg, DBUS_TIMEOUT_USE_DEFAULT, nullptr); |
667 | + *connection, msg, DBUS_TIMEOUT_USE_DEFAULT, nullptr); |
668 | |
669 | reply_promise.set_value(reply); |
670 | }; |
671 | |
672 | === modified file 'src/powerd_mediator.h' |
673 | --- src/powerd_mediator.h 2015-07-17 12:43:46 +0000 |
674 | +++ src/powerd_mediator.h 2016-01-21 17:48:37 +0000 |
675 | @@ -88,7 +88,7 @@ |
676 | void invoke(char const* method, int first_arg_type, ...); |
677 | usc::DBusMessageHandle invoke_with_reply(char const* method, int first_arg_type, ...); |
678 | |
679 | - usc::DBusConnectionHandle connection; |
680 | + std::shared_ptr<usc::DBusConnectionHandle> connection; |
681 | usc::DBusEventLoop dbus_event_loop; |
682 | std::thread dbus_loop_thread; |
683 | |
684 | |
685 | === modified file 'src/screen_event_handler.cpp' |
686 | --- src/screen_event_handler.cpp 2015-11-07 13:29:29 +0000 |
687 | +++ src/screen_event_handler.cpp 2016-01-21 17:48:37 +0000 |
688 | @@ -71,16 +71,20 @@ |
689 | } |
690 | else |
691 | { |
692 | - std::lock_guard<std::mutex> lock{guard}; |
693 | - screen->keep_display_on_temporarily(); |
694 | + keep_or_turn_screen_on(); |
695 | } |
696 | } |
697 | - else if (input_event_type == mir_input_event_type_touch || |
698 | - input_event_type == mir_input_event_type_pointer) |
699 | + else if (input_event_type == mir_input_event_type_touch) |
700 | { |
701 | std::lock_guard<std::mutex> lock{guard}; |
702 | screen->keep_display_on_temporarily(); |
703 | } |
704 | + else if (input_event_type == mir_input_event_type_pointer) |
705 | + { |
706 | + bool const filter_out_event = screen->get_screen_power_mode() != mir_power_mode_on; |
707 | + keep_or_turn_screen_on(); |
708 | + return filter_out_event; |
709 | + } |
710 | |
711 | return false; |
712 | } |
713 | @@ -138,3 +142,18 @@ |
714 | MirPowerMode::mir_power_mode_on, PowerStateChangeReason::power_key); |
715 | long_press_detected = true; |
716 | } |
717 | + |
718 | +void usc::ScreenEventHandler::keep_or_turn_screen_on() |
719 | +{ |
720 | + std::lock_guard<std::mutex> lock{guard}; |
721 | + |
722 | + if (screen->get_screen_power_mode() == mir_power_mode_off) |
723 | + { |
724 | + screen->set_screen_power_mode( |
725 | + MirPowerMode::mir_power_mode_on, PowerStateChangeReason::unknown); |
726 | + } |
727 | + else |
728 | + { |
729 | + screen->keep_display_on_temporarily(); |
730 | + } |
731 | +} |
732 | |
733 | === modified file 'src/screen_event_handler.h' |
734 | --- src/screen_event_handler.h 2015-04-29 14:39:19 +0000 |
735 | +++ src/screen_event_handler.h 2016-01-21 17:48:37 +0000 |
736 | @@ -56,6 +56,7 @@ |
737 | void power_key_down(); |
738 | void shutdown_alarm_notification(); |
739 | void long_press_notification(); |
740 | + void keep_or_turn_screen_on(); |
741 | |
742 | std::mutex guard; |
743 | std::shared_ptr<Screen> const screen; |
744 | |
745 | === modified file 'src/server.cpp' |
746 | --- src/server.cpp 2015-09-30 10:53:54 +0000 |
747 | +++ src/server.cpp 2016-01-21 17:48:37 +0000 |
748 | @@ -28,6 +28,7 @@ |
749 | #include "unity_screen_service.h" |
750 | #include "unity_input_service.h" |
751 | #include "dbus_connection_thread.h" |
752 | +#include "dbus_event_loop.h" |
753 | #include "display_configuration_policy.h" |
754 | #include "steady_clock.h" |
755 | |
756 | @@ -241,7 +242,7 @@ |
757 | return input_configuration( |
758 | [this] |
759 | { |
760 | - return std::make_shared<MirInputConfiguration>(); |
761 | + return std::make_shared<MirInputConfiguration>(the_input_device_hub()); |
762 | }); |
763 | } |
764 | |
765 | @@ -292,12 +293,22 @@ |
766 | }); |
767 | } |
768 | |
769 | +std::shared_ptr<usc::DBusEventLoop> usc::Server::the_dbus_event_loop() |
770 | +{ |
771 | + return dbus_loop( |
772 | + [this] |
773 | + { |
774 | + return std::make_shared<DBusEventLoop>(); |
775 | + }); |
776 | + |
777 | +} |
778 | + |
779 | std::shared_ptr<usc::DBusConnectionThread> usc::Server::the_dbus_connection_thread() |
780 | { |
781 | return dbus_thread( |
782 | [this] |
783 | { |
784 | - return std::make_shared<DBusConnectionThread>(dbus_bus_address()); |
785 | + return std::make_shared<DBusConnectionThread>(the_dbus_event_loop()); |
786 | }); |
787 | } |
788 | |
789 | @@ -307,7 +318,8 @@ |
790 | [this] |
791 | { |
792 | return std::make_shared<UnityScreenService>( |
793 | - the_dbus_connection_thread(), |
794 | + the_dbus_event_loop(), |
795 | + dbus_bus_address(), |
796 | the_screen()); |
797 | }); |
798 | } |
799 | @@ -318,7 +330,8 @@ |
800 | [this] |
801 | { |
802 | return std::make_shared<UnityInputService>( |
803 | - the_dbus_connection_thread(), |
804 | + the_dbus_event_loop(), |
805 | + dbus_bus_address(), |
806 | the_input_configuration()); |
807 | }); |
808 | } |
809 | |
810 | === modified file 'src/server.h' |
811 | --- src/server.h 2015-09-30 10:53:54 +0000 |
812 | +++ src/server.h 2016-01-21 17:48:37 +0000 |
813 | @@ -45,6 +45,7 @@ |
814 | class InputConfiguration; |
815 | class UnityInputService; |
816 | class DBusConnectionThread; |
817 | +class DBusEventLoop; |
818 | class Clock; |
819 | |
820 | class Server : private mir::Server |
821 | @@ -69,6 +70,7 @@ |
822 | virtual std::shared_ptr<ScreenHardware> the_screen_hardware(); |
823 | virtual std::shared_ptr<UnityScreenService> the_unity_screen_service(); |
824 | virtual std::shared_ptr<UnityInputService> the_unity_input_service(); |
825 | + virtual std::shared_ptr<DBusEventLoop> the_dbus_event_loop(); |
826 | virtual std::shared_ptr<DBusConnectionThread> the_dbus_connection_thread(); |
827 | virtual std::shared_ptr<Clock> the_clock(); |
828 | |
829 | @@ -182,6 +184,7 @@ |
830 | mir::CachedPtr<mir::input::EventFilter> screen_event_handler; |
831 | mir::CachedPtr<ScreenHardware> screen_hardware; |
832 | mir::CachedPtr<DBusConnectionThread> dbus_thread; |
833 | + mir::CachedPtr<DBusEventLoop> dbus_loop; |
834 | mir::CachedPtr<UnityScreenService> unity_screen_service; |
835 | mir::CachedPtr<UnityInputService> unity_input_service; |
836 | mir::CachedPtr<Clock> clock; |
837 | |
838 | === modified file 'src/system_compositor.cpp' |
839 | --- src/system_compositor.cpp 2015-08-26 08:26:35 +0000 |
840 | +++ src/system_compositor.cpp 2016-01-21 17:48:37 +0000 |
841 | @@ -22,6 +22,7 @@ |
842 | #include "dm_connection.h" |
843 | |
844 | #include <mir/input/composite_event_filter.h> |
845 | +#include <mir/input/input_device_hub.h> |
846 | #include <mir/abnormal_exit.h> |
847 | |
848 | #include <cerrno> |
849 | @@ -123,6 +124,7 @@ |
850 | |
851 | unity_screen_service = server->the_unity_screen_service(); |
852 | unity_input_service = server->the_unity_input_service(); |
853 | + dbus_service_thread = server->the_dbus_connection_thread(); |
854 | } |
855 | }); |
856 | |
857 | |
858 | === modified file 'src/system_compositor.h' |
859 | --- src/system_compositor.h 2015-08-26 08:26:35 +0000 |
860 | +++ src/system_compositor.h 2016-01-21 17:48:37 +0000 |
861 | @@ -40,6 +40,7 @@ |
862 | class Screen; |
863 | class UnityScreenService; |
864 | class UnityInputService; |
865 | +class DBusConnectionThread; |
866 | |
867 | class SystemCompositor |
868 | { |
869 | @@ -55,6 +56,7 @@ |
870 | std::shared_ptr<mir::input::EventFilter> screen_event_handler; |
871 | std::shared_ptr<UnityScreenService> unity_screen_service; |
872 | std::shared_ptr<UnityInputService> unity_input_service; |
873 | + std::shared_ptr<DBusConnectionThread> dbus_service_thread; |
874 | }; |
875 | |
876 | } |
877 | |
878 | === modified file 'src/unity_input_service.cpp' |
879 | --- src/unity_input_service.cpp 2015-08-28 15:57:25 +0000 |
880 | +++ src/unity_input_service.cpp 2016-01-21 17:48:37 +0000 |
881 | @@ -19,7 +19,7 @@ |
882 | #include "unity_input_service.h" |
883 | #include "input_configuration.h" |
884 | #include "dbus_message_handle.h" |
885 | -#include "dbus_connection_thread.h" |
886 | +#include "dbus_event_loop.h" |
887 | #include "scoped_dbus_error.h" |
888 | |
889 | #include "unity_input_service_introspection.h" // autogenerated |
890 | @@ -33,15 +33,14 @@ |
891 | |
892 | } |
893 | |
894 | -usc::UnityInputService::UnityInputService( |
895 | - std::shared_ptr<usc::DBusConnectionThread> const& dbus, |
896 | - std::shared_ptr<usc::InputConfiguration> const& input_config) |
897 | - : dbus{dbus}, |
898 | - input_config{input_config} |
899 | +usc::UnityInputService::UnityInputService(std::shared_ptr<usc::DBusEventLoop> const& loop, |
900 | + std::string const& address, |
901 | + std::shared_ptr<usc::InputConfiguration> const& input_config) |
902 | + : loop{loop}, connection{std::make_shared<DBusConnectionHandle>(address.c_str())}, input_config{input_config} |
903 | { |
904 | - auto const& connection = dbus->connection(); |
905 | - connection.request_name(dbus_input_service_name); |
906 | - connection.add_filter(handle_dbus_message_thunk, this); |
907 | + loop->add_connection(connection); |
908 | + connection->request_name(dbus_input_service_name); |
909 | + connection->add_filter(handle_dbus_message_thunk, this); |
910 | } |
911 | |
912 | ::DBusHandlerResult usc::UnityInputService::handle_dbus_message_thunk( |
913 | @@ -63,7 +62,7 @@ |
914 | (input_config.get()->*method)(flag); |
915 | |
916 | DBusMessageHandle reply{dbus_message_new_method_return(message)}; |
917 | - dbus_connection_send(dbus->connection(), reply, nullptr); |
918 | + dbus_connection_send(*connection, reply, nullptr); |
919 | } |
920 | } |
921 | |
922 | @@ -79,7 +78,7 @@ |
923 | (input_config.get()->*method)(value); |
924 | |
925 | DBusMessageHandle reply{dbus_message_new_method_return(message)}; |
926 | - dbus_connection_send(dbus->connection(), reply, nullptr); |
927 | + dbus_connection_send(*connection, reply, nullptr); |
928 | } |
929 | } |
930 | |
931 | @@ -95,7 +94,7 @@ |
932 | (input_config.get()->*method)(value); |
933 | |
934 | DBusMessageHandle reply{dbus_message_new_method_return(message)}; |
935 | - dbus_connection_send(dbus->connection(), reply, nullptr); |
936 | + dbus_connection_send(*connection, reply, nullptr); |
937 | } |
938 | } |
939 | |
940 | @@ -151,4 +150,3 @@ |
941 | |
942 | return DBUS_HANDLER_RESULT_HANDLED; |
943 | } |
944 | - |
945 | |
946 | === modified file 'src/unity_input_service.h' |
947 | --- src/unity_input_service.h 2015-08-26 08:00:27 +0000 |
948 | +++ src/unity_input_service.h 2016-01-21 17:48:37 +0000 |
949 | @@ -20,18 +20,20 @@ |
950 | #define USC_UNITY_INPUT_SERVICE_H_ |
951 | |
952 | #include <dbus/dbus.h> |
953 | +#include "dbus_connection_handle.h" |
954 | #include <memory> |
955 | |
956 | namespace usc |
957 | { |
958 | -class DBusConnectionThread; |
959 | +class DBusEventLoop; |
960 | class InputConfiguration; |
961 | |
962 | class UnityInputService |
963 | { |
964 | public: |
965 | UnityInputService( |
966 | - std::shared_ptr<usc::DBusConnectionThread> const& dbus_thread, |
967 | + std::shared_ptr<usc::DBusEventLoop> const& loop, |
968 | + std::string const& address, |
969 | std::shared_ptr<usc::InputConfiguration> const& input_config); |
970 | |
971 | private: |
972 | @@ -44,7 +46,8 @@ |
973 | void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(int32_t)); |
974 | void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(double)); |
975 | |
976 | - std::shared_ptr<usc::DBusConnectionThread> const dbus; |
977 | + std::shared_ptr<usc::DBusEventLoop> const loop; |
978 | + std::shared_ptr<usc::DBusConnectionHandle> connection; |
979 | std::shared_ptr<usc::InputConfiguration> const input_config; |
980 | }; |
981 | |
982 | |
983 | === modified file 'src/unity_screen_service.cpp' |
984 | --- src/unity_screen_service.cpp 2015-08-25 14:35:20 +0000 |
985 | +++ src/unity_screen_service.cpp 2016-01-21 17:48:37 +0000 |
986 | @@ -19,7 +19,7 @@ |
987 | #include "unity_screen_service.h" |
988 | #include "screen.h" |
989 | #include "dbus_message_handle.h" |
990 | -#include "dbus_connection_thread.h" |
991 | +#include "dbus_event_loop.h" |
992 | #include "dbus_connection_handle.h" |
993 | #include "scoped_dbus_error.h" |
994 | |
995 | @@ -35,20 +35,22 @@ |
996 | } |
997 | |
998 | usc::UnityScreenService::UnityScreenService( |
999 | - std::shared_ptr<usc::DBusConnectionThread> const& dbus, |
1000 | + std::shared_ptr<usc::DBusEventLoop> const& loop, |
1001 | + std::string const& address, |
1002 | std::shared_ptr<usc::Screen> const& screen) |
1003 | : screen{screen}, |
1004 | - dbus{dbus}, |
1005 | + loop{loop}, |
1006 | + connection{std::make_shared<DBusConnectionHandle>(address.c_str())}, |
1007 | request_id{0} |
1008 | { |
1009 | - auto const& connection = dbus->connection(); |
1010 | - connection.request_name(dbus_screen_service_name); |
1011 | - connection.add_match( |
1012 | + loop->add_connection(connection); |
1013 | + connection->request_name(dbus_screen_service_name); |
1014 | + connection->add_match( |
1015 | "type='signal'," |
1016 | "sender='org.freedesktop.DBus'," |
1017 | "interface='org.freedesktop.DBus'," |
1018 | "member='NameOwnerChanged'"); |
1019 | - connection.add_filter(handle_dbus_message_thunk, this); |
1020 | + connection->add_filter(handle_dbus_message_thunk, this); |
1021 | |
1022 | screen->register_power_state_change_handler( |
1023 | [this](MirPowerMode mode, PowerStateChangeReason reason) |
1024 | @@ -332,7 +334,7 @@ |
1025 | int32_t const power_state = (power_mode == MirPowerMode::mir_power_mode_off) ? 0 : 1; |
1026 | int32_t const reason_int = static_cast<int32_t>(reason); |
1027 | |
1028 | - dbus->loop().enqueue( |
1029 | + loop->enqueue( |
1030 | [this, power_state, reason_int] |
1031 | { |
1032 | DBusMessageHandle signal{ |
1033 | @@ -344,6 +346,6 @@ |
1034 | DBUS_TYPE_INT32, &reason_int, |
1035 | DBUS_TYPE_INVALID}; |
1036 | |
1037 | - dbus_connection_send(dbus->connection(), signal, nullptr); |
1038 | + dbus_connection_send(*connection, signal, nullptr); |
1039 | }); |
1040 | } |
1041 | |
1042 | === modified file 'src/unity_screen_service.h' |
1043 | --- src/unity_screen_service.h 2015-08-25 14:32:32 +0000 |
1044 | +++ src/unity_screen_service.h 2016-01-21 17:48:37 +0000 |
1045 | @@ -34,13 +34,14 @@ |
1046 | namespace usc |
1047 | { |
1048 | class Screen; |
1049 | -class DBusConnectionThread; |
1050 | +class DBusEventLoop; |
1051 | |
1052 | class UnityScreenService |
1053 | { |
1054 | public: |
1055 | UnityScreenService( |
1056 | - std::shared_ptr<usc::DBusConnectionThread> const& connection, |
1057 | + std::shared_ptr<usc::DBusEventLoop> const& loop, |
1058 | + std::string const& address, |
1059 | std::shared_ptr<usc::Screen> const& screen); |
1060 | |
1061 | private: |
1062 | @@ -64,7 +65,8 @@ |
1063 | MirPowerMode power_mode, PowerStateChangeReason reason); |
1064 | |
1065 | std::shared_ptr<usc::Screen> const screen; |
1066 | - std::shared_ptr<DBusConnectionThread> const dbus; |
1067 | + std::shared_ptr<DBusEventLoop> const loop; |
1068 | + std::shared_ptr<DBusConnectionHandle> connection; |
1069 | |
1070 | std::mutex keep_display_on_mutex; |
1071 | std::unordered_multimap<std::string,int32_t> keep_display_on_ids; |
1072 | |
1073 | === added file 'tests/include/usc/test/mock_input_configuration.h' |
1074 | --- tests/include/usc/test/mock_input_configuration.h 1970-01-01 00:00:00 +0000 |
1075 | +++ tests/include/usc/test/mock_input_configuration.h 2016-01-21 17:48:37 +0000 |
1076 | @@ -0,0 +1,48 @@ |
1077 | +/* |
1078 | + * Copyright © 2015 Canonical Ltd. |
1079 | + * |
1080 | + * This program is free software: you can redistribute it and/or modify |
1081 | + * it under the terms of the GNU General Public License version 3 as |
1082 | + * published by the Free Software Foundation. |
1083 | + * |
1084 | + * This program is distributed in the hope that it will be useful, |
1085 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1086 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1087 | + * GNU General Public License for more details. |
1088 | + * |
1089 | + * You should have received a copy of the GNU General Public License |
1090 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1091 | + * |
1092 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1093 | + */ |
1094 | + |
1095 | +#ifndef USC_TEST_MOCK_INPUT_CONFIGURATION_H_ |
1096 | +#define USC_TEST_MOCK_INPUT_CONFIGURATION_H_ |
1097 | + |
1098 | +#include "src/input_configuration.h" |
1099 | + |
1100 | +#include <gtest/gtest.h> |
1101 | +#include <gmock/gmock.h> |
1102 | + |
1103 | +namespace usc |
1104 | +{ |
1105 | +namespace test |
1106 | +{ |
1107 | +struct MockInputConfiguration : usc::InputConfiguration |
1108 | +{ |
1109 | +public: |
1110 | + MOCK_METHOD1(set_mouse_primary_button, void(int32_t)); |
1111 | + MOCK_METHOD1(set_mouse_cursor_speed, void(double)); |
1112 | + MOCK_METHOD1(set_mouse_scroll_speed, void(double)); |
1113 | + MOCK_METHOD1(set_touchpad_primary_button, void(int32_t)); |
1114 | + MOCK_METHOD1(set_touchpad_cursor_speed, void(double)); |
1115 | + MOCK_METHOD1(set_touchpad_scroll_speed, void(double)); |
1116 | + MOCK_METHOD1(set_two_finger_scroll, void(bool)); |
1117 | + MOCK_METHOD1(set_tap_to_click, void(bool)); |
1118 | + MOCK_METHOD1(set_disable_touchpad_with_mouse, void(bool)); |
1119 | + MOCK_METHOD1(set_disable_touchpad_while_typing, void(bool)); |
1120 | +}; |
1121 | +} |
1122 | +} |
1123 | + |
1124 | +#endif |
1125 | |
1126 | === added file 'tests/include/usc/test/mock_screen.h' |
1127 | --- tests/include/usc/test/mock_screen.h 1970-01-01 00:00:00 +0000 |
1128 | +++ tests/include/usc/test/mock_screen.h 2016-01-21 17:48:37 +0000 |
1129 | @@ -0,0 +1,57 @@ |
1130 | +/* |
1131 | + * Copyright © 2015 Canonical Ltd. |
1132 | + * |
1133 | + * This program is free software: you can redistribute it and/or modify |
1134 | + * it under the terms of the GNU General Public License version 3 as |
1135 | + * published by the Free Software Foundation. |
1136 | + * |
1137 | + * This program is distributed in the hope that it will be useful, |
1138 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1139 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1140 | + * GNU General Public License for more details. |
1141 | + * |
1142 | + * You should have received a copy of the GNU General Public License |
1143 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1144 | + * |
1145 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1146 | + */ |
1147 | + |
1148 | +#ifndef USC_TEST_MOCK_SCREEN_H_ |
1149 | +#define USC_TEST_MOCK_SCREEN_H_ |
1150 | + |
1151 | +#include "src/screen.h" |
1152 | + |
1153 | +#include <gtest/gtest.h> |
1154 | +#include <gmock/gmock.h> |
1155 | +namespace usc |
1156 | +{ |
1157 | +namespace test |
1158 | +{ |
1159 | + |
1160 | +struct MockScreen : usc::Screen |
1161 | +{ |
1162 | + MOCK_METHOD1(enable_inactivity_timers, void(bool enable)); |
1163 | + MOCK_METHOD0(keep_display_on_temporarily, void()); |
1164 | + |
1165 | + MOCK_METHOD0(get_screen_power_mode, MirPowerMode()); |
1166 | + MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason)); |
1167 | + MOCK_METHOD1(keep_display_on, void(bool on)); |
1168 | + MOCK_METHOD1(set_brightness, void(int brightness)); |
1169 | + MOCK_METHOD1(enable_auto_brightness, void(bool enable)); |
1170 | + MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout)); |
1171 | + |
1172 | + MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled)); |
1173 | + |
1174 | + void register_power_state_change_handler( |
1175 | + usc::PowerStateChangeHandler const& handler) |
1176 | + { |
1177 | + power_state_change_handler = handler; |
1178 | + } |
1179 | + |
1180 | + usc::PowerStateChangeHandler power_state_change_handler; |
1181 | +}; |
1182 | + |
1183 | +} |
1184 | +} |
1185 | + |
1186 | +#endif |
1187 | |
1188 | === modified file 'tests/integration-tests/CMakeLists.txt' |
1189 | --- tests/integration-tests/CMakeLists.txt 2015-09-22 16:17:40 +0000 |
1190 | +++ tests/integration-tests/CMakeLists.txt 2016-01-21 17:48:37 +0000 |
1191 | @@ -33,9 +33,12 @@ |
1192 | dbus_bus.cpp |
1193 | dbus_client.cpp |
1194 | spin_wait.cpp |
1195 | + unity_screen_dbus_client.cpp |
1196 | + unity_input_dbus_client.cpp |
1197 | test_dbus_event_loop.cpp |
1198 | test_unity_screen_service.cpp |
1199 | test_unity_input_service.cpp |
1200 | + test_unity_services.cpp |
1201 | test_external_spinner.cpp |
1202 | test_powerd_mediator.cpp |
1203 | test_deadlock_lp1491566.cpp |
1204 | |
1205 | === modified file 'tests/integration-tests/test_dbus_event_loop.cpp' |
1206 | --- tests/integration-tests/test_dbus_event_loop.cpp 2015-05-27 09:42:40 +0000 |
1207 | +++ tests/integration-tests/test_dbus_event_loop.cpp 2016-01-21 17:48:37 +0000 |
1208 | @@ -79,8 +79,9 @@ |
1209 | { |
1210 | ADBusEventLoop() |
1211 | { |
1212 | - connection.request_name(test_service_name); |
1213 | - connection.add_filter(handle_dbus_message_thunk, this); |
1214 | + dbus_event_loop.add_connection(connection); |
1215 | + connection->request_name(test_service_name); |
1216 | + connection->add_filter(handle_dbus_message_thunk, this); |
1217 | |
1218 | std::promise<void> event_loop_started; |
1219 | auto event_loop_started_future = event_loop_started.get_future(); |
1220 | @@ -102,8 +103,7 @@ |
1221 | } |
1222 | |
1223 | static ::DBusHandlerResult handle_dbus_message_thunk( |
1224 | - ::DBusConnection* connection, DBusMessage* message, void* user_data) |
1225 | - { |
1226 | + ::DBusConnection* connection, DBusMessage* message, void* user_data) { |
1227 | auto const a_dbus_event_loop = static_cast<ADBusEventLoop*>(user_data); |
1228 | return a_dbus_event_loop->handle_dbus_message(connection, message, user_data); |
1229 | } |
1230 | @@ -142,8 +142,8 @@ |
1231 | |
1232 | ut::DBusBus bus; |
1233 | |
1234 | - usc::DBusConnectionHandle connection{bus.address().c_str()}; |
1235 | - usc::DBusEventLoop dbus_event_loop{connection}; |
1236 | + std::shared_ptr<usc::DBusConnectionHandle> connection{std::make_shared<usc::DBusConnectionHandle>(bus.address())}; |
1237 | + usc::DBusEventLoop dbus_event_loop{}; |
1238 | std::thread dbus_loop_thread; |
1239 | TestDBusClient client{bus.address()}; |
1240 | }; |
1241 | @@ -173,7 +173,7 @@ |
1242 | test_service_interface, |
1243 | "signal")}; |
1244 | |
1245 | - dbus_connection_send(connection, msg, nullptr); |
1246 | + dbus_connection_send(*connection, msg, nullptr); |
1247 | }); |
1248 | |
1249 | auto const reply = client.listen_for_signal(); |
1250 | @@ -214,7 +214,7 @@ |
1251 | |
1252 | DBusPendingCall* pending{nullptr}; |
1253 | dbus_connection_send_with_reply( |
1254 | - connection, msg, &pending, timeout_ms); |
1255 | + *connection, msg, &pending, timeout_ms); |
1256 | dbus_pending_call_set_notify( |
1257 | pending, &pending_complete, &pending_promise, nullptr); |
1258 | }); |
1259 | |
1260 | === modified file 'tests/integration-tests/test_powerd_mediator.cpp' |
1261 | --- tests/integration-tests/test_powerd_mediator.cpp 2015-07-17 12:43:46 +0000 |
1262 | +++ tests/integration-tests/test_powerd_mediator.cpp 2016-01-21 17:48:37 +0000 |
1263 | @@ -41,9 +41,10 @@ |
1264 | dbus_bool_t auto_brightness_supported, |
1265 | StartNow start_now) |
1266 | : auto_brightness_supported{auto_brightness_supported}, |
1267 | - connection{address.c_str()}, |
1268 | - dbus_event_loop{connection} |
1269 | + connection{std::make_shared<usc::DBusConnectionHandle>(address)}, |
1270 | + dbus_event_loop{} |
1271 | { |
1272 | + dbus_event_loop.add_connection(connection); |
1273 | if (start_now == StartNow::yes) |
1274 | start(); |
1275 | } |
1276 | @@ -60,8 +61,8 @@ |
1277 | ON_CALL(*this, dbus_setUserBrightness(normal_brightness)) |
1278 | .WillByDefault(WakeUp(&initial_setup_done)); |
1279 | |
1280 | - connection.request_name(powerd_service_name); |
1281 | - connection.add_filter(handle_dbus_message_thunk, this); |
1282 | + connection->request_name(powerd_service_name); |
1283 | + connection->add_filter(handle_dbus_message_thunk, this); |
1284 | |
1285 | std::promise<void> event_loop_started; |
1286 | auto event_loop_started_future = event_loop_started.get_future(); |
1287 | @@ -104,7 +105,7 @@ |
1288 | DBUS_TYPE_INT32, &state, |
1289 | DBUS_TYPE_INVALID}; |
1290 | |
1291 | - dbus_connection_send(connection, signal, nullptr); |
1292 | + dbus_connection_send(*connection, signal, nullptr); |
1293 | } |
1294 | |
1295 | private: |
1296 | @@ -230,7 +231,7 @@ |
1297 | |
1298 | ut::WaitCondition initial_setup_done; |
1299 | |
1300 | - usc::DBusConnectionHandle connection; |
1301 | + std::shared_ptr<usc::DBusConnectionHandle> connection; |
1302 | usc::DBusEventLoop dbus_event_loop; |
1303 | std::thread dbus_loop_thread; |
1304 | }; |
1305 | |
1306 | === modified file 'tests/integration-tests/test_unity_input_service.cpp' |
1307 | --- tests/integration-tests/test_unity_input_service.cpp 2015-08-28 15:57:25 +0000 |
1308 | +++ tests/integration-tests/test_unity_input_service.cpp 2016-01-21 17:48:37 +0000 |
1309 | @@ -19,15 +19,16 @@ |
1310 | #include "src/unity_input_service.h" |
1311 | #include "src/dbus_connection_handle.h" |
1312 | #include "src/dbus_connection_thread.h" |
1313 | +#include "src/dbus_event_loop.h" |
1314 | #include "src/dbus_message_handle.h" |
1315 | -#include "src/input_configuration.h" |
1316 | #include "src/unity_input_service_introspection.h" |
1317 | + |
1318 | #include "wait_condition.h" |
1319 | #include "dbus_bus.h" |
1320 | #include "dbus_client.h" |
1321 | +#include "unity_input_dbus_client.h" |
1322 | |
1323 | -#include <gtest/gtest.h> |
1324 | -#include <gmock/gmock.h> |
1325 | +#include "usc/test/mock_input_configuration.h" |
1326 | |
1327 | #include <stdexcept> |
1328 | #include <memory> |
1329 | @@ -37,128 +38,19 @@ |
1330 | namespace |
1331 | { |
1332 | |
1333 | -struct MockInputConfiguration : usc::InputConfiguration |
1334 | -{ |
1335 | -public: |
1336 | - MOCK_METHOD1(set_mouse_primary_button, void(int32_t)); |
1337 | - MOCK_METHOD1(set_mouse_cursor_speed, void(double)); |
1338 | - MOCK_METHOD1(set_mouse_scroll_speed, void(double)); |
1339 | - MOCK_METHOD1(set_touchpad_primary_button, void(int32_t)); |
1340 | - MOCK_METHOD1(set_touchpad_cursor_speed, void(double)); |
1341 | - MOCK_METHOD1(set_touchpad_scroll_speed, void(double)); |
1342 | - MOCK_METHOD1(set_two_finger_scroll, void(bool)); |
1343 | - MOCK_METHOD1(set_tap_to_click, void(bool)); |
1344 | - MOCK_METHOD1(set_disable_touchpad_with_mouse, void(bool)); |
1345 | - MOCK_METHOD1(set_disable_touchpad_while_typing, void(bool)); |
1346 | -}; |
1347 | - |
1348 | -class UnityInputDBusClient : public ut::DBusClient |
1349 | -{ |
1350 | -public: |
1351 | - UnityInputDBusClient(std::string const& address) |
1352 | - : ut::DBusClient{ |
1353 | - address, |
1354 | - "com.canonical.Unity.Input", |
1355 | - "/com/canonical/Unity/Input"} |
1356 | - { |
1357 | - } |
1358 | - |
1359 | - ut::DBusAsyncReplyString request_introspection() |
1360 | - { |
1361 | - return invoke_with_reply<ut::DBusAsyncReplyString>( |
1362 | - "org.freedesktop.DBus.Introspectable", "Introspect", |
1363 | - DBUS_TYPE_INVALID); |
1364 | - } |
1365 | - |
1366 | - ut::DBusAsyncReplyVoid request(char const* requestName, int32_t value) |
1367 | - { |
1368 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1369 | - unity_input_interface, requestName, |
1370 | - DBUS_TYPE_INT32, &value, |
1371 | - DBUS_TYPE_INVALID); |
1372 | - } |
1373 | - |
1374 | - ut::DBusAsyncReplyVoid request_set_mouse_primary_button(int32_t button) |
1375 | - { |
1376 | - return request("setMousePrimaryButton", button); |
1377 | - } |
1378 | - |
1379 | - ut::DBusAsyncReplyVoid request_set_touchpad_primary_button(int32_t button) |
1380 | - { |
1381 | - return request("setTouchpadPrimaryButton", button); |
1382 | - } |
1383 | - |
1384 | - ut::DBusAsyncReplyVoid request(char const* requestName, double value) |
1385 | - { |
1386 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1387 | - unity_input_interface, requestName, |
1388 | - DBUS_TYPE_DOUBLE, &value, |
1389 | - DBUS_TYPE_INVALID); |
1390 | - } |
1391 | - |
1392 | - ut::DBusAsyncReplyVoid request_set_mouse_cursor_speed(double speed) |
1393 | - { |
1394 | - return request("setMouseCursorSpeed", speed); |
1395 | - } |
1396 | - |
1397 | - ut::DBusAsyncReplyVoid request_set_mouse_scroll_speed(double speed) |
1398 | - { |
1399 | - return request("setMouseScrollSpeed", speed); |
1400 | - } |
1401 | - |
1402 | - ut::DBusAsyncReplyVoid request_set_touchpad_cursor_speed(double speed) |
1403 | - { |
1404 | - return request("setTouchpadCursorSpeed", speed); |
1405 | - } |
1406 | - |
1407 | - ut::DBusAsyncReplyVoid request_set_touchpad_scroll_speed(double speed) |
1408 | - { |
1409 | - return request("setTouchpadScrollSpeed", speed); |
1410 | - } |
1411 | - |
1412 | - ut::DBusAsyncReplyVoid request(char const* requestName, bool value) |
1413 | - { |
1414 | - dbus_bool_t copied = value; |
1415 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1416 | - unity_input_interface, requestName, |
1417 | - DBUS_TYPE_BOOLEAN, &copied, |
1418 | - DBUS_TYPE_INVALID); |
1419 | - } |
1420 | - |
1421 | - ut::DBusAsyncReplyVoid request_set_touchpad_two_finger_scroll(bool enabled) |
1422 | - { |
1423 | - return request("setTouchpadTwoFingerScroll", enabled); |
1424 | - } |
1425 | - |
1426 | - ut::DBusAsyncReplyVoid request_set_touchpad_tap_to_click(bool enabled) |
1427 | - { |
1428 | - return request("setTouchpadTapToClick", enabled); |
1429 | - } |
1430 | - |
1431 | - ut::DBusAsyncReplyVoid request_set_touchpad_disable_with_mouse(bool enabled) |
1432 | - { |
1433 | - return request("setTouchpadDisableWithMouse", enabled); |
1434 | - } |
1435 | - |
1436 | - ut::DBusAsyncReplyVoid request_set_touchpad_disable_while_typing(bool enabled) |
1437 | - { |
1438 | - return request("setTouchpadDisableWhileTyping", enabled); |
1439 | - } |
1440 | - |
1441 | - char const* const unity_input_interface = "com.canonical.Unity.Input"; |
1442 | -}; |
1443 | - |
1444 | struct AUnityInputService : testing::Test |
1445 | { |
1446 | std::chrono::seconds const default_timeout{3}; |
1447 | ut::DBusBus bus; |
1448 | |
1449 | - std::shared_ptr<MockInputConfiguration> const mock_input_configuration = |
1450 | - std::make_shared<testing::NiceMock<MockInputConfiguration>>(); |
1451 | - UnityInputDBusClient client{bus.address()}; |
1452 | + std::shared_ptr<ut::MockInputConfiguration> const mock_input_configuration = |
1453 | + std::make_shared<testing::NiceMock<ut::MockInputConfiguration>>(); |
1454 | + ut::UnityInputDBusClient client{bus.address()}; |
1455 | + std::shared_ptr<usc::DBusEventLoop> const dbus_loop= |
1456 | + std::make_shared<usc::DBusEventLoop>(); |
1457 | + usc::UnityInputService service{dbus_loop, bus.address(), mock_input_configuration}; |
1458 | std::shared_ptr<usc::DBusConnectionThread> const dbus_thread = |
1459 | - std::make_shared<usc::DBusConnectionThread>(bus.address()); |
1460 | - usc::UnityInputService service{dbus_thread, mock_input_configuration}; |
1461 | + std::make_shared<usc::DBusConnectionThread>(dbus_loop); |
1462 | }; |
1463 | |
1464 | } |
1465 | |
1466 | === modified file 'tests/integration-tests/test_unity_screen_service.cpp' |
1467 | --- tests/integration-tests/test_unity_screen_service.cpp 2015-08-25 14:27:23 +0000 |
1468 | +++ tests/integration-tests/test_unity_screen_service.cpp 2016-01-21 17:48:37 +0000 |
1469 | @@ -19,14 +19,16 @@ |
1470 | #include "src/unity_screen_service.h" |
1471 | #include "src/dbus_connection_handle.h" |
1472 | #include "src/dbus_connection_thread.h" |
1473 | +#include "src/dbus_event_loop.h" |
1474 | #include "src/dbus_message_handle.h" |
1475 | #include "src/screen.h" |
1476 | #include "src/power_state_change_reason.h" |
1477 | #include "src/unity_screen_service_introspection.h" |
1478 | #include "wait_condition.h" |
1479 | #include "dbus_bus.h" |
1480 | -#include "dbus_client.h" |
1481 | +#include "unity_screen_dbus_client.h" |
1482 | |
1483 | +#include "usc/test/mock_screen.h" |
1484 | #include <gtest/gtest.h> |
1485 | #include <gmock/gmock.h> |
1486 | |
1487 | @@ -38,157 +40,20 @@ |
1488 | namespace |
1489 | { |
1490 | |
1491 | -struct MockScreen : usc::Screen |
1492 | -{ |
1493 | - MOCK_METHOD1(enable_inactivity_timers, void(bool enable)); |
1494 | - MOCK_METHOD0(keep_display_on_temporarily, void()); |
1495 | - |
1496 | - MOCK_METHOD0(get_screen_power_mode, MirPowerMode()); |
1497 | - MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason)); |
1498 | - MOCK_METHOD1(keep_display_on, void(bool on)); |
1499 | - MOCK_METHOD1(set_brightness, void(int brightness)); |
1500 | - MOCK_METHOD1(enable_auto_brightness, void(bool enable)); |
1501 | - MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout)); |
1502 | - |
1503 | - MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled)); |
1504 | - |
1505 | - void register_power_state_change_handler( |
1506 | - usc::PowerStateChangeHandler const& handler) |
1507 | - { |
1508 | - power_state_change_handler = handler; |
1509 | - } |
1510 | - |
1511 | - usc::PowerStateChangeHandler power_state_change_handler; |
1512 | -}; |
1513 | - |
1514 | -class UnityScreenDBusClient : public ut::DBusClient |
1515 | -{ |
1516 | -public: |
1517 | - UnityScreenDBusClient(std::string const& address) |
1518 | - : ut::DBusClient{ |
1519 | - address, |
1520 | - "com.canonical.Unity.Screen", |
1521 | - "/com/canonical/Unity/Screen"} |
1522 | - { |
1523 | - connection.add_match( |
1524 | - "type='signal'," |
1525 | - "interface='com.canonical.Unity.Screen'," |
1526 | - "member='DisplayPowerStateChange'"); |
1527 | - } |
1528 | - |
1529 | - ut::DBusAsyncReplyString request_introspection() |
1530 | - { |
1531 | - return invoke_with_reply<ut::DBusAsyncReplyString>( |
1532 | - "org.freedesktop.DBus.Introspectable", "Introspect", |
1533 | - DBUS_TYPE_INVALID); |
1534 | - } |
1535 | - |
1536 | - ut::DBusAsyncReplyVoid request_set_user_brightness(int32_t brightness) |
1537 | - { |
1538 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1539 | - unity_screen_interface, "setUserBrightness", |
1540 | - DBUS_TYPE_INT32, &brightness, |
1541 | - DBUS_TYPE_INVALID); |
1542 | - } |
1543 | - |
1544 | - ut::DBusAsyncReplyVoid request_user_auto_brightness_enable(bool enabled) |
1545 | - { |
1546 | - dbus_bool_t const e = enabled ? TRUE : FALSE; |
1547 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1548 | - unity_screen_interface, "userAutobrightnessEnable", |
1549 | - DBUS_TYPE_BOOLEAN, &e, |
1550 | - DBUS_TYPE_INVALID); |
1551 | - } |
1552 | - |
1553 | - ut::DBusAsyncReplyVoid request_set_inactivity_timeouts( |
1554 | - int32_t poweroff_timeout, int32_t dimmer_timeout) |
1555 | - { |
1556 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1557 | - unity_screen_interface, "setInactivityTimeouts", |
1558 | - DBUS_TYPE_INT32, &poweroff_timeout, |
1559 | - DBUS_TYPE_INT32, &dimmer_timeout, |
1560 | - DBUS_TYPE_INVALID); |
1561 | - } |
1562 | - |
1563 | - ut::DBusAsyncReplyVoid request_set_touch_visualization_enabled(bool enabled) |
1564 | - { |
1565 | - dbus_bool_t const e = enabled ? TRUE : FALSE; |
1566 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1567 | - unity_screen_interface, "setTouchVisualizationEnabled", |
1568 | - DBUS_TYPE_BOOLEAN, &e, |
1569 | - DBUS_TYPE_INVALID); |
1570 | - } |
1571 | - |
1572 | - ut::DBusAsyncReplyBool request_set_screen_power_mode( |
1573 | - std::string const& mode, int reason) |
1574 | - { |
1575 | - auto mode_cstr = mode.c_str(); |
1576 | - return invoke_with_reply<ut::DBusAsyncReplyBool>( |
1577 | - unity_screen_interface, "setScreenPowerMode", |
1578 | - DBUS_TYPE_STRING, &mode_cstr, |
1579 | - DBUS_TYPE_INT32, &reason, |
1580 | - DBUS_TYPE_INVALID); |
1581 | - } |
1582 | - |
1583 | - ut::DBusAsyncReplyInt request_keep_display_on() |
1584 | - { |
1585 | - return invoke_with_reply<ut::DBusAsyncReplyInt>( |
1586 | - unity_screen_interface, "keepDisplayOn", |
1587 | - DBUS_TYPE_INVALID); |
1588 | - } |
1589 | - |
1590 | - ut::DBusAsyncReplyVoid request_remove_display_on_request(int id) |
1591 | - { |
1592 | - return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1593 | - unity_screen_interface, "removeDisplayOnRequest", |
1594 | - DBUS_TYPE_INT32, &id, |
1595 | - DBUS_TYPE_INVALID); |
1596 | - } |
1597 | - |
1598 | - ut::DBusAsyncReply request_invalid_method() |
1599 | - { |
1600 | - return invoke_with_reply<ut::DBusAsyncReply>( |
1601 | - unity_screen_interface, "invalidMethod", |
1602 | - DBUS_TYPE_INVALID); |
1603 | - } |
1604 | - |
1605 | - ut::DBusAsyncReply request_method_with_invalid_arguments() |
1606 | - { |
1607 | - char const* const str = "abcd"; |
1608 | - return invoke_with_reply<ut::DBusAsyncReply>( |
1609 | - unity_screen_interface, "setUserBrightness", |
1610 | - DBUS_TYPE_STRING, &str, |
1611 | - DBUS_TYPE_INVALID); |
1612 | - } |
1613 | - |
1614 | - usc::DBusMessageHandle listen_for_power_state_change_signal() |
1615 | - { |
1616 | - while (true) |
1617 | - { |
1618 | - dbus_connection_read_write(connection, 1); |
1619 | - auto msg = usc::DBusMessageHandle{dbus_connection_pop_message(connection)}; |
1620 | - |
1621 | - if (msg && dbus_message_is_signal(msg, "com.canonical.Unity.Screen", "DisplayPowerStateChange")) |
1622 | - { |
1623 | - return msg; |
1624 | - } |
1625 | - } |
1626 | - } |
1627 | - |
1628 | - char const* const unity_screen_interface = "com.canonical.Unity.Screen"; |
1629 | -}; |
1630 | - |
1631 | struct AUnityScreenService : testing::Test |
1632 | { |
1633 | std::chrono::seconds const default_timeout{3}; |
1634 | ut::DBusBus bus; |
1635 | |
1636 | - std::shared_ptr<MockScreen> const mock_screen = |
1637 | - std::make_shared<testing::NiceMock<MockScreen>>(); |
1638 | - UnityScreenDBusClient client{bus.address()}; |
1639 | + std::shared_ptr<ut::MockScreen> const mock_screen = |
1640 | + std::make_shared<testing::NiceMock<ut::MockScreen>>(); |
1641 | + ut::UnityScreenDBusClient client{bus.address()}; |
1642 | + std::shared_ptr<usc::DBusEventLoop> const dbus_loop= |
1643 | + std::make_shared<usc::DBusEventLoop>(); |
1644 | + usc::UnityScreenService service{dbus_loop, bus.address(), mock_screen}; |
1645 | std::shared_ptr<usc::DBusConnectionThread> const dbus_thread = |
1646 | - std::make_shared<usc::DBusConnectionThread>(bus.address()); |
1647 | - usc::UnityScreenService service{dbus_thread, mock_screen}; |
1648 | + std::make_shared<usc::DBusConnectionThread>(dbus_loop); |
1649 | + |
1650 | }; |
1651 | |
1652 | } |
1653 | @@ -340,7 +205,7 @@ |
1654 | { |
1655 | using namespace testing; |
1656 | |
1657 | - UnityScreenDBusClient other_client{bus.address()}; |
1658 | + ut::UnityScreenDBusClient other_client{bus.address()}; |
1659 | |
1660 | EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(4); |
1661 | EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0); |
1662 | |
1663 | === added file 'tests/integration-tests/test_unity_services.cpp' |
1664 | --- tests/integration-tests/test_unity_services.cpp 1970-01-01 00:00:00 +0000 |
1665 | +++ tests/integration-tests/test_unity_services.cpp 2016-01-21 17:48:37 +0000 |
1666 | @@ -0,0 +1,82 @@ |
1667 | +/* |
1668 | + * Copyright © 2016 Canonical Ltd. |
1669 | + * |
1670 | + * This program is free software: you can redistribute it and/or modify |
1671 | + * it under the terms of the GNU General Public License version 3 as |
1672 | + * published by the Free Software Foundation. |
1673 | + * |
1674 | + * This program is distributed in the hope that it will be useful, |
1675 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1676 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1677 | + * GNU General Public License for more details. |
1678 | + * |
1679 | + * You should have received a copy of the GNU General Public License |
1680 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1681 | + * |
1682 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1683 | + */ |
1684 | +#include "src/unity_input_service.h" |
1685 | +#include "src/dbus_connection_handle.h" |
1686 | +#include "src/dbus_connection_thread.h" |
1687 | +#include "src/dbus_event_loop.h" |
1688 | +#include "src/dbus_message_handle.h" |
1689 | +#include "src/unity_screen_service.h" |
1690 | +#include "src/unity_input_service_introspection.h" |
1691 | +#include "src/unity_screen_service_introspection.h" |
1692 | + |
1693 | +#include "wait_condition.h" |
1694 | +#include "dbus_bus.h" |
1695 | +#include "dbus_client.h" |
1696 | +#include "unity_input_dbus_client.h" |
1697 | +#include "unity_screen_dbus_client.h" |
1698 | + |
1699 | +#include "usc/test/mock_input_configuration.h" |
1700 | +#include "usc/test/mock_screen.h" |
1701 | + |
1702 | +namespace ut = usc::test; |
1703 | +using namespace testing; |
1704 | + |
1705 | +namespace |
1706 | +{ |
1707 | + |
1708 | +struct UnityServices : testing::Test |
1709 | +{ |
1710 | + std::chrono::seconds const default_timeout{3}; |
1711 | + ut::DBusBus bus; |
1712 | + |
1713 | + ut::UnityScreenDBusClient screen_client{bus.address()}; |
1714 | + ut::UnityInputDBusClient input_client{bus.address()}; |
1715 | + std::shared_ptr<ut::MockScreen> const mock_screen = |
1716 | + std::make_shared<testing::NiceMock<ut::MockScreen>>(); |
1717 | + std::shared_ptr<ut::MockInputConfiguration> const mock_input_configuration = |
1718 | + std::make_shared<testing::NiceMock<ut::MockInputConfiguration>>(); |
1719 | + std::shared_ptr<usc::DBusEventLoop> const dbus_loop= |
1720 | + std::make_shared<usc::DBusEventLoop>(); |
1721 | + usc::UnityScreenService screen_service{dbus_loop, bus.address(), mock_screen}; |
1722 | + usc::UnityInputService input_service{dbus_loop, bus.address(), mock_input_configuration}; |
1723 | + std::shared_ptr<usc::DBusConnectionThread> const dbus_thread = |
1724 | + std::make_shared<usc::DBusConnectionThread>(dbus_loop); |
1725 | +}; |
1726 | + |
1727 | +} |
1728 | + |
1729 | +TEST_F(UnityServices, offer_screen_introspection) |
1730 | +{ |
1731 | + auto reply = screen_client.request_introspection(); |
1732 | + EXPECT_THAT(reply.get(), Eq(unity_screen_service_introspection)); |
1733 | +} |
1734 | + |
1735 | +TEST_F(UnityServices, offer_input_introspection) |
1736 | +{ |
1737 | + auto reply = input_client.request_introspection(); |
1738 | + EXPECT_THAT(reply.get(), Eq(unity_input_service_introspection)); |
1739 | +} |
1740 | + |
1741 | +TEST_F(UnityServices, provides_access_to_input_methods) |
1742 | +{ |
1743 | + double const speed = 8.0; |
1744 | + |
1745 | + EXPECT_CALL(*mock_input_configuration, set_mouse_scroll_speed(speed)); |
1746 | + |
1747 | + input_client.request_set_mouse_scroll_speed(speed); |
1748 | +} |
1749 | |
1750 | === added file 'tests/integration-tests/unity_input_dbus_client.cpp' |
1751 | --- tests/integration-tests/unity_input_dbus_client.cpp 1970-01-01 00:00:00 +0000 |
1752 | +++ tests/integration-tests/unity_input_dbus_client.cpp 2016-01-21 17:48:37 +0000 |
1753 | @@ -0,0 +1,113 @@ |
1754 | +/* |
1755 | + * Copyright © 2015 Canonical Ltd. |
1756 | + * |
1757 | + * This program is free software: you can redistribute it and/or modify |
1758 | + * it under the terms of the GNU General Public License version 3 as |
1759 | + * published by the Free Software Foundation. |
1760 | + * |
1761 | + * This program is distributed in the hope that it will be useful, |
1762 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1763 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1764 | + * GNU General Public License for more details. |
1765 | + * |
1766 | + * You should have received a copy of the GNU General Public License |
1767 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1768 | + * |
1769 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1770 | + */ |
1771 | + |
1772 | +#include "unity_input_dbus_client.h" |
1773 | + |
1774 | +namespace ut = usc::test; |
1775 | + |
1776 | +ut::UnityInputDBusClient::UnityInputDBusClient(std::string const& address) |
1777 | + : ut::DBusClient{ |
1778 | + address, |
1779 | + "com.canonical.Unity.Input", |
1780 | + "/com/canonical/Unity/Input"} |
1781 | +{ |
1782 | +} |
1783 | + |
1784 | +ut::DBusAsyncReplyString ut::UnityInputDBusClient::request_introspection() |
1785 | +{ |
1786 | + return invoke_with_reply<ut::DBusAsyncReplyString>( |
1787 | + "org.freedesktop.DBus.Introspectable", "Introspect", |
1788 | + DBUS_TYPE_INVALID); |
1789 | +} |
1790 | + |
1791 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, int32_t value) |
1792 | +{ |
1793 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1794 | + unity_input_interface, requestName, |
1795 | + DBUS_TYPE_INT32, &value, |
1796 | + DBUS_TYPE_INVALID); |
1797 | +} |
1798 | + |
1799 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_primary_button(int32_t button) |
1800 | +{ |
1801 | + return request("setMousePrimaryButton", button); |
1802 | +} |
1803 | + |
1804 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_primary_button(int32_t button) |
1805 | +{ |
1806 | + return request("setTouchpadPrimaryButton", button); |
1807 | +} |
1808 | + |
1809 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, double value) |
1810 | +{ |
1811 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1812 | + unity_input_interface, requestName, |
1813 | + DBUS_TYPE_DOUBLE, &value, |
1814 | + DBUS_TYPE_INVALID); |
1815 | +} |
1816 | + |
1817 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_cursor_speed(double speed) |
1818 | +{ |
1819 | + return request("setMouseCursorSpeed", speed); |
1820 | +} |
1821 | + |
1822 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_scroll_speed(double speed) |
1823 | +{ |
1824 | + return request("setMouseScrollSpeed", speed); |
1825 | +} |
1826 | + |
1827 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_cursor_speed(double speed) |
1828 | +{ |
1829 | + return request("setTouchpadCursorSpeed", speed); |
1830 | +} |
1831 | + |
1832 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_scroll_speed(double speed) |
1833 | +{ |
1834 | + return request("setTouchpadScrollSpeed", speed); |
1835 | +} |
1836 | + |
1837 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, bool value) |
1838 | +{ |
1839 | + dbus_bool_t copied = value; |
1840 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>( |
1841 | + unity_input_interface, requestName, |
1842 | + DBUS_TYPE_BOOLEAN, &copied, |
1843 | + DBUS_TYPE_INVALID); |
1844 | +} |
1845 | + |
1846 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_two_finger_scroll(bool enabled) |
1847 | +{ |
1848 | + return request("setTouchpadTwoFingerScroll", enabled); |
1849 | +} |
1850 | + |
1851 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_tap_to_click(bool enabled) |
1852 | +{ |
1853 | + return request("setTouchpadTapToClick", enabled); |
1854 | +} |
1855 | + |
1856 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_with_mouse(bool enabled) |
1857 | +{ |
1858 | + return request("setTouchpadDisableWithMouse", enabled); |
1859 | +} |
1860 | + |
1861 | +ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_while_typing(bool enabled) |
1862 | +{ |
1863 | + return request("setTouchpadDisableWhileTyping", enabled); |
1864 | +} |
1865 | + |
1866 | + |
1867 | |
1868 | === added file 'tests/integration-tests/unity_input_dbus_client.h' |
1869 | --- tests/integration-tests/unity_input_dbus_client.h 1970-01-01 00:00:00 +0000 |
1870 | +++ tests/integration-tests/unity_input_dbus_client.h 2016-01-21 17:48:37 +0000 |
1871 | @@ -0,0 +1,52 @@ |
1872 | +/* |
1873 | + * Copyright © 2015 Canonical Ltd. |
1874 | + * |
1875 | + * This program is free software: you can redistribute it and/or modify |
1876 | + * it under the terms of the GNU General Public License version 3 as |
1877 | + * published by the Free Software Foundation. |
1878 | + * |
1879 | + * This program is distributed in the hope that it will be useful, |
1880 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1881 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1882 | + * GNU General Public License for more details. |
1883 | + * |
1884 | + * You should have received a copy of the GNU General Public License |
1885 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1886 | + * |
1887 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1888 | + */ |
1889 | + |
1890 | +#ifndef USC_TEST_UNITY_INPUT_DBUS_CLIENT_H_ |
1891 | +#define USC_TEST_UNITY_INPUT_DBUS_CLIENT_H_ |
1892 | + |
1893 | +#include "dbus_client.h" |
1894 | + |
1895 | +namespace usc |
1896 | +{ |
1897 | +namespace test |
1898 | +{ |
1899 | +class UnityInputDBusClient : public DBusClient |
1900 | +{ |
1901 | +public: |
1902 | + UnityInputDBusClient(std::string const& address); |
1903 | + DBusAsyncReplyString request_introspection(); |
1904 | + DBusAsyncReplyVoid request(char const* requestName, int32_t value); |
1905 | + DBusAsyncReplyVoid request_set_mouse_primary_button(int32_t button); |
1906 | + DBusAsyncReplyVoid request_set_touchpad_primary_button(int32_t button); |
1907 | + DBusAsyncReplyVoid request(char const* requestName, double value); |
1908 | + DBusAsyncReplyVoid request_set_mouse_cursor_speed(double speed); |
1909 | + DBusAsyncReplyVoid request_set_mouse_scroll_speed(double speed); |
1910 | + DBusAsyncReplyVoid request_set_touchpad_cursor_speed(double speed); |
1911 | + DBusAsyncReplyVoid request_set_touchpad_scroll_speed(double speed); |
1912 | + DBusAsyncReplyVoid request(char const* requestName, bool value); |
1913 | + DBusAsyncReplyVoid request_set_touchpad_two_finger_scroll(bool enabled); |
1914 | + DBusAsyncReplyVoid request_set_touchpad_tap_to_click(bool enabled); |
1915 | + DBusAsyncReplyVoid request_set_touchpad_disable_with_mouse(bool enabled); |
1916 | + DBusAsyncReplyVoid request_set_touchpad_disable_while_typing(bool enabled); |
1917 | + char const* const unity_input_interface = "com.canonical.Unity.Input"; |
1918 | +}; |
1919 | + |
1920 | +} |
1921 | +} |
1922 | + |
1923 | +#endif |
1924 | |
1925 | === added file 'tests/integration-tests/unity_screen_dbus_client.cpp' |
1926 | --- tests/integration-tests/unity_screen_dbus_client.cpp 1970-01-01 00:00:00 +0000 |
1927 | +++ tests/integration-tests/unity_screen_dbus_client.cpp 2016-01-21 17:48:37 +0000 |
1928 | @@ -0,0 +1,112 @@ |
1929 | +/* |
1930 | + * Copyright © 2015 Canonical Ltd. |
1931 | + * |
1932 | + * This program is free software: you can redistribute it and/or modify |
1933 | + * it under the terms of the GNU General Public License version 3 as |
1934 | + * published by the Free Software Foundation. |
1935 | + * |
1936 | + * This program is distributed in the hope that it will be useful, |
1937 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1938 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1939 | + * GNU General Public License for more details. |
1940 | + * |
1941 | + * You should have received a copy of the GNU General Public License |
1942 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1943 | + * |
1944 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
1945 | + */ |
1946 | + |
1947 | +#include "unity_screen_dbus_client.h" |
1948 | +#include "src/dbus_message_handle.h" |
1949 | + |
1950 | +namespace ut = usc::test; |
1951 | + |
1952 | +ut::UnityScreenDBusClient::UnityScreenDBusClient(std::string const& address) |
1953 | + : ut::DBusClient{ |
1954 | + address, |
1955 | + "com.canonical.Unity.Screen", |
1956 | + "/com/canonical/Unity/Screen"} |
1957 | +{ |
1958 | + connection.add_match( |
1959 | + "type='signal'," |
1960 | + "interface='com.canonical.Unity.Screen'," |
1961 | + "member='DisplayPowerStateChange'"); |
1962 | +} |
1963 | + |
1964 | +ut::DBusAsyncReplyString ut::UnityScreenDBusClient::request_introspection() |
1965 | +{ |
1966 | + return invoke_with_reply<ut::DBusAsyncReplyString>("org.freedesktop.DBus.Introspectable", "Introspect", |
1967 | + DBUS_TYPE_INVALID); |
1968 | +} |
1969 | + |
1970 | +ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_user_brightness(int32_t brightness) |
1971 | +{ |
1972 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setUserBrightness", DBUS_TYPE_INT32, |
1973 | + &brightness, DBUS_TYPE_INVALID); |
1974 | +} |
1975 | + |
1976 | +ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_user_auto_brightness_enable(bool enabled) |
1977 | +{ |
1978 | + dbus_bool_t const e = enabled ? TRUE : FALSE; |
1979 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "userAutobrightnessEnable", |
1980 | + DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID); |
1981 | +} |
1982 | + |
1983 | +ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_inactivity_timeouts(int32_t poweroff_timeout, |
1984 | + int32_t dimmer_timeout) |
1985 | +{ |
1986 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setInactivityTimeouts", DBUS_TYPE_INT32, |
1987 | + &poweroff_timeout, DBUS_TYPE_INT32, &dimmer_timeout, |
1988 | + DBUS_TYPE_INVALID); |
1989 | +} |
1990 | + |
1991 | +ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_touch_visualization_enabled(bool enabled) |
1992 | +{ |
1993 | + dbus_bool_t const e = enabled ? TRUE : FALSE; |
1994 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setTouchVisualizationEnabled", |
1995 | + DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID); |
1996 | +} |
1997 | + |
1998 | +ut::DBusAsyncReplyBool ut::UnityScreenDBusClient::request_set_screen_power_mode(std::string const& mode, int reason) |
1999 | +{ |
2000 | + auto mode_cstr = mode.c_str(); |
2001 | + return invoke_with_reply<ut::DBusAsyncReplyBool>(unity_screen_interface, "setScreenPowerMode", DBUS_TYPE_STRING, |
2002 | + &mode_cstr, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INVALID); |
2003 | +} |
2004 | + |
2005 | +ut::DBusAsyncReplyInt ut::UnityScreenDBusClient::request_keep_display_on() |
2006 | +{ |
2007 | + return invoke_with_reply<ut::DBusAsyncReplyInt>(unity_screen_interface, "keepDisplayOn", DBUS_TYPE_INVALID); |
2008 | +} |
2009 | + |
2010 | +ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_remove_display_on_request(int id) |
2011 | +{ |
2012 | + return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "removeDisplayOnRequest", DBUS_TYPE_INT32, |
2013 | + &id, DBUS_TYPE_INVALID); |
2014 | +} |
2015 | + |
2016 | +ut::DBusAsyncReply ut::UnityScreenDBusClient::request_invalid_method() |
2017 | +{ |
2018 | + return invoke_with_reply<ut::DBusAsyncReply>(unity_screen_interface, "invalidMethod", DBUS_TYPE_INVALID); |
2019 | +} |
2020 | + |
2021 | +ut::DBusAsyncReply ut::UnityScreenDBusClient::request_method_with_invalid_arguments() |
2022 | +{ |
2023 | + char const* const str = "abcd"; |
2024 | + return invoke_with_reply<ut::DBusAsyncReply>(unity_screen_interface, "setUserBrightness", DBUS_TYPE_STRING, &str, |
2025 | + DBUS_TYPE_INVALID); |
2026 | +} |
2027 | + |
2028 | +usc::DBusMessageHandle ut::UnityScreenDBusClient::listen_for_power_state_change_signal() |
2029 | +{ |
2030 | + while (true) |
2031 | + { |
2032 | + dbus_connection_read_write(connection, 1); |
2033 | + auto msg = usc::DBusMessageHandle{dbus_connection_pop_message(connection)}; |
2034 | + |
2035 | + if (msg && dbus_message_is_signal(msg, "com.canonical.Unity.Screen", "DisplayPowerStateChange")) |
2036 | + { |
2037 | + return msg; |
2038 | + } |
2039 | + } |
2040 | +} |
2041 | |
2042 | === added file 'tests/integration-tests/unity_screen_dbus_client.h' |
2043 | --- tests/integration-tests/unity_screen_dbus_client.h 1970-01-01 00:00:00 +0000 |
2044 | +++ tests/integration-tests/unity_screen_dbus_client.h 2016-01-21 17:48:37 +0000 |
2045 | @@ -0,0 +1,54 @@ |
2046 | +/* |
2047 | + * Copyright © 2015 Canonical Ltd. |
2048 | + * |
2049 | + * This program is free software: you can redistribute it and/or modify |
2050 | + * it under the terms of the GNU General Public License version 3 as |
2051 | + * published by the Free Software Foundation. |
2052 | + * |
2053 | + * This program is distributed in the hope that it will be useful, |
2054 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2055 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2056 | + * GNU General Public License for more details. |
2057 | + * |
2058 | + * You should have received a copy of the GNU General Public License |
2059 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2060 | + * |
2061 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
2062 | + */ |
2063 | + |
2064 | +#ifndef USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_ |
2065 | +#define USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_ |
2066 | + |
2067 | +#include "dbus_client.h" |
2068 | + |
2069 | +namespace usc |
2070 | +{ |
2071 | +namespace test |
2072 | +{ |
2073 | + |
2074 | +class UnityScreenDBusClient : public DBusClient |
2075 | +{ |
2076 | +public: |
2077 | + UnityScreenDBusClient(std::string const& address); |
2078 | + |
2079 | + DBusAsyncReplyString request_introspection(); |
2080 | + DBusAsyncReplyVoid request_set_user_brightness(int32_t brightness); |
2081 | + DBusAsyncReplyVoid request_user_auto_brightness_enable(bool enabled); |
2082 | + DBusAsyncReplyVoid request_set_inactivity_timeouts( |
2083 | + int32_t poweroff_timeout, int32_t dimmer_timeout); |
2084 | + DBusAsyncReplyVoid request_set_touch_visualization_enabled(bool enabled); |
2085 | + DBusAsyncReplyBool request_set_screen_power_mode( |
2086 | + std::string const& mode, int reason); |
2087 | + |
2088 | + DBusAsyncReplyInt request_keep_display_on(); |
2089 | + DBusAsyncReplyVoid request_remove_display_on_request(int id); |
2090 | + DBusAsyncReply request_invalid_method(); |
2091 | + DBusAsyncReply request_method_with_invalid_arguments(); |
2092 | + usc::DBusMessageHandle listen_for_power_state_change_signal(); |
2093 | + char const* const unity_screen_interface = "com.canonical.Unity.Screen"; |
2094 | +}; |
2095 | + |
2096 | +} |
2097 | +} |
2098 | + |
2099 | +#endif |
2100 | |
2101 | === modified file 'tests/unit-tests/CMakeLists.txt' |
2102 | --- tests/unit-tests/CMakeLists.txt 2015-02-18 14:40:29 +0000 |
2103 | +++ tests/unit-tests/CMakeLists.txt 2016-01-21 17:48:37 +0000 |
2104 | @@ -25,6 +25,7 @@ |
2105 | test_session_switcher.cpp |
2106 | test_screen_event_handler.cpp |
2107 | test_mir_screen.cpp |
2108 | + test_mir_input_configuration.cpp |
2109 | |
2110 | advanceable_timer.cpp |
2111 | ) |
2112 | |
2113 | === added file 'tests/unit-tests/test_mir_input_configuration.cpp' |
2114 | --- tests/unit-tests/test_mir_input_configuration.cpp 1970-01-01 00:00:00 +0000 |
2115 | +++ tests/unit-tests/test_mir_input_configuration.cpp 2016-01-21 17:48:37 +0000 |
2116 | @@ -0,0 +1,114 @@ |
2117 | +/* |
2118 | + * Copyright © 2015 Canonical Ltd. |
2119 | + * |
2120 | + * This program is free software: you can redistribute it and/or modify |
2121 | + * it under the terms of the GNU General Public License version 3 as |
2122 | + * published by the Free Software Foundation. |
2123 | + * |
2124 | + * This program is distributed in the hope that it will be useful, |
2125 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2126 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2127 | + * GNU General Public License for more details. |
2128 | + * |
2129 | + * You should have received a copy of the GNU General Public License |
2130 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2131 | + * |
2132 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
2133 | + */ |
2134 | + |
2135 | + |
2136 | +#include "src/mir_input_configuration.h" |
2137 | +#include "mir/input/input_device_hub.h" |
2138 | +#include "mir/input/device_capability.h" |
2139 | +#include "mir/input/input_device_observer.h" |
2140 | +#include "mir/input/device.h" |
2141 | + |
2142 | +#include <gtest/gtest.h> |
2143 | +#include <gmock/gmock.h> |
2144 | + |
2145 | +namespace mi = mir::input; |
2146 | + |
2147 | +using namespace ::testing; |
2148 | + |
2149 | +namespace |
2150 | +{ |
2151 | +struct MockDevice : mi::Device |
2152 | +{ |
2153 | + MOCK_CONST_METHOD0(id, MirInputDeviceId()); |
2154 | + MOCK_CONST_METHOD0(capabilities, mi::DeviceCapabilities()); |
2155 | + MOCK_CONST_METHOD0(name, std::string()); |
2156 | + MOCK_CONST_METHOD0(unique_id, std::string()); |
2157 | + MOCK_CONST_METHOD0(pointer_configuration, mir::optional_value<mi::PointerConfiguration>()); |
2158 | + MOCK_METHOD1(apply_pointer_configuration, void(mi::PointerConfiguration const&)); |
2159 | + MOCK_CONST_METHOD0(touchpad_configuration, mir::optional_value<mi::TouchpadConfiguration> ()); |
2160 | + MOCK_METHOD1(apply_touchpad_configuration, void(mi::TouchpadConfiguration const&)); |
2161 | + |
2162 | + MockDevice(mi::DeviceCapabilities caps) |
2163 | + : caps(caps) |
2164 | + { |
2165 | + ON_CALL(*this, capabilities()).WillByDefault(Return(this->caps)); |
2166 | + } |
2167 | + |
2168 | + mi::DeviceCapabilities caps; |
2169 | +}; |
2170 | + |
2171 | +struct MockInputDeviceHub : mi::InputDeviceHub |
2172 | +{ |
2173 | + MOCK_METHOD1(add_observer,void(std::shared_ptr<mi::InputDeviceObserver> const&)); |
2174 | + MOCK_METHOD1(remove_observer,void(std::weak_ptr<mi::InputDeviceObserver> const&)); |
2175 | +}; |
2176 | + |
2177 | +struct MirInputConfiguration : ::testing::Test |
2178 | +{ |
2179 | + template<typename T> |
2180 | + using shared_mock = std::shared_ptr<::testing::NiceMock<T>>; |
2181 | + shared_mock<MockInputDeviceHub> mock_hub{std::make_shared<::testing::NiceMock<MockInputDeviceHub>>()}; |
2182 | + shared_mock<MockDevice> mock_mouse{ |
2183 | + std::make_shared<::testing::NiceMock<MockDevice>>(mi::DeviceCapability::pointer)}; |
2184 | + shared_mock<MockDevice> mock_touchpad{std::make_shared<::testing::NiceMock<MockDevice>>( |
2185 | + mi::DeviceCapability::pointer | mi::DeviceCapability::touchpad)}; |
2186 | + shared_mock<MockDevice> mock_keyboard{std::make_shared<::testing::NiceMock<MockDevice>>( |
2187 | + mi::DeviceCapability::keyboard | mi::DeviceCapability::alpha_numeric)}; |
2188 | + |
2189 | + std::shared_ptr<mi::InputDeviceObserver> obs; |
2190 | + |
2191 | + MirInputConfiguration() |
2192 | + { |
2193 | + ON_CALL(*mock_hub, add_observer(_)).WillByDefault(SaveArg<0>(&obs)); |
2194 | + } |
2195 | +}; |
2196 | +} |
2197 | + |
2198 | +TEST_F(MirInputConfiguration, registers_something_as_device_observer) |
2199 | +{ |
2200 | + EXPECT_CALL(*mock_hub, add_observer(_)); |
2201 | + |
2202 | + usc::MirInputConfiguration config(mock_hub); |
2203 | +} |
2204 | + |
2205 | +TEST_F(MirInputConfiguration, configures_device_on_add) |
2206 | +{ |
2207 | + usc::MirInputConfiguration config(mock_hub); |
2208 | + |
2209 | + EXPECT_CALL(*mock_touchpad, apply_pointer_configuration(_)); |
2210 | + EXPECT_CALL(*mock_touchpad, apply_touchpad_configuration(_)); |
2211 | + obs->device_added(mock_touchpad); |
2212 | +} |
2213 | + |
2214 | +TEST_F(MirInputConfiguration, configures_mouse_on_add) |
2215 | +{ |
2216 | + usc::MirInputConfiguration config(mock_hub); |
2217 | + |
2218 | + EXPECT_CALL(*mock_mouse, apply_pointer_configuration(_)); |
2219 | + obs->device_added(mock_mouse); |
2220 | +} |
2221 | + |
2222 | +TEST_F(MirInputConfiguration, ignores_keyboard_when_added) |
2223 | +{ |
2224 | + usc::MirInputConfiguration config(mock_hub); |
2225 | + |
2226 | + EXPECT_CALL(*mock_keyboard, apply_touchpad_configuration(_)).Times(0); |
2227 | + EXPECT_CALL(*mock_keyboard, apply_pointer_configuration(_)).Times(0); |
2228 | + obs->device_added(mock_keyboard); |
2229 | +} |
2230 | + |
2231 | |
2232 | === modified file 'tests/unit-tests/test_screen_event_handler.cpp' |
2233 | --- tests/unit-tests/test_screen_event_handler.cpp 2015-12-01 13:53:20 +0000 |
2234 | +++ tests/unit-tests/test_screen_event_handler.cpp 2016-01-21 17:48:37 +0000 |
2235 | @@ -203,23 +203,50 @@ |
2236 | touch_screen(); |
2237 | } |
2238 | |
2239 | -TEST_F(AScreenEventHandler, keeps_display_on_temporarily_on_pointer_event) |
2240 | -{ |
2241 | +TEST_F(AScreenEventHandler, turns_on_screen_and_filters_first_pointer_event_when_screen_is_off) |
2242 | +{ |
2243 | + mock_screen.mock_mode = MirPowerMode::mir_power_mode_off; |
2244 | + EXPECT_CALL(mock_screen, |
2245 | + set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
2246 | + PowerStateChangeReason::unknown)); |
2247 | + |
2248 | + auto const event_filtered = screen_event_handler.handle(*pointer_event); |
2249 | + EXPECT_TRUE(event_filtered); |
2250 | +} |
2251 | + |
2252 | +TEST_F(AScreenEventHandler, turns_on_screen_and_propagates_keys_when_screen_is_off) |
2253 | +{ |
2254 | + mock_screen.mock_mode = MirPowerMode::mir_power_mode_off; |
2255 | + EXPECT_CALL(mock_screen, |
2256 | + set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
2257 | + PowerStateChangeReason::unknown)); |
2258 | + |
2259 | + auto const event_filtered = screen_event_handler.handle(*another_key_down_event); |
2260 | + EXPECT_FALSE(event_filtered); |
2261 | +} |
2262 | + |
2263 | +TEST_F(AScreenEventHandler, keeps_display_on_temporarily_for_pointer_event_when_screen_is_on) |
2264 | +{ |
2265 | + mock_screen.mock_mode = MirPowerMode::mir_power_mode_on; |
2266 | EXPECT_CALL(mock_screen, keep_display_on_temporarily()); |
2267 | |
2268 | move_pointer(); |
2269 | } |
2270 | |
2271 | -TEST_F(AScreenEventHandler, keeps_display_on_temporarily_on_other_keys) |
2272 | +TEST_F(AScreenEventHandler, keeps_display_on_temporarily_key_event_when_screen_is_on) |
2273 | { |
2274 | + mock_screen.mock_mode = MirPowerMode::mir_power_mode_on; |
2275 | EXPECT_CALL(mock_screen, keep_display_on_temporarily()); |
2276 | |
2277 | press_a_key(); |
2278 | } |
2279 | |
2280 | -TEST_F(AScreenEventHandler, does_not_keep_display_on_for_volume_keys) |
2281 | +TEST_F(AScreenEventHandler, does_not_affect_screen_state_for_volume_keys) |
2282 | { |
2283 | + using namespace testing; |
2284 | + |
2285 | EXPECT_CALL(mock_screen, keep_display_on_temporarily()).Times(0); |
2286 | + EXPECT_CALL(mock_screen, set_screen_power_mode(_,_)).Times(0); |
2287 | |
2288 | press_volume_keys(); |
2289 | } |
2290 | @@ -255,10 +282,12 @@ |
2291 | release_power_key(); |
2292 | } |
2293 | |
2294 | -TEST_F(AScreenEventHandler, passes_through_all_handled_events) |
2295 | +TEST_F(AScreenEventHandler, passes_through_all_handled_events_when_screen_is_on) |
2296 | { |
2297 | using namespace testing; |
2298 | |
2299 | + mock_screen.mock_mode = MirPowerMode::mir_power_mode_on; |
2300 | + |
2301 | EXPECT_FALSE(screen_event_handler.handle(*power_key_down_event)); |
2302 | EXPECT_FALSE(screen_event_handler.handle(*power_key_up_event)); |
2303 | EXPECT_FALSE(screen_event_handler.handle(*touch_event)); |