Merge lp:~kdub/unity-system-compositor/nochange-rebuild into lp:unity-system-compositor/0.2

Proposed by Kevin DuBois
Status: Rejected
Rejected by: Alberto Aguirre
Proposed branch: lp:~kdub/unity-system-compositor/nochange-rebuild
Merge into: lp:unity-system-compositor/0.2
Diff against target: 2854 lines (+1302/-542) (has conflicts)
45 files modified
CMakeLists.txt (+4/-3)
debian/changelog (+62/-3)
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 (+41/-12)
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/CMakeLists.txt (+1/-0)
tests/include/usc/test/mock_display.h (+67/-0)
tests/include/usc/test/mock_input_configuration.h (+48/-0)
tests/include/usc/test/mock_screen.h (+57/-0)
tests/include/usc/test/stub_display_configuration.h (+65/-0)
tests/integration-tests/CMakeLists.txt (+3/-0)
tests/integration-tests/test_dbus_event_loop.cpp (+8/-8)
tests/integration-tests/test_deadlock_lp1491566.cpp (+4/-68)
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_mir_screen.cpp (+5/-60)
tests/unit-tests/test_screen_event_handler.cpp (+93/-7)
tools/png2header.py (+3/-2)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~kdub/unity-system-compositor/nochange-rebuild
Reviewer Review Type Date Requested Status
Unity System Compositor Development Team Pending
Review via email: mp+277588@code.launchpad.net

This proposal supersedes a proposal from 2015-11-13.

Commit message

do not land: no change rebuild to test a mir corruption fix that breaks abi

Description of the change

do not land: no change rebuild to test a mir corruption fix that breaks abi

To post a comment you must log in.
259. By Andreas Pokorny

follow the deprecation warning and use tobytes instead of tostring.

Approved by PS Jenkins bot.

260. By Andreas Pokorny

do not premultiply RGB images

python would raise an exception if we attempt to access pixel[x,y][3] on a RGB image.
.

Approved by PS Jenkins bot.

261. By Andrea Cimitan

Updated wallpaper for spinner from unity8.

Approved by PS Jenkins bot, Andreas Pokorny.

262. By Andreas Pokorny

Change keyboard handling to scan codes.

Additionally relevant for ubuntu-pd: use none-phone keys to keep display on. Fixes: https://bugs.launchpad.net/bugs/1514059, https://bugs.launchpad.net/bugs/1520422.

Approved by Alexandros Frantzis, PS Jenkins bot.

263. By Andreas Pokorny

Catch all devices with pointer or touchpad capabilities and forward input configuration changes to them.

Approved by Alexandros Frantzis, PS Jenkins bot.

264. By Andreas Pokorny

Use actual image.bytes_per_pixel to decide about GL format of pixel data.

Approved by Alexandros Frantzis, PS Jenkins bot, Kevin DuBois.

265. By Andreas Pokorny

merge updated change log and version

266. By Andreas Pokorny

Move Mocks around and integration test utilities to reuse them in further tests.

Approved by Alexandros Frantzis, PS Jenkins bot.

267. By Andreas Pokorny

Split out the single DBusConnectionHandle from DBusConnectionThread

This allows having multiple connection names that actually work. As opposed to assigning multiple connection names to a single DBusConnection, in which case the first one wins. Fixes: https://bugs.launchpad.net/bugs/1536383.

Approved by PS Jenkins bot, Alexandros Frantzis.

268. By Michael Terry

Properly clamp mouseCursorSpeed and touchpadCursorSpeed settings.

Approved by PS Jenkins bot, Andreas Pokorny.

269. By Alexandros Frantzis

Unblank the screen when a pointer or key event arrives. Fixes: https://bugs.launchpad.net/bugs/1488413.

Approved by Andreas Pokorny, PS Jenkins bot.

270. By Kevin DuBois

bump changelog for no change rebuild

271. By Kevin DuBois

 update changelog after 0.3 landing

Unmerged revisions

271. By Kevin DuBois

 update changelog after 0.3 landing

270. By Kevin DuBois

bump changelog for no change rebuild

269. By Alexandros Frantzis

Unblank the screen when a pointer or key event arrives. Fixes: https://bugs.launchpad.net/bugs/1488413.

Approved by Andreas Pokorny, PS Jenkins bot.

268. By Michael Terry

Properly clamp mouseCursorSpeed and touchpadCursorSpeed settings.

Approved by PS Jenkins bot, Andreas Pokorny.

267. By Andreas Pokorny

Split out the single DBusConnectionHandle from DBusConnectionThread

This allows having multiple connection names that actually work. As opposed to assigning multiple connection names to a single DBusConnection, in which case the first one wins. Fixes: https://bugs.launchpad.net/bugs/1536383.

Approved by PS Jenkins bot, Alexandros Frantzis.

266. By Andreas Pokorny

Move Mocks around and integration test utilities to reuse them in further tests.

Approved by Alexandros Frantzis, PS Jenkins bot.

265. By Andreas Pokorny

merge updated change log and version

264. By Andreas Pokorny

Use actual image.bytes_per_pixel to decide about GL format of pixel data.

Approved by Alexandros Frantzis, PS Jenkins bot, Kevin DuBois.

263. By Andreas Pokorny

Catch all devices with pointer or touchpad capabilities and forward input configuration changes to them.

Approved by Alexandros Frantzis, PS Jenkins bot.

262. By Andreas Pokorny

Change keyboard handling to scan codes.

Additionally relevant for ubuntu-pd: use none-phone keys to keep display on. Fixes: https://bugs.launchpad.net/bugs/1514059, https://bugs.launchpad.net/bugs/1520422.

Approved by Alexandros Frantzis, PS Jenkins bot.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-10-08 09:54:02 +0000
+++ CMakeLists.txt 2016-01-27 14:14:14 +0000
@@ -16,8 +16,8 @@
1616
17project(UnitySystemCompositor)17project(UnitySystemCompositor)
18set(USC_VERSION_MAJOR 0)18set(USC_VERSION_MAJOR 0)
19set(USC_VERSION_MINOR 2)19set(USC_VERSION_MINOR 3)
20set(USC_VERSION_PATCH 0)20set(USC_VERSION_PATCH 1)
21set(USC_VERSION "${USC_VERSION_MAJOR}.${USC_VERSION_MINOR}.${USC_VERSION_PATCH}")21set(USC_VERSION "${USC_VERSION_MAJOR}.${USC_VERSION_MINOR}.${USC_VERSION_PATCH}")
2222
23cmake_minimum_required(VERSION 2.8)23cmake_minimum_required(VERSION 2.8)
@@ -35,7 +35,7 @@
3535
36# Use C++11 and warnings36# Use C++11 and warnings
37set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall")37set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall")
38set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")38set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
3939
40find_package(PkgConfig)40find_package(PkgConfig)
41pkg_check_modules(ANDROIDPROPS libandroid-properties)41pkg_check_modules(ANDROIDPROPS libandroid-properties)
@@ -57,6 +57,7 @@
5757
58if (MIR_ENABLE_TESTS)58if (MIR_ENABLE_TESTS)
59 find_package(Gtest REQUIRED)59 find_package(Gtest REQUIRED)
60 include_directories(${MIRCLIENT_INCLUDE_DIRS} )
60 include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})61 include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})
61 add_subdirectory(tests/)62 add_subdirectory(tests/)
62endif ()63endif ()
6364
=== modified file 'debian/changelog'
--- debian/changelog 2015-11-16 15:36:56 +0000
+++ debian/changelog 2016-01-27 14:14:14 +0000
@@ -1,6 +1,65 @@
1unity-system-compositor (0.2.0+15.10.20151008.1-0ubuntu1) wily; urgency=medium1<<<<<<< TREE
22unity-system-compositor (0.2.0+15.10.20151008.1-0ubuntu1) wily; urgency=medium
3 [ Alexandros Frantzis ]3
4 [ Alexandros Frantzis ]
5=======
6unity-system-compositor (0.3.1+16.04.20160121-0ubuntu2) UNRELEASED; urgency=medium
7
8 * no change rebuild for mir 0.18.2
9
10 -- Kevin DuBois <kevin.dubois@canonical.com> Wed, 27 Jan 2016 09:12:35 -0500
11
12unity-system-compositor (0.3.1+16.04.20160121-0ubuntu1) xenial; urgency=medium
13
14 [ Alexandros Frantzis ]
15 * Unblank the screen when a pointer or key event arrives. (LP: #1488413)
16
17 [ Andreas Pokorny ]
18 * Implement a DBus interface for setting pointer speed/acceleration.
19 (LP: #1536383)
20
21 -- Alexandros Frantzis <alexandros.frantzis@canonical.com> Thu, 21 Jan 2016 19:27:33 +0200
22
23unity-system-compositor (0.2.0+16.04.20151222.1-0ubuntu1) xenial; urgency=medium
24
25 [ Alexandros Frantzis ]
26 * tests: Fix build failure with gcc-4.9
27
28 [ Andrea Cimitan ]
29 * Updated wallpaper for spinner from unity8.
30
31 [ Andreas Pokorny ]
32 * Add clone method to StubdisplayConfigurations
33 * Change keyboard handling to scan codes. (LP: #1514059, #1520422)
34 * do not premultiply RGB images
35 * follow the deprecation warning and use tobytes instead of tostring.
36
37 [ Kevin DuBois ]
38 * Accommodate RGB images (LP: #1528279)
39 * Accommodate RGB images (LP: #1528279)
40
41 -- Kevin DuBois <kevin.dubois@canonical.com> Tue, 22 Dec 2015 19:09:40 +0000
42
43unity-system-compositor (0.2.0+16.04.20151216.1-0ubuntu1) xenial; urgency=medium
44
45 [ Alexandros Frantzis ]
46 * Merge trunk into 0.3.0
47
48 [ Andrea Cimitan ]
49 * Merge trunk into 0.3.0
50
51 [ Andreas Pokorny ]
52 * Merge trunk into 0.3.0
53
54 [ Kevin DuBois ]
55 * Merge trunk into 0.3.0
56
57 -- Kevin DuBois <kevin.dubois@canonical.com> Wed, 16 Dec 2015 22:44:38 +0000
58
59unity-system-compositor (0.2.0+15.10.20151008.1-0ubuntu1) wily; urgency=medium
60
61 [ Alexandros Frantzis ]
62>>>>>>> MERGE-SOURCE
4 * Use new versions of mir::event::make_event() overloads.63 * Use new versions of mir::event::make_event() overloads.
5 * Rebuild for Mir 0.17.64 * Rebuild for Mir 0.17.
665
766
=== modified file 'spinner/eglspinner.cpp'
--- spinner/eglspinner.cpp 2015-06-30 12:04:53 +0000
+++ spinner/eglspinner.cpp 2016-01-27 14:14:14 +0000
@@ -150,14 +150,17 @@
150void uploadTexture (GLuint id, Image& image)150void uploadTexture (GLuint id, Image& image)
151{151{
152 glBindTexture(GL_TEXTURE_2D, id);152 glBindTexture(GL_TEXTURE_2D, id);
153 GLint format = GL_RGBA;
154 if (image.bytes_per_pixel == 3)
155 format = GL_RGB;
153156
154 glTexImage2D(GL_TEXTURE_2D,157 glTexImage2D(GL_TEXTURE_2D,
155 0,158 0,
156 GL_RGBA,159 format,
157 image.width,160 image.width,
158 image.height,161 image.height,
159 0,162 0,
160 GL_RGBA,163 format,
161 GL_UNSIGNED_BYTE,164 GL_UNSIGNED_BYTE,
162 image.pixel_data);165 image.pixel_data);
163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
164167
=== modified file 'spinner/wallpaper.png'
165Binary files spinner/wallpaper.png 2015-07-03 11:43:24 +0000 and spinner/wallpaper.png 2016-01-27 14:14:14 +0000 differ168Binary files spinner/wallpaper.png 2015-07-03 11:43:24 +0000 and spinner/wallpaper.png 2016-01-27 14:14:14 +0000 differ
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2015-08-29 14:38:35 +0000
+++ src/CMakeLists.txt 2016-01-27 14:14:14 +0000
@@ -72,6 +72,7 @@
72 ${Boost_INCLUDE_DIRS}72 ${Boost_INCLUDE_DIRS}
73 ${GLESv2_INCLUDE_DIRS}73 ${GLESv2_INCLUDE_DIRS}
74 ${MIRSERVER_INCLUDE_DIRS}74 ${MIRSERVER_INCLUDE_DIRS}
75 ${MIRCLIENT_INCLUDE_DIRS}
75 ${DBUS_INCLUDE_DIRS}76 ${DBUS_INCLUDE_DIRS}
76)77)
77add_definitions(78add_definitions(
7879
=== modified file 'src/dbus_connection_handle.cpp'
--- src/dbus_connection_handle.cpp 2015-03-18 12:20:58 +0000
+++ src/dbus_connection_handle.cpp 2016-01-27 14:14:14 +0000
@@ -22,12 +22,12 @@
22#include <stdexcept>22#include <stdexcept>
23#include <boost/throw_exception.hpp>23#include <boost/throw_exception.hpp>
2424
25usc::DBusConnectionHandle::DBusConnectionHandle(const char* address)25usc::DBusConnectionHandle::DBusConnectionHandle(std::string const& address)
26{26{
27 dbus_threads_init_default();27 dbus_threads_init_default();
28 ScopedDBusError error;28 ScopedDBusError error;
2929
30 connection = dbus_connection_open_private(address, &error);30 connection = dbus_connection_open_private(address.c_str(), &error);
31 if (!connection || error)31 if (!connection || error)
32 {32 {
33 BOOST_THROW_EXCEPTION(33 BOOST_THROW_EXCEPTION(
3434
=== modified file 'src/dbus_connection_handle.h'
--- src/dbus_connection_handle.h 2015-03-17 18:17:14 +0000
+++ src/dbus_connection_handle.h 2016-01-27 14:14:14 +0000
@@ -21,13 +21,15 @@
2121
22#include <dbus/dbus.h>22#include <dbus/dbus.h>
2323
24#include <string>
25
24namespace usc26namespace usc
25{27{
2628
27class DBusConnectionHandle29class DBusConnectionHandle
28{30{
29public:31public:
30 DBusConnectionHandle(char const* address);32 DBusConnectionHandle(std::string const& address);
31 ~DBusConnectionHandle();33 ~DBusConnectionHandle();
3234
33 void request_name(char const* name) const;35 void request_name(char const* name) const;
3436
=== modified file 'src/dbus_connection_thread.cpp'
--- src/dbus_connection_thread.cpp 2015-08-25 14:27:23 +0000
+++ src/dbus_connection_thread.cpp 2016-01-27 14:14:14 +0000
@@ -17,11 +17,10 @@
17 */17 */
1818
19#include "dbus_connection_thread.h"19#include "dbus_connection_thread.h"
20#include "dbus_event_loop.h"
20#include "thread_name.h"21#include "thread_name.h"
2122
22usc::DBusConnectionThread::DBusConnectionThread(std::string const& address)23usc::DBusConnectionThread::DBusConnectionThread(std::shared_ptr<DBusEventLoop> const& loop) : dbus_event_loop(loop)
23 : dbus_connection{address.c_str()},
24 dbus_event_loop{dbus_connection}
25{24{
26 std::promise<void> event_loop_started;25 std::promise<void> event_loop_started;
27 auto event_loop_started_future = event_loop_started.get_future();26 auto event_loop_started_future = event_loop_started.get_future();
@@ -30,7 +29,7 @@
30 [this,&event_loop_started]29 [this,&event_loop_started]
31 {30 {
32 usc::set_thread_name("USC/DBus");31 usc::set_thread_name("USC/DBus");
33 dbus_event_loop.run(event_loop_started);32 dbus_event_loop->run(event_loop_started);
34 });33 });
3534
36 event_loop_started_future.wait();35 event_loop_started_future.wait();
@@ -38,16 +37,11 @@
3837
39usc::DBusConnectionThread::~DBusConnectionThread()38usc::DBusConnectionThread::~DBusConnectionThread()
40{39{
41 dbus_event_loop.stop();40 dbus_event_loop->stop();
42 dbus_loop_thread.join();41 dbus_loop_thread.join();
43}42}
4443
45usc::DBusConnectionHandle const& usc::DBusConnectionThread::connection() const
46{
47 return dbus_connection;
48}
49
50usc::DBusEventLoop & usc::DBusConnectionThread::loop()44usc::DBusEventLoop & usc::DBusConnectionThread::loop()
51{45{
52 return dbus_event_loop;46 return *dbus_event_loop;
53}47}
5448
=== modified file 'src/dbus_connection_thread.h'
--- src/dbus_connection_thread.h 2015-08-25 14:27:23 +0000
+++ src/dbus_connection_thread.h 2016-01-27 14:14:14 +0000
@@ -19,25 +19,21 @@
19#ifndef USC_DBUS_CONNECTION_THREAD_H_19#ifndef USC_DBUS_CONNECTION_THREAD_H_
20#define USC_DBUS_CONNECTION_THREAD_H_20#define USC_DBUS_CONNECTION_THREAD_H_
2121
22#include "dbus_connection_handle.h"
23#include "dbus_event_loop.h"
24
25#include <thread>22#include <thread>
2623
27namespace usc24namespace usc
28{25{
2926
27class DBusEventLoop;
30class DBusConnectionThread28class DBusConnectionThread
31{29{
32public:30public:
33 DBusConnectionThread(std::string const& address);31 DBusConnectionThread(std::shared_ptr<DBusEventLoop> const& thread);
34 ~DBusConnectionThread();32 ~DBusConnectionThread();
35 DBusConnectionHandle const& connection() const;
36 DBusEventLoop & loop();33 DBusEventLoop & loop();
3734
38private:35private:
39 DBusConnectionHandle dbus_connection;36 std::shared_ptr<DBusEventLoop> dbus_event_loop;
40 DBusEventLoop dbus_event_loop;
41 std::thread dbus_loop_thread;37 std::thread dbus_loop_thread;
42};38};
4339
4440
=== modified file 'src/dbus_event_loop.cpp'
--- src/dbus_event_loop.cpp 2015-03-18 12:20:58 +0000
+++ src/dbus_event_loop.cpp 2016-01-27 14:14:14 +0000
@@ -21,6 +21,7 @@
21#endif21#endif
2222
23#include "dbus_event_loop.h"23#include "dbus_event_loop.h"
24#include "dbus_connection_handle.h"
2425
25#include <algorithm>26#include <algorithm>
2627
@@ -78,9 +79,8 @@
7879
79}80}
8081
81usc::DBusEventLoop::DBusEventLoop(DBusConnection* connection)82usc::DBusEventLoop::DBusEventLoop()
82 : connection{connection},83 : running{false},
83 running{false},
84 epoll_fd{epoll_create1(EPOLL_CLOEXEC)}84 epoll_fd{epoll_create1(EPOLL_CLOEXEC)}
85{85{
86 if (epoll_fd == -1)86 if (epoll_fd == -1)
@@ -109,9 +109,17 @@
109 BOOST_THROW_EXCEPTION(109 BOOST_THROW_EXCEPTION(
110 std::system_error(errno, std::system_category(), "epoll_ctl"));110 std::system_error(errno, std::system_category(), "epoll_ctl"));
111 }111 }
112}
113
114void usc::DBusEventLoop::add_connection(std::shared_ptr<DBusConnectionHandle> const& connection)
115{
116 if (running)
117 BOOST_THROW_EXCEPTION(std::logic_error("Connection added after dbus event loop started"));
118
119 connections.push_back(connection);
112120
113 dbus_connection_set_watch_functions(121 dbus_connection_set_watch_functions(
114 connection,122 *connection,
115 DBusEventLoop::static_add_watch,123 DBusEventLoop::static_add_watch,
116 DBusEventLoop::static_remove_watch,124 DBusEventLoop::static_remove_watch,
117 DBusEventLoop::static_toggle_watch,125 DBusEventLoop::static_toggle_watch,
@@ -119,7 +127,7 @@
119 nullptr);127 nullptr);
120128
121 dbus_connection_set_timeout_functions(129 dbus_connection_set_timeout_functions(
122 connection,130 *connection,
123 DBusEventLoop::static_add_timeout,131 DBusEventLoop::static_add_timeout,
124 DBusEventLoop::static_remove_timeout,132 DBusEventLoop::static_remove_timeout,
125 DBusEventLoop::static_toggle_timeout,133 DBusEventLoop::static_toggle_timeout,
@@ -127,7 +135,7 @@
127 nullptr);135 nullptr);
128136
129 dbus_connection_set_wakeup_main_function(137 dbus_connection_set_wakeup_main_function(
130 connection,138 *connection,
131 DBusEventLoop::static_wake_up_loop,139 DBusEventLoop::static_wake_up_loop,
132 this, nullptr);140 this, nullptr);
133}141}
@@ -136,14 +144,17 @@
136{144{
137 stop();145 stop();
138146
139 dbus_connection_set_watch_functions(147 for(auto connection : connections)
140 connection, nullptr, nullptr, nullptr, nullptr, nullptr);148 {
141149 dbus_connection_set_watch_functions(
142 dbus_connection_set_timeout_functions(150 *connection, nullptr, nullptr, nullptr, nullptr, nullptr);
143 connection, nullptr, nullptr, nullptr, nullptr, nullptr);151
144152 dbus_connection_set_timeout_functions(
145 dbus_connection_set_wakeup_main_function(153 *connection, nullptr, nullptr, nullptr, nullptr, nullptr);
146 connection, nullptr, nullptr, nullptr);154
155 dbus_connection_set_wakeup_main_function(
156 *connection, nullptr, nullptr, nullptr);
157 }
147}158}
148159
149void usc::DBusEventLoop::run(std::promise<void>& started)160void usc::DBusEventLoop::run(std::promise<void>& started)
@@ -187,14 +198,17 @@
187198
188 dispatch_actions();199 dispatch_actions();
189200
190 dbus_connection_flush(connection);201 for (auto connection : connections)
202 {
203 dbus_connection_flush(*connection);
191204
192 while (dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS)205 while (dbus_connection_dispatch(*connection) == DBUS_DISPATCH_DATA_REMAINS);
193 continue;206 }
194 }207 }
195208
196 // Flush any remaining outgoing messages209 // Flush any remaining outgoing messages
197 dbus_connection_flush(connection);210 for (auto connection : connections)
211 dbus_connection_flush(*connection);
198}212}
199213
200void usc::DBusEventLoop::stop()214void usc::DBusEventLoop::stop()
201215
=== modified file 'src/dbus_event_loop.h'
--- src/dbus_event_loop.h 2015-03-18 11:56:28 +0000
+++ src/dbus_event_loop.h 2016-01-27 14:14:14 +0000
@@ -30,13 +30,15 @@
3030
31namespace usc31namespace usc
32{32{
33class DBusConnectionHandle;
3334
34class DBusEventLoop35class DBusEventLoop
35{36{
36public:37public:
37 DBusEventLoop(DBusConnection* connection);38 DBusEventLoop();
38 ~DBusEventLoop();39 ~DBusEventLoop();
3940
41 void add_connection(std::shared_ptr<DBusConnectionHandle> const& connection);
40 void run(std::promise<void>& started);42 void run(std::promise<void>& started);
41 void stop();43 void stop();
4244
@@ -70,10 +72,10 @@
70 static void static_toggle_timeout(DBusTimeout* timeout, void* data);72 static void static_toggle_timeout(DBusTimeout* timeout, void* data);
71 static void static_wake_up_loop(void* data);73 static void static_wake_up_loop(void* data);
7274
73 DBusConnection* const connection;
74 std::atomic<bool> running;75 std::atomic<bool> running;
7576
76 std::mutex mutex;77 std::mutex mutex;
78 std::vector<std::shared_ptr<DBusConnectionHandle>> connections;
77 std::vector<DBusWatch*> watches;79 std::vector<DBusWatch*> watches;
78 std::vector<std::pair<DBusTimeout*,mir::Fd>> timeouts;80 std::vector<std::pair<DBusTimeout*,mir::Fd>> timeouts;
79 std::vector<std::function<void(void)>> actions;81 std::vector<std::function<void(void)>> actions;
8082
=== modified file 'src/mir_input_configuration.cpp'
--- src/mir_input_configuration.cpp 2015-08-26 08:26:35 +0000
+++ src/mir_input_configuration.cpp 2016-01-27 14:14:14 +0000
@@ -15,58 +15,173 @@
15 */15 */
1616
17#include "mir_input_configuration.h"17#include "mir_input_configuration.h"
1818#include "mir/input/input_device_observer.h"
19// just a stub at the moment, this implementation will be supposed to19#include "mir/input/input_device_hub.h"
20// observe available input devices and apply settings to it.20#include "mir/input/pointer_configuration.h"
2121#include "mir/input/touchpad_configuration.h"
22#include "mir/input/device.h"
23
24namespace mi = mir::input;
25
26namespace
27{
28struct DeviceObserver : mi::InputDeviceObserver
29{
30 usc::MirInputConfiguration* conf;
31 DeviceObserver(usc::MirInputConfiguration* conf)
32 : conf{conf}
33 {
34 }
35
36 void device_added(std::shared_ptr<mi::Device> const& device) override
37 {
38 conf->device_added(device);
39 }
40
41 void device_changed(std::shared_ptr<mi::Device> const&) override
42 {
43 }
44
45 void device_removed(std::shared_ptr<mi::Device> const&device) override
46 {
47 conf->device_removed(device);
48 }
49
50 void changes_complete() override
51 {
52 }
53};
54}
55
56
57usc::MirInputConfiguration::MirInputConfiguration(std::shared_ptr<mi::InputDeviceHub> const& device_hub) :
58 observer{std::make_shared<DeviceObserver>(this)}
59{
60 device_hub->add_observer(observer);
61}
62
63void usc::MirInputConfiguration::device_removed(std::shared_ptr<mi::Device> const& dev)
64{
65 std::lock_guard<decltype(devices_lock)> lock(devices_lock);
66 touchpads.erase(dev);
67 mice.erase(dev);
68}
69
70void usc::MirInputConfiguration::configure_mouse(mi::Device& dev)
71{
72 dev.apply_pointer_configuration(mouse_pointer_config);
73}
74
75void usc::MirInputConfiguration::configure_touchpad(mi::Device& dev)
76{
77 dev.apply_pointer_configuration(touchpad_pointer_config);
78 dev.apply_touchpad_configuration(touchpad_config);
79}
80
81void usc::MirInputConfiguration::device_added(std::shared_ptr<mi::Device> const& dev)
82{
83 std::lock_guard<decltype(devices_lock)> lock(devices_lock);
84
85 if (contains(dev->capabilities(), mi::DeviceCapability::touchpad))
86 {
87 touchpads.insert(dev);
88 configure_touchpad(*dev);
89 }
90 else if (contains(dev->capabilities(), mi::DeviceCapability::pointer))
91 {
92 mice.insert(dev);
93 configure_mouse(*dev);
94 }
95}
96
97void usc::MirInputConfiguration::update_touchpads()
98{
99 for (auto const& touchpad : touchpads)
100 configure_touchpad(*touchpad);
101}
102
103void usc::MirInputConfiguration::update_mice()
104{
105 for (auto const& mouse : mice)
106 configure_mouse(*mouse);
107}
22108
23void usc::MirInputConfiguration::set_mouse_primary_button(int32_t button)109void usc::MirInputConfiguration::set_mouse_primary_button(int32_t button)
24{110{
25 mouse_primary_button = button;111 mouse_pointer_config.handedness = button == 0 ?
112 mir_pointer_handedness_right :
113 mir_pointer_handedness_left;
114 update_mice();
26}115}
27116
28void usc::MirInputConfiguration::set_mouse_cursor_speed(double speed)117void usc::MirInputConfiguration::set_mouse_cursor_speed(double speed)
29{118{
30 mouse_cursor_speed = speed;119 double clamped = speed;
120 if (clamped < 0.0)
121 clamped = 0.0;
122 if (clamped > 1.0)
123 clamped = 1.0;
124 mouse_pointer_config.cursor_acceleration_bias = clamped * 2.0 - 1.0;
125 update_mice();
31}126}
32127
33void usc::MirInputConfiguration::set_mouse_scroll_speed(double speed)128void usc::MirInputConfiguration::set_mouse_scroll_speed(double speed)
34{129{
35 mouse_scroll_speed = speed;130 mouse_pointer_config.horizontal_scroll_scale = speed;
131 mouse_pointer_config.vertical_scroll_scale = speed;
132 update_mice();
36}133}
37134
38void usc::MirInputConfiguration::set_touchpad_primary_button(int32_t button)135void usc::MirInputConfiguration::set_touchpad_primary_button(int32_t button)
39{136{
40 touchpad_primary_button = button;137 touchpad_pointer_config.handedness = button == 0?mir_pointer_handedness_right:mir_pointer_handedness_left;
138 update_touchpads();
41}139}
42140
43void usc::MirInputConfiguration::set_touchpad_cursor_speed(double speed)141void usc::MirInputConfiguration::set_touchpad_cursor_speed(double speed)
44{142{
45 touchpad_cursor_speed = speed;143 double clamped = speed;
144 if (clamped < 0.0)
145 clamped = 0.0;
146 if (clamped > 1.0)
147 clamped = 1.0;
148 touchpad_pointer_config.cursor_acceleration_bias = clamped * 2.0 - 1.0;
149 update_touchpads();
46}150}
47151
48void usc::MirInputConfiguration::set_touchpad_scroll_speed(double speed)152void usc::MirInputConfiguration::set_touchpad_scroll_speed(double speed)
49{153{
50 touchpad_scroll_speed = speed;154 touchpad_pointer_config.horizontal_scroll_scale = speed;
155 touchpad_pointer_config.vertical_scroll_scale = speed;
156 update_touchpads();
51}157}
52158
53void usc::MirInputConfiguration::set_two_finger_scroll(bool enable)159void usc::MirInputConfiguration::set_two_finger_scroll(bool enable)
54{160{
55 two_finger_scroll = enable;161 MirTouchpadScrollModes current = touchpad_config.scroll_mode;
162 if (enable)
163 current |= mir_touchpad_scroll_mode_two_finger_scroll;
164 else
165 current &= ~mir_touchpad_scroll_mode_two_finger_scroll;
166 touchpad_config.scroll_mode = current;
167 update_touchpads();
56}168}
57169
58void usc::MirInputConfiguration::set_tap_to_click(bool enable)170void usc::MirInputConfiguration::set_tap_to_click(bool enable)
59{171{
60 tap_to_click = enable;172 touchpad_config.tap_to_click = enable;
173 update_touchpads();
61}174}
62175
63void usc::MirInputConfiguration::set_disable_touchpad_while_typing(bool enable)176void usc::MirInputConfiguration::set_disable_touchpad_while_typing(bool enable)
64{177{
65 disable_while_typing = enable;178 touchpad_config.disable_while_typing = enable;
179 update_touchpads();
66}180}
67181
68void usc::MirInputConfiguration::set_disable_touchpad_with_mouse(bool enable)182void usc::MirInputConfiguration::set_disable_touchpad_with_mouse(bool enable)
69{183{
70 disable_with_mouse = enable;184 touchpad_config.disable_with_mouse = enable;
185 update_touchpads();
71}186}
72187
73188
=== modified file 'src/mir_input_configuration.h'
--- src/mir_input_configuration.h 2015-08-26 08:26:35 +0000
+++ src/mir_input_configuration.h 2016-01-27 14:14:14 +0000
@@ -14,18 +14,36 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */15 */
1616
17
18#ifndef USC_MIR_INPUT_CONFIGRATION_H_17#ifndef USC_MIR_INPUT_CONFIGRATION_H_
19#define USC_MIR_INPUT_CONFIGRATION_H_18#define USC_MIR_INPUT_CONFIGRATION_H_
2019
21#include "input_configuration.h"20#include "input_configuration.h"
2221
22#include "mir/input/touchpad_configuration.h"
23#include "mir/input/pointer_configuration.h"
24
25#include <memory>
26#include <thread>
27#include <mutex>
28#include <unordered_set>
29
30namespace mir
31{
32namespace input
33{
34class InputDeviceHub;
35class Device;
36class InputDeviceObserver;
37}
38}
39
23namespace usc40namespace usc
24{41{
2542
26struct MirInputConfiguration : InputConfiguration43struct MirInputConfiguration : InputConfiguration
27{44{
28public:45public:
46 MirInputConfiguration(std::shared_ptr<mir::input::InputDeviceHub> const& device_hub);
29 void set_mouse_primary_button(int32_t button) override;47 void set_mouse_primary_button(int32_t button) override;
30 void set_mouse_cursor_speed(double speed) override;48 void set_mouse_cursor_speed(double speed) override;
31 void set_mouse_scroll_speed(double speed) override;49 void set_mouse_scroll_speed(double speed) override;
@@ -36,17 +54,22 @@
36 void set_tap_to_click(bool enable) override;54 void set_tap_to_click(bool enable) override;
37 void set_disable_touchpad_while_typing(bool enable) override;55 void set_disable_touchpad_while_typing(bool enable) override;
38 void set_disable_touchpad_with_mouse(bool enable) override;56 void set_disable_touchpad_with_mouse(bool enable) override;
57
58 void device_added(std::shared_ptr<mir::input::Device> const& device);
59 void device_removed(std::shared_ptr<mir::input::Device> const& device);
39private:60private:
40 int32_t mouse_primary_button{0};61 void configure_mouse(mir::input::Device& dev);
41 double mouse_cursor_speed{0.5};62 void configure_touchpad(mir::input::Device& dev);
42 double mouse_scroll_speed{0.5};63 void update_touchpads();
43 int32_t touchpad_primary_button{0};64 void update_mice();
44 double touchpad_cursor_speed{0.5};65
45 double touchpad_scroll_speed{0.5};66 std::shared_ptr<mir::input::InputDeviceObserver> const observer;
46 bool two_finger_scroll{false};67 std::mutex devices_lock;
47 bool tap_to_click{false};68 std::unordered_set<std::shared_ptr<mir::input::Device>> touchpads;
48 bool disable_while_typing{false};69 std::unordered_set<std::shared_ptr<mir::input::Device>> mice;
49 bool disable_with_mouse{true};70 mir::input::PointerConfiguration mouse_pointer_config;
71 mir::input::PointerConfiguration touchpad_pointer_config;
72 mir::input::TouchpadConfiguration touchpad_config;
50};73};
5174
52}75}
5376
=== modified file 'src/powerd_mediator.cpp'
--- src/powerd_mediator.cpp 2015-07-17 12:43:46 +0000
+++ src/powerd_mediator.cpp 2016-01-27 14:14:14 +0000
@@ -45,8 +45,7 @@
45}45}
4646
47usc::PowerdMediator::PowerdMediator(std::string const& bus_addr)47usc::PowerdMediator::PowerdMediator(std::string const& bus_addr)
48 : connection{bus_addr.c_str()},48 : connection{std::make_shared<DBusConnectionHandle>(bus_addr.c_str())},
49 dbus_event_loop{connection},
50 pending_suspend_block_request{false},49 pending_suspend_block_request{false},
51 dim_brightness_{10},50 dim_brightness_{10},
52 min_brightness_{0},51 min_brightness_{0},
@@ -59,17 +58,18 @@
59 proximity_enabled{false},58 proximity_enabled{false},
60 sys_state{SysState::unknown}59 sys_state{SysState::unknown}
61{60{
62 connection.add_match(61 dbus_event_loop.add_connection(connection);
62 connection->add_match(
63 "type='signal',"63 "type='signal',"
64 "sender='com.canonical.powerd',"64 "sender='com.canonical.powerd',"
65 "interface='com.canonical.powerd',"65 "interface='com.canonical.powerd',"
66 "member='SysPowerStateChange'");66 "member='SysPowerStateChange'");
67 connection.add_match(67 connection->add_match(
68 "type='signal',"68 "type='signal',"
69 "sender='org.freedesktop.DBus',"69 "sender='org.freedesktop.DBus',"
70 "interface='org.freedesktop.DBus',"70 "interface='org.freedesktop.DBus',"
71 "member='NameOwnerChanged'");71 "member='NameOwnerChanged'");
72 connection.add_filter(handle_dbus_message_thunk, this);72 connection->add_filter(handle_dbus_message_thunk, this);
7373
74 std::promise<void> event_loop_started;74 std::promise<void> event_loop_started;
75 auto event_loop_started_future = event_loop_started.get_future();75 auto event_loop_started_future = event_loop_started.get_future();
@@ -477,7 +477,7 @@
477 [this, &msg, &reply_promise]477 [this, &msg, &reply_promise]
478 {478 {
479 auto const reply = dbus_connection_send_with_reply_and_block(479 auto const reply = dbus_connection_send_with_reply_and_block(
480 connection, msg, DBUS_TIMEOUT_USE_DEFAULT, nullptr);480 *connection, msg, DBUS_TIMEOUT_USE_DEFAULT, nullptr);
481481
482 reply_promise.set_value(reply);482 reply_promise.set_value(reply);
483 };483 };
484484
=== modified file 'src/powerd_mediator.h'
--- src/powerd_mediator.h 2015-07-17 12:43:46 +0000
+++ src/powerd_mediator.h 2016-01-27 14:14:14 +0000
@@ -88,7 +88,7 @@
88 void invoke(char const* method, int first_arg_type, ...);88 void invoke(char const* method, int first_arg_type, ...);
89 usc::DBusMessageHandle invoke_with_reply(char const* method, int first_arg_type, ...);89 usc::DBusMessageHandle invoke_with_reply(char const* method, int first_arg_type, ...);
9090
91 usc::DBusConnectionHandle connection;91 std::shared_ptr<usc::DBusConnectionHandle> connection;
92 usc::DBusEventLoop dbus_event_loop;92 usc::DBusEventLoop dbus_event_loop;
93 std::thread dbus_loop_thread;93 std::thread dbus_loop_thread;
9494
9595
=== modified file 'src/screen_event_handler.cpp'
--- src/screen_event_handler.cpp 2015-07-13 12:35:41 +0000
+++ src/screen_event_handler.cpp 2016-01-27 14:14:14 +0000
@@ -21,6 +21,7 @@
21#include <mir/time/alarm_factory.h>21#include <mir/time/alarm_factory.h>
22#include <mir_toolkit/events/input/input_event.h>22#include <mir_toolkit/events/input/input_event.h>
2323
24#include "linux/input.h"
24#include <cstdio>25#include <cstdio>
2526
26usc::ScreenEventHandler::ScreenEventHandler(27usc::ScreenEventHandler::ScreenEventHandler(
@@ -45,8 +46,6 @@
4546
46bool usc::ScreenEventHandler::handle(MirEvent const& event)47bool usc::ScreenEventHandler::handle(MirEvent const& event)
47{48{
48 static const int32_t POWER_KEY_CODE = 26;
49
50 if (mir_event_get_type(&event) != mir_event_type_input)49 if (mir_event_get_type(&event) != mir_event_type_input)
51 return false;50 return false;
5251
@@ -56,21 +55,36 @@
56 if (input_event_type == mir_input_event_type_key)55 if (input_event_type == mir_input_event_type_key)
57 {56 {
58 auto const kev = mir_input_event_get_keyboard_event(input_event);57 auto const kev = mir_input_event_get_keyboard_event(input_event);
59 if (mir_keyboard_event_key_code(kev) != POWER_KEY_CODE)58 if (mir_keyboard_event_scan_code(kev) == KEY_POWER)
60 return false;59 {
6160 auto const action = mir_keyboard_event_action(kev);
62 auto const action = mir_keyboard_event_action(kev);61 if (action == mir_keyboard_action_down)
63 if (action == mir_keyboard_action_down)62 power_key_down();
64 power_key_down();63 else if (action == mir_keyboard_action_up)
65 else if (action == mir_keyboard_action_up)64 power_key_up();
66 power_key_up();65 }
66 // we might want to come up with a whole range of media player related keys
67 else if (mir_keyboard_event_scan_code(kev) == KEY_VOLUMEDOWN||
68 mir_keyboard_event_scan_code(kev) == KEY_VOLUMEUP)
69 {
70 // do not keep display on when interacting with media player
71 }
72 else
73 {
74 keep_or_turn_screen_on();
75 }
67 }76 }
68 else if (input_event_type == mir_input_event_type_touch ||77 else if (input_event_type == mir_input_event_type_touch)
69 input_event_type == mir_input_event_type_pointer)
70 {78 {
71 std::lock_guard<std::mutex> lock{guard};79 std::lock_guard<std::mutex> lock{guard};
72 screen->keep_display_on_temporarily();80 screen->keep_display_on_temporarily();
73 }81 }
82 else if (input_event_type == mir_input_event_type_pointer)
83 {
84 bool const filter_out_event = screen->get_screen_power_mode() != mir_power_mode_on;
85 keep_or_turn_screen_on();
86 return filter_out_event;
87 }
7488
75 return false;89 return false;
76}90}
@@ -128,3 +142,18 @@
128 MirPowerMode::mir_power_mode_on, PowerStateChangeReason::power_key);142 MirPowerMode::mir_power_mode_on, PowerStateChangeReason::power_key);
129 long_press_detected = true;143 long_press_detected = true;
130}144}
145
146void usc::ScreenEventHandler::keep_or_turn_screen_on()
147{
148 std::lock_guard<std::mutex> lock{guard};
149
150 if (screen->get_screen_power_mode() == mir_power_mode_off)
151 {
152 screen->set_screen_power_mode(
153 MirPowerMode::mir_power_mode_on, PowerStateChangeReason::unknown);
154 }
155 else
156 {
157 screen->keep_display_on_temporarily();
158 }
159}
131160
=== modified file 'src/screen_event_handler.h'
--- src/screen_event_handler.h 2015-04-29 14:39:19 +0000
+++ src/screen_event_handler.h 2016-01-27 14:14:14 +0000
@@ -56,6 +56,7 @@
56 void power_key_down();56 void power_key_down();
57 void shutdown_alarm_notification();57 void shutdown_alarm_notification();
58 void long_press_notification();58 void long_press_notification();
59 void keep_or_turn_screen_on();
5960
60 std::mutex guard;61 std::mutex guard;
61 std::shared_ptr<Screen> const screen;62 std::shared_ptr<Screen> const screen;
6263
=== modified file 'src/server.cpp'
--- src/server.cpp 2015-09-30 10:53:54 +0000
+++ src/server.cpp 2016-01-27 14:14:14 +0000
@@ -28,6 +28,7 @@
28#include "unity_screen_service.h"28#include "unity_screen_service.h"
29#include "unity_input_service.h"29#include "unity_input_service.h"
30#include "dbus_connection_thread.h"30#include "dbus_connection_thread.h"
31#include "dbus_event_loop.h"
31#include "display_configuration_policy.h"32#include "display_configuration_policy.h"
32#include "steady_clock.h"33#include "steady_clock.h"
3334
@@ -241,7 +242,7 @@
241 return input_configuration(242 return input_configuration(
242 [this]243 [this]
243 {244 {
244 return std::make_shared<MirInputConfiguration>();245 return std::make_shared<MirInputConfiguration>(the_input_device_hub());
245 });246 });
246}247}
247248
@@ -292,12 +293,22 @@
292 });293 });
293}294}
294295
296std::shared_ptr<usc::DBusEventLoop> usc::Server::the_dbus_event_loop()
297{
298 return dbus_loop(
299 [this]
300 {
301 return std::make_shared<DBusEventLoop>();
302 });
303
304}
305
295std::shared_ptr<usc::DBusConnectionThread> usc::Server::the_dbus_connection_thread()306std::shared_ptr<usc::DBusConnectionThread> usc::Server::the_dbus_connection_thread()
296{307{
297 return dbus_thread(308 return dbus_thread(
298 [this]309 [this]
299 {310 {
300 return std::make_shared<DBusConnectionThread>(dbus_bus_address());311 return std::make_shared<DBusConnectionThread>(the_dbus_event_loop());
301 });312 });
302}313}
303314
@@ -307,7 +318,8 @@
307 [this]318 [this]
308 {319 {
309 return std::make_shared<UnityScreenService>(320 return std::make_shared<UnityScreenService>(
310 the_dbus_connection_thread(),321 the_dbus_event_loop(),
322 dbus_bus_address(),
311 the_screen());323 the_screen());
312 });324 });
313}325}
@@ -318,7 +330,8 @@
318 [this]330 [this]
319 {331 {
320 return std::make_shared<UnityInputService>(332 return std::make_shared<UnityInputService>(
321 the_dbus_connection_thread(),333 the_dbus_event_loop(),
334 dbus_bus_address(),
322 the_input_configuration());335 the_input_configuration());
323 });336 });
324}337}
325338
=== modified file 'src/server.h'
--- src/server.h 2015-09-30 10:53:54 +0000
+++ src/server.h 2016-01-27 14:14:14 +0000
@@ -45,6 +45,7 @@
45class InputConfiguration;45class InputConfiguration;
46class UnityInputService;46class UnityInputService;
47class DBusConnectionThread;47class DBusConnectionThread;
48class DBusEventLoop;
48class Clock;49class Clock;
4950
50class Server : private mir::Server51class Server : private mir::Server
@@ -69,6 +70,7 @@
69 virtual std::shared_ptr<ScreenHardware> the_screen_hardware();70 virtual std::shared_ptr<ScreenHardware> the_screen_hardware();
70 virtual std::shared_ptr<UnityScreenService> the_unity_screen_service();71 virtual std::shared_ptr<UnityScreenService> the_unity_screen_service();
71 virtual std::shared_ptr<UnityInputService> the_unity_input_service();72 virtual std::shared_ptr<UnityInputService> the_unity_input_service();
73 virtual std::shared_ptr<DBusEventLoop> the_dbus_event_loop();
72 virtual std::shared_ptr<DBusConnectionThread> the_dbus_connection_thread();74 virtual std::shared_ptr<DBusConnectionThread> the_dbus_connection_thread();
73 virtual std::shared_ptr<Clock> the_clock();75 virtual std::shared_ptr<Clock> the_clock();
7476
@@ -182,6 +184,7 @@
182 mir::CachedPtr<mir::input::EventFilter> screen_event_handler;184 mir::CachedPtr<mir::input::EventFilter> screen_event_handler;
183 mir::CachedPtr<ScreenHardware> screen_hardware;185 mir::CachedPtr<ScreenHardware> screen_hardware;
184 mir::CachedPtr<DBusConnectionThread> dbus_thread;186 mir::CachedPtr<DBusConnectionThread> dbus_thread;
187 mir::CachedPtr<DBusEventLoop> dbus_loop;
185 mir::CachedPtr<UnityScreenService> unity_screen_service;188 mir::CachedPtr<UnityScreenService> unity_screen_service;
186 mir::CachedPtr<UnityInputService> unity_input_service;189 mir::CachedPtr<UnityInputService> unity_input_service;
187 mir::CachedPtr<Clock> clock;190 mir::CachedPtr<Clock> clock;
188191
=== modified file 'src/system_compositor.cpp'
--- src/system_compositor.cpp 2015-08-26 08:26:35 +0000
+++ src/system_compositor.cpp 2016-01-27 14:14:14 +0000
@@ -22,6 +22,7 @@
22#include "dm_connection.h"22#include "dm_connection.h"
2323
24#include <mir/input/composite_event_filter.h>24#include <mir/input/composite_event_filter.h>
25#include <mir/input/input_device_hub.h>
25#include <mir/abnormal_exit.h>26#include <mir/abnormal_exit.h>
2627
27#include <cerrno>28#include <cerrno>
@@ -123,6 +124,7 @@
123124
124 unity_screen_service = server->the_unity_screen_service();125 unity_screen_service = server->the_unity_screen_service();
125 unity_input_service = server->the_unity_input_service();126 unity_input_service = server->the_unity_input_service();
127 dbus_service_thread = server->the_dbus_connection_thread();
126 }128 }
127 });129 });
128130
129131
=== modified file 'src/system_compositor.h'
--- src/system_compositor.h 2015-08-26 08:26:35 +0000
+++ src/system_compositor.h 2016-01-27 14:14:14 +0000
@@ -40,6 +40,7 @@
40class Screen;40class Screen;
41class UnityScreenService;41class UnityScreenService;
42class UnityInputService;42class UnityInputService;
43class DBusConnectionThread;
4344
44class SystemCompositor45class SystemCompositor
45{46{
@@ -55,6 +56,7 @@
55 std::shared_ptr<mir::input::EventFilter> screen_event_handler;56 std::shared_ptr<mir::input::EventFilter> screen_event_handler;
56 std::shared_ptr<UnityScreenService> unity_screen_service;57 std::shared_ptr<UnityScreenService> unity_screen_service;
57 std::shared_ptr<UnityInputService> unity_input_service;58 std::shared_ptr<UnityInputService> unity_input_service;
59 std::shared_ptr<DBusConnectionThread> dbus_service_thread;
58};60};
5961
60}62}
6163
=== modified file 'src/unity_input_service.cpp'
--- src/unity_input_service.cpp 2015-08-28 15:57:25 +0000
+++ src/unity_input_service.cpp 2016-01-27 14:14:14 +0000
@@ -19,7 +19,7 @@
19#include "unity_input_service.h"19#include "unity_input_service.h"
20#include "input_configuration.h"20#include "input_configuration.h"
21#include "dbus_message_handle.h"21#include "dbus_message_handle.h"
22#include "dbus_connection_thread.h"22#include "dbus_event_loop.h"
23#include "scoped_dbus_error.h"23#include "scoped_dbus_error.h"
2424
25#include "unity_input_service_introspection.h" // autogenerated25#include "unity_input_service_introspection.h" // autogenerated
@@ -33,15 +33,14 @@
3333
34}34}
3535
36usc::UnityInputService::UnityInputService(36usc::UnityInputService::UnityInputService(std::shared_ptr<usc::DBusEventLoop> const& loop,
37 std::shared_ptr<usc::DBusConnectionThread> const& dbus,37 std::string const& address,
38 std::shared_ptr<usc::InputConfiguration> const& input_config)38 std::shared_ptr<usc::InputConfiguration> const& input_config)
39 : dbus{dbus},39 : loop{loop}, connection{std::make_shared<DBusConnectionHandle>(address.c_str())}, input_config{input_config}
40 input_config{input_config}
41{40{
42 auto const& connection = dbus->connection();41 loop->add_connection(connection);
43 connection.request_name(dbus_input_service_name);42 connection->request_name(dbus_input_service_name);
44 connection.add_filter(handle_dbus_message_thunk, this);43 connection->add_filter(handle_dbus_message_thunk, this);
45}44}
4645
47::DBusHandlerResult usc::UnityInputService::handle_dbus_message_thunk(46::DBusHandlerResult usc::UnityInputService::handle_dbus_message_thunk(
@@ -63,7 +62,7 @@
63 (input_config.get()->*method)(flag);62 (input_config.get()->*method)(flag);
6463
65 DBusMessageHandle reply{dbus_message_new_method_return(message)};64 DBusMessageHandle reply{dbus_message_new_method_return(message)};
66 dbus_connection_send(dbus->connection(), reply, nullptr);65 dbus_connection_send(*connection, reply, nullptr);
67 }66 }
68}67}
6968
@@ -79,7 +78,7 @@
79 (input_config.get()->*method)(value);78 (input_config.get()->*method)(value);
8079
81 DBusMessageHandle reply{dbus_message_new_method_return(message)};80 DBusMessageHandle reply{dbus_message_new_method_return(message)};
82 dbus_connection_send(dbus->connection(), reply, nullptr);81 dbus_connection_send(*connection, reply, nullptr);
83 }82 }
84}83}
8584
@@ -95,7 +94,7 @@
95 (input_config.get()->*method)(value);94 (input_config.get()->*method)(value);
9695
97 DBusMessageHandle reply{dbus_message_new_method_return(message)};96 DBusMessageHandle reply{dbus_message_new_method_return(message)};
98 dbus_connection_send(dbus->connection(), reply, nullptr);97 dbus_connection_send(*connection, reply, nullptr);
99 }98 }
100}99}
101100
@@ -151,4 +150,3 @@
151150
152 return DBUS_HANDLER_RESULT_HANDLED;151 return DBUS_HANDLER_RESULT_HANDLED;
153}152}
154
155153
=== modified file 'src/unity_input_service.h'
--- src/unity_input_service.h 2015-08-26 08:00:27 +0000
+++ src/unity_input_service.h 2016-01-27 14:14:14 +0000
@@ -20,18 +20,20 @@
20#define USC_UNITY_INPUT_SERVICE_H_20#define USC_UNITY_INPUT_SERVICE_H_
2121
22#include <dbus/dbus.h>22#include <dbus/dbus.h>
23#include "dbus_connection_handle.h"
23#include <memory>24#include <memory>
2425
25namespace usc26namespace usc
26{27{
27class DBusConnectionThread;28class DBusEventLoop;
28class InputConfiguration;29class InputConfiguration;
2930
30class UnityInputService31class UnityInputService
31{32{
32public:33public:
33 UnityInputService(34 UnityInputService(
34 std::shared_ptr<usc::DBusConnectionThread> const& dbus_thread,35 std::shared_ptr<usc::DBusEventLoop> const& loop,
36 std::string const& address,
35 std::shared_ptr<usc::InputConfiguration> const& input_config);37 std::shared_ptr<usc::InputConfiguration> const& input_config);
3638
37private:39private:
@@ -44,7 +46,8 @@
44 void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(int32_t));46 void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(int32_t));
45 void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(double));47 void handle_message(DBusMessage* message, void (usc::InputConfiguration::* method)(double));
4648
47 std::shared_ptr<usc::DBusConnectionThread> const dbus;49 std::shared_ptr<usc::DBusEventLoop> const loop;
50 std::shared_ptr<usc::DBusConnectionHandle> connection;
48 std::shared_ptr<usc::InputConfiguration> const input_config;51 std::shared_ptr<usc::InputConfiguration> const input_config;
49};52};
5053
5154
=== modified file 'src/unity_screen_service.cpp'
--- src/unity_screen_service.cpp 2015-08-25 14:35:20 +0000
+++ src/unity_screen_service.cpp 2016-01-27 14:14:14 +0000
@@ -19,7 +19,7 @@
19#include "unity_screen_service.h"19#include "unity_screen_service.h"
20#include "screen.h"20#include "screen.h"
21#include "dbus_message_handle.h"21#include "dbus_message_handle.h"
22#include "dbus_connection_thread.h"22#include "dbus_event_loop.h"
23#include "dbus_connection_handle.h"23#include "dbus_connection_handle.h"
24#include "scoped_dbus_error.h"24#include "scoped_dbus_error.h"
2525
@@ -35,20 +35,22 @@
35}35}
3636
37usc::UnityScreenService::UnityScreenService(37usc::UnityScreenService::UnityScreenService(
38 std::shared_ptr<usc::DBusConnectionThread> const& dbus,38 std::shared_ptr<usc::DBusEventLoop> const& loop,
39 std::string const& address,
39 std::shared_ptr<usc::Screen> const& screen)40 std::shared_ptr<usc::Screen> const& screen)
40 : screen{screen},41 : screen{screen},
41 dbus{dbus},42 loop{loop},
43 connection{std::make_shared<DBusConnectionHandle>(address.c_str())},
42 request_id{0}44 request_id{0}
43{45{
44 auto const& connection = dbus->connection();46 loop->add_connection(connection);
45 connection.request_name(dbus_screen_service_name);47 connection->request_name(dbus_screen_service_name);
46 connection.add_match(48 connection->add_match(
47 "type='signal',"49 "type='signal',"
48 "sender='org.freedesktop.DBus',"50 "sender='org.freedesktop.DBus',"
49 "interface='org.freedesktop.DBus',"51 "interface='org.freedesktop.DBus',"
50 "member='NameOwnerChanged'");52 "member='NameOwnerChanged'");
51 connection.add_filter(handle_dbus_message_thunk, this);53 connection->add_filter(handle_dbus_message_thunk, this);
5254
53 screen->register_power_state_change_handler(55 screen->register_power_state_change_handler(
54 [this](MirPowerMode mode, PowerStateChangeReason reason)56 [this](MirPowerMode mode, PowerStateChangeReason reason)
@@ -332,7 +334,7 @@
332 int32_t const power_state = (power_mode == MirPowerMode::mir_power_mode_off) ? 0 : 1;334 int32_t const power_state = (power_mode == MirPowerMode::mir_power_mode_off) ? 0 : 1;
333 int32_t const reason_int = static_cast<int32_t>(reason);335 int32_t const reason_int = static_cast<int32_t>(reason);
334336
335 dbus->loop().enqueue(337 loop->enqueue(
336 [this, power_state, reason_int]338 [this, power_state, reason_int]
337 {339 {
338 DBusMessageHandle signal{340 DBusMessageHandle signal{
@@ -344,6 +346,6 @@
344 DBUS_TYPE_INT32, &reason_int,346 DBUS_TYPE_INT32, &reason_int,
345 DBUS_TYPE_INVALID};347 DBUS_TYPE_INVALID};
346348
347 dbus_connection_send(dbus->connection(), signal, nullptr);349 dbus_connection_send(*connection, signal, nullptr);
348 });350 });
349}351}
350352
=== modified file 'src/unity_screen_service.h'
--- src/unity_screen_service.h 2015-08-25 14:32:32 +0000
+++ src/unity_screen_service.h 2016-01-27 14:14:14 +0000
@@ -34,13 +34,14 @@
34namespace usc34namespace usc
35{35{
36class Screen;36class Screen;
37class DBusConnectionThread;37class DBusEventLoop;
3838
39class UnityScreenService39class UnityScreenService
40{40{
41public:41public:
42 UnityScreenService(42 UnityScreenService(
43 std::shared_ptr<usc::DBusConnectionThread> const& connection,43 std::shared_ptr<usc::DBusEventLoop> const& loop,
44 std::string const& address,
44 std::shared_ptr<usc::Screen> const& screen);45 std::shared_ptr<usc::Screen> const& screen);
4546
46private:47private:
@@ -64,7 +65,8 @@
64 MirPowerMode power_mode, PowerStateChangeReason reason);65 MirPowerMode power_mode, PowerStateChangeReason reason);
6566
66 std::shared_ptr<usc::Screen> const screen;67 std::shared_ptr<usc::Screen> const screen;
67 std::shared_ptr<DBusConnectionThread> const dbus;68 std::shared_ptr<DBusEventLoop> const loop;
69 std::shared_ptr<DBusConnectionHandle> connection;
6870
69 std::mutex keep_display_on_mutex;71 std::mutex keep_display_on_mutex;
70 std::unordered_multimap<std::string,int32_t> keep_display_on_ids;72 std::unordered_multimap<std::string,int32_t> keep_display_on_ids;
7173
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2015-03-17 18:17:14 +0000
+++ tests/CMakeLists.txt 2016-01-27 14:14:14 +0000
@@ -14,5 +14,6 @@
14#14#
15# Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>15# Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
1616
17include_directories(include)
17add_subdirectory(unit-tests/)18add_subdirectory(unit-tests/)
18add_subdirectory(integration-tests/)19add_subdirectory(integration-tests/)
1920
=== added directory 'tests/include'
=== added directory 'tests/include/usc'
=== added directory 'tests/include/usc/test'
=== added file 'tests/include/usc/test/mock_display.h'
--- tests/include/usc/test/mock_display.h 1970-01-01 00:00:00 +0000
+++ tests/include/usc/test/mock_display.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef USC_TEST_MOCK_DISPLAY_H
18#define USC_TEST_MOCK_DISPLAY_H
19
20#include "usc/test/stub_display_configuration.h"
21
22#include <mir/graphics/display.h>
23#include <gmock/gmock.h>
24
25namespace usc
26{
27namespace test
28{
29struct MockDisplay : mir::graphics::Display
30{
31 void for_each_display_sync_group(std::function<void(mir::graphics::DisplaySyncGroup&)> const& f) override
32 {
33 }
34
35 std::unique_ptr<mir::graphics::DisplayConfiguration> configuration() const override
36 { return std::make_unique<usc::test::StubDisplayConfiguration>(); }
37
38 MOCK_METHOD1(configure, void(mir::graphics::DisplayConfiguration const& conf));
39
40 void register_configuration_change_handler(
41 mir::graphics::EventHandlerRegister& ,
42 mir::graphics::DisplayConfigurationChangeHandler const& ) override {};
43
44 void register_pause_resume_handlers(
45 mir::graphics::EventHandlerRegister&,
46 mir::graphics::DisplayPauseHandler const&,
47 mir::graphics::DisplayResumeHandler const&) override
48 {
49 }
50
51 void pause() override {};
52
53 void resume() override {};
54
55 std::shared_ptr<mir::graphics::Cursor> create_hardware_cursor(
56 std::shared_ptr<mir::graphics::CursorImage> const&) override
57 {
58 return {};
59 };
60
61 std::unique_ptr<mir::graphics::GLContext> create_gl_context() override
62 { return std::unique_ptr<mir::graphics::GLContext>{};};
63};
64}
65}
66
67#endif
068
=== added file 'tests/include/usc/test/mock_input_configuration.h'
--- tests/include/usc/test/mock_input_configuration.h 1970-01-01 00:00:00 +0000
+++ tests/include/usc/test/mock_input_configuration.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#ifndef USC_TEST_MOCK_INPUT_CONFIGURATION_H_
20#define USC_TEST_MOCK_INPUT_CONFIGURATION_H_
21
22#include "src/input_configuration.h"
23
24#include <gtest/gtest.h>
25#include <gmock/gmock.h>
26
27namespace usc
28{
29namespace test
30{
31struct MockInputConfiguration : usc::InputConfiguration
32{
33public:
34 MOCK_METHOD1(set_mouse_primary_button, void(int32_t));
35 MOCK_METHOD1(set_mouse_cursor_speed, void(double));
36 MOCK_METHOD1(set_mouse_scroll_speed, void(double));
37 MOCK_METHOD1(set_touchpad_primary_button, void(int32_t));
38 MOCK_METHOD1(set_touchpad_cursor_speed, void(double));
39 MOCK_METHOD1(set_touchpad_scroll_speed, void(double));
40 MOCK_METHOD1(set_two_finger_scroll, void(bool));
41 MOCK_METHOD1(set_tap_to_click, void(bool));
42 MOCK_METHOD1(set_disable_touchpad_with_mouse, void(bool));
43 MOCK_METHOD1(set_disable_touchpad_while_typing, void(bool));
44};
45}
46}
47
48#endif
049
=== added file 'tests/include/usc/test/mock_screen.h'
--- tests/include/usc/test/mock_screen.h 1970-01-01 00:00:00 +0000
+++ tests/include/usc/test/mock_screen.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#ifndef USC_TEST_MOCK_SCREEN_H_
20#define USC_TEST_MOCK_SCREEN_H_
21
22#include "src/screen.h"
23
24#include <gtest/gtest.h>
25#include <gmock/gmock.h>
26namespace usc
27{
28namespace test
29{
30
31struct MockScreen : usc::Screen
32{
33 MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
34 MOCK_METHOD0(keep_display_on_temporarily, void());
35
36 MOCK_METHOD0(get_screen_power_mode, MirPowerMode());
37 MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
38 MOCK_METHOD1(keep_display_on, void(bool on));
39 MOCK_METHOD1(set_brightness, void(int brightness));
40 MOCK_METHOD1(enable_auto_brightness, void(bool enable));
41 MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout));
42
43 MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled));
44
45 void register_power_state_change_handler(
46 usc::PowerStateChangeHandler const& handler)
47 {
48 power_state_change_handler = handler;
49 }
50
51 usc::PowerStateChangeHandler power_state_change_handler;
52};
53
54}
55}
56
57#endif
058
=== added file 'tests/include/usc/test/stub_display_configuration.h'
--- tests/include/usc/test/stub_display_configuration.h 1970-01-01 00:00:00 +0000
+++ tests/include/usc/test/stub_display_configuration.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef USC_TEST_STUB_DISPLAY_CONFIGURATION_H_
18#define USC_TEST_STUB_DISPLAY_CONFIGURATION_H_
19
20#include <mir/graphics/display_configuration.h>
21
22namespace usc
23{
24namespace test
25{
26
27struct StubDisplayConfiguration : mir::graphics::DisplayConfiguration
28{
29 StubDisplayConfiguration()
30 {
31 conf_output.power_mode = MirPowerMode::mir_power_mode_on;
32 }
33
34 StubDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const& output)
35 : conf_output(output)
36 {
37 }
38
39 void for_each_card(std::function<void(mir::graphics::DisplayConfigurationCard const&)>) const override
40 {
41 }
42
43 void for_each_output(std::function<void(mir::graphics::DisplayConfigurationOutput const&)> f) const override
44 {
45 f(conf_output);
46 }
47
48 void for_each_output(std::function<void(mir::graphics::UserDisplayConfigurationOutput&)> f)
49 {
50 mir::graphics::UserDisplayConfigurationOutput user{conf_output};
51 f(user);
52 }
53
54 std::unique_ptr<mir::graphics::DisplayConfiguration> clone() const override
55 {
56 return std::make_unique<StubDisplayConfiguration>(conf_output);
57 }
58
59 mir::graphics::DisplayConfigurationOutput conf_output;
60};
61
62}
63}
64
65#endif
066
=== modified file 'tests/integration-tests/CMakeLists.txt'
--- tests/integration-tests/CMakeLists.txt 2015-09-22 16:17:40 +0000
+++ tests/integration-tests/CMakeLists.txt 2016-01-27 14:14:14 +0000
@@ -33,9 +33,12 @@
33 dbus_bus.cpp33 dbus_bus.cpp
34 dbus_client.cpp34 dbus_client.cpp
35 spin_wait.cpp35 spin_wait.cpp
36 unity_screen_dbus_client.cpp
37 unity_input_dbus_client.cpp
36 test_dbus_event_loop.cpp38 test_dbus_event_loop.cpp
37 test_unity_screen_service.cpp39 test_unity_screen_service.cpp
38 test_unity_input_service.cpp40 test_unity_input_service.cpp
41 test_unity_services.cpp
39 test_external_spinner.cpp42 test_external_spinner.cpp
40 test_powerd_mediator.cpp43 test_powerd_mediator.cpp
41 test_deadlock_lp1491566.cpp44 test_deadlock_lp1491566.cpp
4245
=== modified file 'tests/integration-tests/test_dbus_event_loop.cpp'
--- tests/integration-tests/test_dbus_event_loop.cpp 2015-05-27 09:42:40 +0000
+++ tests/integration-tests/test_dbus_event_loop.cpp 2016-01-27 14:14:14 +0000
@@ -79,8 +79,9 @@
79{79{
80 ADBusEventLoop()80 ADBusEventLoop()
81 {81 {
82 connection.request_name(test_service_name);82 dbus_event_loop.add_connection(connection);
83 connection.add_filter(handle_dbus_message_thunk, this);83 connection->request_name(test_service_name);
84 connection->add_filter(handle_dbus_message_thunk, this);
8485
85 std::promise<void> event_loop_started;86 std::promise<void> event_loop_started;
86 auto event_loop_started_future = event_loop_started.get_future();87 auto event_loop_started_future = event_loop_started.get_future();
@@ -102,8 +103,7 @@
102 }103 }
103104
104 static ::DBusHandlerResult handle_dbus_message_thunk(105 static ::DBusHandlerResult handle_dbus_message_thunk(
105 ::DBusConnection* connection, DBusMessage* message, void* user_data)106 ::DBusConnection* connection, DBusMessage* message, void* user_data) {
106 {
107 auto const a_dbus_event_loop = static_cast<ADBusEventLoop*>(user_data);107 auto const a_dbus_event_loop = static_cast<ADBusEventLoop*>(user_data);
108 return a_dbus_event_loop->handle_dbus_message(connection, message, user_data);108 return a_dbus_event_loop->handle_dbus_message(connection, message, user_data);
109 }109 }
@@ -142,8 +142,8 @@
142142
143 ut::DBusBus bus;143 ut::DBusBus bus;
144144
145 usc::DBusConnectionHandle connection{bus.address().c_str()};145 std::shared_ptr<usc::DBusConnectionHandle> connection{std::make_shared<usc::DBusConnectionHandle>(bus.address())};
146 usc::DBusEventLoop dbus_event_loop{connection};146 usc::DBusEventLoop dbus_event_loop{};
147 std::thread dbus_loop_thread;147 std::thread dbus_loop_thread;
148 TestDBusClient client{bus.address()};148 TestDBusClient client{bus.address()};
149};149};
@@ -173,7 +173,7 @@
173 test_service_interface,173 test_service_interface,
174 "signal")};174 "signal")};
175175
176 dbus_connection_send(connection, msg, nullptr);176 dbus_connection_send(*connection, msg, nullptr);
177 });177 });
178178
179 auto const reply = client.listen_for_signal();179 auto const reply = client.listen_for_signal();
@@ -214,7 +214,7 @@
214214
215 DBusPendingCall* pending{nullptr};215 DBusPendingCall* pending{nullptr};
216 dbus_connection_send_with_reply(216 dbus_connection_send_with_reply(
217 connection, msg, &pending, timeout_ms);217 *connection, msg, &pending, timeout_ms);
218 dbus_pending_call_set_notify(218 dbus_pending_call_set_notify(
219 pending, &pending_complete, &pending_promise, nullptr);219 pending, &pending_complete, &pending_promise, nullptr);
220 });220 });
221221
=== modified file 'tests/integration-tests/test_deadlock_lp1491566.cpp'
--- tests/integration-tests/test_deadlock_lp1491566.cpp 2015-09-29 13:05:56 +0000
+++ tests/integration-tests/test_deadlock_lp1491566.cpp 2016-01-27 14:14:14 +0000
@@ -21,11 +21,11 @@
21#include "src/screen_hardware.h"21#include "src/screen_hardware.h"
22#include "src/power_state_change_reason.h"22#include "src/power_state_change_reason.h"
23#include "spin_wait.h"23#include "spin_wait.h"
24#include "usc/test/stub_display_configuration.h"
25#include "usc/test/mock_display.h"
2426
25#include <mir/compositor/compositor.h>27#include <mir/compositor/compositor.h>
26#include <mir/main_loop.h>28#include <mir/main_loop.h>
27#include <mir/graphics/display.h>
28#include <mir/graphics/display_configuration.h>
29#include <mir/graphics/gl_context.h>29#include <mir/graphics/gl_context.h>
30#include <mir/input/touch_visualizer.h>30#include <mir/input/touch_visualizer.h>
3131
@@ -36,6 +36,7 @@
36#include <future>36#include <future>
3737
38namespace mg = mir::graphics;38namespace mg = mir::graphics;
39namespace ut = usc::test;
3940
40namespace41namespace
41{42{
@@ -46,71 +47,6 @@
46 void stop() override {}47 void stop() override {}
47};48};
4849
49struct StubDisplayConfiguration : mg::DisplayConfiguration
50{
51 StubDisplayConfiguration()
52 {
53 conf_output.power_mode = MirPowerMode::mir_power_mode_on;
54 }
55
56 void for_each_card(std::function<void(mg::DisplayConfigurationCard const&)> f) const override
57 {
58 }
59
60 void for_each_output(std::function<void(mg::DisplayConfigurationOutput const&)> f) const override
61 {
62 f(conf_output);
63 }
64
65 void for_each_output(std::function<void(mg::UserDisplayConfigurationOutput&)> f)
66 {
67 mg::UserDisplayConfigurationOutput user{conf_output};
68 f(user);
69 }
70
71 mg::DisplayConfigurationOutput conf_output;
72};
73
74struct StubDisplay : mg::Display
75{
76 void for_each_display_sync_group(std::function<void(mg::DisplaySyncGroup&)> const& f) override
77 {
78 }
79
80 std::unique_ptr<mg::DisplayConfiguration> configuration() const override
81 {
82 return std::unique_ptr<mg::DisplayConfiguration>{new StubDisplayConfiguration{}};
83 }
84
85 void configure(mg::DisplayConfiguration const&) override {}
86
87 void register_configuration_change_handler(
88 mg::EventHandlerRegister& ,
89 mg::DisplayConfigurationChangeHandler const& ) override
90 {
91 }
92
93 void register_pause_resume_handlers(
94 mg::EventHandlerRegister&,
95 mg::DisplayPauseHandler const&,
96 mg::DisplayResumeHandler const&) override
97 {
98 }
99
100 void pause() override {}
101 void resume() override {}
102
103 std::shared_ptr<mg::Cursor> create_hardware_cursor(
104 std::shared_ptr<mg::CursorImage> const&) override
105 {
106 return{};
107 }
108
109 std::unique_ptr<mg::GLContext> create_gl_context() override
110 {
111 return std::unique_ptr<mg::GLContext>{};
112 }
113};
11450
115struct StubScreenHardware : usc::ScreenHardware51struct StubScreenHardware : usc::ScreenHardware
116{52{
@@ -219,7 +155,7 @@
219 TestMirScreen mir_screen{155 TestMirScreen mir_screen{
220 std::make_shared<StubScreenHardware>(),156 std::make_shared<StubScreenHardware>(),
221 std::make_shared<NullCompositor>(),157 std::make_shared<NullCompositor>(),
222 std::make_shared<StubDisplay>(),158 std::make_shared<::testing::NiceMock<ut::MockDisplay>>(),
223 std::make_shared<NullTouchVisualizer>(),159 std::make_shared<NullTouchVisualizer>(),
224 main_loop,160 main_loop,
225 server.the_clock(),161 server.the_clock(),
226162
=== modified file 'tests/integration-tests/test_powerd_mediator.cpp'
--- tests/integration-tests/test_powerd_mediator.cpp 2015-07-17 12:43:46 +0000
+++ tests/integration-tests/test_powerd_mediator.cpp 2016-01-27 14:14:14 +0000
@@ -41,9 +41,10 @@
41 dbus_bool_t auto_brightness_supported,41 dbus_bool_t auto_brightness_supported,
42 StartNow start_now)42 StartNow start_now)
43 : auto_brightness_supported{auto_brightness_supported},43 : auto_brightness_supported{auto_brightness_supported},
44 connection{address.c_str()},44 connection{std::make_shared<usc::DBusConnectionHandle>(address)},
45 dbus_event_loop{connection}45 dbus_event_loop{}
46 {46 {
47 dbus_event_loop.add_connection(connection);
47 if (start_now == StartNow::yes)48 if (start_now == StartNow::yes)
48 start();49 start();
49 }50 }
@@ -60,8 +61,8 @@
60 ON_CALL(*this, dbus_setUserBrightness(normal_brightness))61 ON_CALL(*this, dbus_setUserBrightness(normal_brightness))
61 .WillByDefault(WakeUp(&initial_setup_done));62 .WillByDefault(WakeUp(&initial_setup_done));
6263
63 connection.request_name(powerd_service_name);64 connection->request_name(powerd_service_name);
64 connection.add_filter(handle_dbus_message_thunk, this);65 connection->add_filter(handle_dbus_message_thunk, this);
6566
66 std::promise<void> event_loop_started;67 std::promise<void> event_loop_started;
67 auto event_loop_started_future = event_loop_started.get_future();68 auto event_loop_started_future = event_loop_started.get_future();
@@ -104,7 +105,7 @@
104 DBUS_TYPE_INT32, &state,105 DBUS_TYPE_INT32, &state,
105 DBUS_TYPE_INVALID};106 DBUS_TYPE_INVALID};
106107
107 dbus_connection_send(connection, signal, nullptr);108 dbus_connection_send(*connection, signal, nullptr);
108 }109 }
109110
110private:111private:
@@ -230,7 +231,7 @@
230231
231 ut::WaitCondition initial_setup_done;232 ut::WaitCondition initial_setup_done;
232233
233 usc::DBusConnectionHandle connection;234 std::shared_ptr<usc::DBusConnectionHandle> connection;
234 usc::DBusEventLoop dbus_event_loop;235 usc::DBusEventLoop dbus_event_loop;
235 std::thread dbus_loop_thread;236 std::thread dbus_loop_thread;
236};237};
237238
=== modified file 'tests/integration-tests/test_unity_input_service.cpp'
--- tests/integration-tests/test_unity_input_service.cpp 2015-08-28 15:57:25 +0000
+++ tests/integration-tests/test_unity_input_service.cpp 2016-01-27 14:14:14 +0000
@@ -19,15 +19,16 @@
19#include "src/unity_input_service.h"19#include "src/unity_input_service.h"
20#include "src/dbus_connection_handle.h"20#include "src/dbus_connection_handle.h"
21#include "src/dbus_connection_thread.h"21#include "src/dbus_connection_thread.h"
22#include "src/dbus_event_loop.h"
22#include "src/dbus_message_handle.h"23#include "src/dbus_message_handle.h"
23#include "src/input_configuration.h"
24#include "src/unity_input_service_introspection.h"24#include "src/unity_input_service_introspection.h"
25
25#include "wait_condition.h"26#include "wait_condition.h"
26#include "dbus_bus.h"27#include "dbus_bus.h"
27#include "dbus_client.h"28#include "dbus_client.h"
29#include "unity_input_dbus_client.h"
2830
29#include <gtest/gtest.h>31#include "usc/test/mock_input_configuration.h"
30#include <gmock/gmock.h>
3132
32#include <stdexcept>33#include <stdexcept>
33#include <memory>34#include <memory>
@@ -37,128 +38,19 @@
37namespace38namespace
38{39{
3940
40struct MockInputConfiguration : usc::InputConfiguration
41{
42public:
43 MOCK_METHOD1(set_mouse_primary_button, void(int32_t));
44 MOCK_METHOD1(set_mouse_cursor_speed, void(double));
45 MOCK_METHOD1(set_mouse_scroll_speed, void(double));
46 MOCK_METHOD1(set_touchpad_primary_button, void(int32_t));
47 MOCK_METHOD1(set_touchpad_cursor_speed, void(double));
48 MOCK_METHOD1(set_touchpad_scroll_speed, void(double));
49 MOCK_METHOD1(set_two_finger_scroll, void(bool));
50 MOCK_METHOD1(set_tap_to_click, void(bool));
51 MOCK_METHOD1(set_disable_touchpad_with_mouse, void(bool));
52 MOCK_METHOD1(set_disable_touchpad_while_typing, void(bool));
53};
54
55class UnityInputDBusClient : public ut::DBusClient
56{
57public:
58 UnityInputDBusClient(std::string const& address)
59 : ut::DBusClient{
60 address,
61 "com.canonical.Unity.Input",
62 "/com/canonical/Unity/Input"}
63 {
64 }
65
66 ut::DBusAsyncReplyString request_introspection()
67 {
68 return invoke_with_reply<ut::DBusAsyncReplyString>(
69 "org.freedesktop.DBus.Introspectable", "Introspect",
70 DBUS_TYPE_INVALID);
71 }
72
73 ut::DBusAsyncReplyVoid request(char const* requestName, int32_t value)
74 {
75 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
76 unity_input_interface, requestName,
77 DBUS_TYPE_INT32, &value,
78 DBUS_TYPE_INVALID);
79 }
80
81 ut::DBusAsyncReplyVoid request_set_mouse_primary_button(int32_t button)
82 {
83 return request("setMousePrimaryButton", button);
84 }
85
86 ut::DBusAsyncReplyVoid request_set_touchpad_primary_button(int32_t button)
87 {
88 return request("setTouchpadPrimaryButton", button);
89 }
90
91 ut::DBusAsyncReplyVoid request(char const* requestName, double value)
92 {
93 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
94 unity_input_interface, requestName,
95 DBUS_TYPE_DOUBLE, &value,
96 DBUS_TYPE_INVALID);
97 }
98
99 ut::DBusAsyncReplyVoid request_set_mouse_cursor_speed(double speed)
100 {
101 return request("setMouseCursorSpeed", speed);
102 }
103
104 ut::DBusAsyncReplyVoid request_set_mouse_scroll_speed(double speed)
105 {
106 return request("setMouseScrollSpeed", speed);
107 }
108
109 ut::DBusAsyncReplyVoid request_set_touchpad_cursor_speed(double speed)
110 {
111 return request("setTouchpadCursorSpeed", speed);
112 }
113
114 ut::DBusAsyncReplyVoid request_set_touchpad_scroll_speed(double speed)
115 {
116 return request("setTouchpadScrollSpeed", speed);
117 }
118
119 ut::DBusAsyncReplyVoid request(char const* requestName, bool value)
120 {
121 dbus_bool_t copied = value;
122 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
123 unity_input_interface, requestName,
124 DBUS_TYPE_BOOLEAN, &copied,
125 DBUS_TYPE_INVALID);
126 }
127
128 ut::DBusAsyncReplyVoid request_set_touchpad_two_finger_scroll(bool enabled)
129 {
130 return request("setTouchpadTwoFingerScroll", enabled);
131 }
132
133 ut::DBusAsyncReplyVoid request_set_touchpad_tap_to_click(bool enabled)
134 {
135 return request("setTouchpadTapToClick", enabled);
136 }
137
138 ut::DBusAsyncReplyVoid request_set_touchpad_disable_with_mouse(bool enabled)
139 {
140 return request("setTouchpadDisableWithMouse", enabled);
141 }
142
143 ut::DBusAsyncReplyVoid request_set_touchpad_disable_while_typing(bool enabled)
144 {
145 return request("setTouchpadDisableWhileTyping", enabled);
146 }
147
148 char const* const unity_input_interface = "com.canonical.Unity.Input";
149};
150
151struct AUnityInputService : testing::Test41struct AUnityInputService : testing::Test
152{42{
153 std::chrono::seconds const default_timeout{3};43 std::chrono::seconds const default_timeout{3};
154 ut::DBusBus bus;44 ut::DBusBus bus;
15545
156 std::shared_ptr<MockInputConfiguration> const mock_input_configuration =46 std::shared_ptr<ut::MockInputConfiguration> const mock_input_configuration =
157 std::make_shared<testing::NiceMock<MockInputConfiguration>>();47 std::make_shared<testing::NiceMock<ut::MockInputConfiguration>>();
158 UnityInputDBusClient client{bus.address()};48 ut::UnityInputDBusClient client{bus.address()};
49 std::shared_ptr<usc::DBusEventLoop> const dbus_loop=
50 std::make_shared<usc::DBusEventLoop>();
51 usc::UnityInputService service{dbus_loop, bus.address(), mock_input_configuration};
159 std::shared_ptr<usc::DBusConnectionThread> const dbus_thread =52 std::shared_ptr<usc::DBusConnectionThread> const dbus_thread =
160 std::make_shared<usc::DBusConnectionThread>(bus.address());53 std::make_shared<usc::DBusConnectionThread>(dbus_loop);
161 usc::UnityInputService service{dbus_thread, mock_input_configuration};
162};54};
16355
164}56}
16557
=== modified file 'tests/integration-tests/test_unity_screen_service.cpp'
--- tests/integration-tests/test_unity_screen_service.cpp 2015-08-25 14:27:23 +0000
+++ tests/integration-tests/test_unity_screen_service.cpp 2016-01-27 14:14:14 +0000
@@ -19,14 +19,16 @@
19#include "src/unity_screen_service.h"19#include "src/unity_screen_service.h"
20#include "src/dbus_connection_handle.h"20#include "src/dbus_connection_handle.h"
21#include "src/dbus_connection_thread.h"21#include "src/dbus_connection_thread.h"
22#include "src/dbus_event_loop.h"
22#include "src/dbus_message_handle.h"23#include "src/dbus_message_handle.h"
23#include "src/screen.h"24#include "src/screen.h"
24#include "src/power_state_change_reason.h"25#include "src/power_state_change_reason.h"
25#include "src/unity_screen_service_introspection.h"26#include "src/unity_screen_service_introspection.h"
26#include "wait_condition.h"27#include "wait_condition.h"
27#include "dbus_bus.h"28#include "dbus_bus.h"
28#include "dbus_client.h"29#include "unity_screen_dbus_client.h"
2930
31#include "usc/test/mock_screen.h"
30#include <gtest/gtest.h>32#include <gtest/gtest.h>
31#include <gmock/gmock.h>33#include <gmock/gmock.h>
3234
@@ -38,157 +40,20 @@
38namespace40namespace
39{41{
4042
41struct MockScreen : usc::Screen
42{
43 MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
44 MOCK_METHOD0(keep_display_on_temporarily, void());
45
46 MOCK_METHOD0(get_screen_power_mode, MirPowerMode());
47 MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
48 MOCK_METHOD1(keep_display_on, void(bool on));
49 MOCK_METHOD1(set_brightness, void(int brightness));
50 MOCK_METHOD1(enable_auto_brightness, void(bool enable));
51 MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout));
52
53 MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled));
54
55 void register_power_state_change_handler(
56 usc::PowerStateChangeHandler const& handler)
57 {
58 power_state_change_handler = handler;
59 }
60
61 usc::PowerStateChangeHandler power_state_change_handler;
62};
63
64class UnityScreenDBusClient : public ut::DBusClient
65{
66public:
67 UnityScreenDBusClient(std::string const& address)
68 : ut::DBusClient{
69 address,
70 "com.canonical.Unity.Screen",
71 "/com/canonical/Unity/Screen"}
72 {
73 connection.add_match(
74 "type='signal',"
75 "interface='com.canonical.Unity.Screen',"
76 "member='DisplayPowerStateChange'");
77 }
78
79 ut::DBusAsyncReplyString request_introspection()
80 {
81 return invoke_with_reply<ut::DBusAsyncReplyString>(
82 "org.freedesktop.DBus.Introspectable", "Introspect",
83 DBUS_TYPE_INVALID);
84 }
85
86 ut::DBusAsyncReplyVoid request_set_user_brightness(int32_t brightness)
87 {
88 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
89 unity_screen_interface, "setUserBrightness",
90 DBUS_TYPE_INT32, &brightness,
91 DBUS_TYPE_INVALID);
92 }
93
94 ut::DBusAsyncReplyVoid request_user_auto_brightness_enable(bool enabled)
95 {
96 dbus_bool_t const e = enabled ? TRUE : FALSE;
97 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
98 unity_screen_interface, "userAutobrightnessEnable",
99 DBUS_TYPE_BOOLEAN, &e,
100 DBUS_TYPE_INVALID);
101 }
102
103 ut::DBusAsyncReplyVoid request_set_inactivity_timeouts(
104 int32_t poweroff_timeout, int32_t dimmer_timeout)
105 {
106 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
107 unity_screen_interface, "setInactivityTimeouts",
108 DBUS_TYPE_INT32, &poweroff_timeout,
109 DBUS_TYPE_INT32, &dimmer_timeout,
110 DBUS_TYPE_INVALID);
111 }
112
113 ut::DBusAsyncReplyVoid request_set_touch_visualization_enabled(bool enabled)
114 {
115 dbus_bool_t const e = enabled ? TRUE : FALSE;
116 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
117 unity_screen_interface, "setTouchVisualizationEnabled",
118 DBUS_TYPE_BOOLEAN, &e,
119 DBUS_TYPE_INVALID);
120 }
121
122 ut::DBusAsyncReplyBool request_set_screen_power_mode(
123 std::string const& mode, int reason)
124 {
125 auto mode_cstr = mode.c_str();
126 return invoke_with_reply<ut::DBusAsyncReplyBool>(
127 unity_screen_interface, "setScreenPowerMode",
128 DBUS_TYPE_STRING, &mode_cstr,
129 DBUS_TYPE_INT32, &reason,
130 DBUS_TYPE_INVALID);
131 }
132
133 ut::DBusAsyncReplyInt request_keep_display_on()
134 {
135 return invoke_with_reply<ut::DBusAsyncReplyInt>(
136 unity_screen_interface, "keepDisplayOn",
137 DBUS_TYPE_INVALID);
138 }
139
140 ut::DBusAsyncReplyVoid request_remove_display_on_request(int id)
141 {
142 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
143 unity_screen_interface, "removeDisplayOnRequest",
144 DBUS_TYPE_INT32, &id,
145 DBUS_TYPE_INVALID);
146 }
147
148 ut::DBusAsyncReply request_invalid_method()
149 {
150 return invoke_with_reply<ut::DBusAsyncReply>(
151 unity_screen_interface, "invalidMethod",
152 DBUS_TYPE_INVALID);
153 }
154
155 ut::DBusAsyncReply request_method_with_invalid_arguments()
156 {
157 char const* const str = "abcd";
158 return invoke_with_reply<ut::DBusAsyncReply>(
159 unity_screen_interface, "setUserBrightness",
160 DBUS_TYPE_STRING, &str,
161 DBUS_TYPE_INVALID);
162 }
163
164 usc::DBusMessageHandle listen_for_power_state_change_signal()
165 {
166 while (true)
167 {
168 dbus_connection_read_write(connection, 1);
169 auto msg = usc::DBusMessageHandle{dbus_connection_pop_message(connection)};
170
171 if (msg && dbus_message_is_signal(msg, "com.canonical.Unity.Screen", "DisplayPowerStateChange"))
172 {
173 return msg;
174 }
175 }
176 }
177
178 char const* const unity_screen_interface = "com.canonical.Unity.Screen";
179};
180
181struct AUnityScreenService : testing::Test43struct AUnityScreenService : testing::Test
182{44{
183 std::chrono::seconds const default_timeout{3};45 std::chrono::seconds const default_timeout{3};
184 ut::DBusBus bus;46 ut::DBusBus bus;
18547
186 std::shared_ptr<MockScreen> const mock_screen =48 std::shared_ptr<ut::MockScreen> const mock_screen =
187 std::make_shared<testing::NiceMock<MockScreen>>();49 std::make_shared<testing::NiceMock<ut::MockScreen>>();
188 UnityScreenDBusClient client{bus.address()};50 ut::UnityScreenDBusClient client{bus.address()};
51 std::shared_ptr<usc::DBusEventLoop> const dbus_loop=
52 std::make_shared<usc::DBusEventLoop>();
53 usc::UnityScreenService service{dbus_loop, bus.address(), mock_screen};
189 std::shared_ptr<usc::DBusConnectionThread> const dbus_thread =54 std::shared_ptr<usc::DBusConnectionThread> const dbus_thread =
190 std::make_shared<usc::DBusConnectionThread>(bus.address());55 std::make_shared<usc::DBusConnectionThread>(dbus_loop);
191 usc::UnityScreenService service{dbus_thread, mock_screen};56
192};57};
19358
194}59}
@@ -340,7 +205,7 @@
340{205{
341 using namespace testing;206 using namespace testing;
342207
343 UnityScreenDBusClient other_client{bus.address()};208 ut::UnityScreenDBusClient other_client{bus.address()};
344209
345 EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(4);210 EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(4);
346 EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);211 EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);
347212
=== added file 'tests/integration-tests/test_unity_services.cpp'
--- tests/integration-tests/test_unity_services.cpp 1970-01-01 00:00:00 +0000
+++ tests/integration-tests/test_unity_services.cpp 2016-01-27 14:14:14 +0000
@@ -0,0 +1,82 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18#include "src/unity_input_service.h"
19#include "src/dbus_connection_handle.h"
20#include "src/dbus_connection_thread.h"
21#include "src/dbus_event_loop.h"
22#include "src/dbus_message_handle.h"
23#include "src/unity_screen_service.h"
24#include "src/unity_input_service_introspection.h"
25#include "src/unity_screen_service_introspection.h"
26
27#include "wait_condition.h"
28#include "dbus_bus.h"
29#include "dbus_client.h"
30#include "unity_input_dbus_client.h"
31#include "unity_screen_dbus_client.h"
32
33#include "usc/test/mock_input_configuration.h"
34#include "usc/test/mock_screen.h"
35
36namespace ut = usc::test;
37using namespace testing;
38
39namespace
40{
41
42struct UnityServices : testing::Test
43{
44 std::chrono::seconds const default_timeout{3};
45 ut::DBusBus bus;
46
47 ut::UnityScreenDBusClient screen_client{bus.address()};
48 ut::UnityInputDBusClient input_client{bus.address()};
49 std::shared_ptr<ut::MockScreen> const mock_screen =
50 std::make_shared<testing::NiceMock<ut::MockScreen>>();
51 std::shared_ptr<ut::MockInputConfiguration> const mock_input_configuration =
52 std::make_shared<testing::NiceMock<ut::MockInputConfiguration>>();
53 std::shared_ptr<usc::DBusEventLoop> const dbus_loop=
54 std::make_shared<usc::DBusEventLoop>();
55 usc::UnityScreenService screen_service{dbus_loop, bus.address(), mock_screen};
56 usc::UnityInputService input_service{dbus_loop, bus.address(), mock_input_configuration};
57 std::shared_ptr<usc::DBusConnectionThread> const dbus_thread =
58 std::make_shared<usc::DBusConnectionThread>(dbus_loop);
59};
60
61}
62
63TEST_F(UnityServices, offer_screen_introspection)
64{
65 auto reply = screen_client.request_introspection();
66 EXPECT_THAT(reply.get(), Eq(unity_screen_service_introspection));
67}
68
69TEST_F(UnityServices, offer_input_introspection)
70{
71 auto reply = input_client.request_introspection();
72 EXPECT_THAT(reply.get(), Eq(unity_input_service_introspection));
73}
74
75TEST_F(UnityServices, provides_access_to_input_methods)
76{
77 double const speed = 8.0;
78
79 EXPECT_CALL(*mock_input_configuration, set_mouse_scroll_speed(speed));
80
81 input_client.request_set_mouse_scroll_speed(speed);
82}
083
=== added file 'tests/integration-tests/unity_input_dbus_client.cpp'
--- tests/integration-tests/unity_input_dbus_client.cpp 1970-01-01 00:00:00 +0000
+++ tests/integration-tests/unity_input_dbus_client.cpp 2016-01-27 14:14:14 +0000
@@ -0,0 +1,113 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#include "unity_input_dbus_client.h"
20
21namespace ut = usc::test;
22
23ut::UnityInputDBusClient::UnityInputDBusClient(std::string const& address)
24 : ut::DBusClient{
25 address,
26 "com.canonical.Unity.Input",
27 "/com/canonical/Unity/Input"}
28{
29}
30
31ut::DBusAsyncReplyString ut::UnityInputDBusClient::request_introspection()
32{
33 return invoke_with_reply<ut::DBusAsyncReplyString>(
34 "org.freedesktop.DBus.Introspectable", "Introspect",
35 DBUS_TYPE_INVALID);
36}
37
38ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, int32_t value)
39{
40 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
41 unity_input_interface, requestName,
42 DBUS_TYPE_INT32, &value,
43 DBUS_TYPE_INVALID);
44}
45
46ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_primary_button(int32_t button)
47{
48 return request("setMousePrimaryButton", button);
49}
50
51ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_primary_button(int32_t button)
52{
53 return request("setTouchpadPrimaryButton", button);
54}
55
56ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, double value)
57{
58 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
59 unity_input_interface, requestName,
60 DBUS_TYPE_DOUBLE, &value,
61 DBUS_TYPE_INVALID);
62}
63
64ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_cursor_speed(double speed)
65{
66 return request("setMouseCursorSpeed", speed);
67}
68
69ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_scroll_speed(double speed)
70{
71 return request("setMouseScrollSpeed", speed);
72}
73
74ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_cursor_speed(double speed)
75{
76 return request("setTouchpadCursorSpeed", speed);
77}
78
79ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_scroll_speed(double speed)
80{
81 return request("setTouchpadScrollSpeed", speed);
82}
83
84ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, bool value)
85{
86 dbus_bool_t copied = value;
87 return invoke_with_reply<ut::DBusAsyncReplyVoid>(
88 unity_input_interface, requestName,
89 DBUS_TYPE_BOOLEAN, &copied,
90 DBUS_TYPE_INVALID);
91}
92
93ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_two_finger_scroll(bool enabled)
94{
95 return request("setTouchpadTwoFingerScroll", enabled);
96}
97
98ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_tap_to_click(bool enabled)
99{
100 return request("setTouchpadTapToClick", enabled);
101}
102
103ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_with_mouse(bool enabled)
104{
105 return request("setTouchpadDisableWithMouse", enabled);
106}
107
108ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_while_typing(bool enabled)
109{
110 return request("setTouchpadDisableWhileTyping", enabled);
111}
112
113
0114
=== added file 'tests/integration-tests/unity_input_dbus_client.h'
--- tests/integration-tests/unity_input_dbus_client.h 1970-01-01 00:00:00 +0000
+++ tests/integration-tests/unity_input_dbus_client.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,52 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#ifndef USC_TEST_UNITY_INPUT_DBUS_CLIENT_H_
20#define USC_TEST_UNITY_INPUT_DBUS_CLIENT_H_
21
22#include "dbus_client.h"
23
24namespace usc
25{
26namespace test
27{
28class UnityInputDBusClient : public DBusClient
29{
30public:
31 UnityInputDBusClient(std::string const& address);
32 DBusAsyncReplyString request_introspection();
33 DBusAsyncReplyVoid request(char const* requestName, int32_t value);
34 DBusAsyncReplyVoid request_set_mouse_primary_button(int32_t button);
35 DBusAsyncReplyVoid request_set_touchpad_primary_button(int32_t button);
36 DBusAsyncReplyVoid request(char const* requestName, double value);
37 DBusAsyncReplyVoid request_set_mouse_cursor_speed(double speed);
38 DBusAsyncReplyVoid request_set_mouse_scroll_speed(double speed);
39 DBusAsyncReplyVoid request_set_touchpad_cursor_speed(double speed);
40 DBusAsyncReplyVoid request_set_touchpad_scroll_speed(double speed);
41 DBusAsyncReplyVoid request(char const* requestName, bool value);
42 DBusAsyncReplyVoid request_set_touchpad_two_finger_scroll(bool enabled);
43 DBusAsyncReplyVoid request_set_touchpad_tap_to_click(bool enabled);
44 DBusAsyncReplyVoid request_set_touchpad_disable_with_mouse(bool enabled);
45 DBusAsyncReplyVoid request_set_touchpad_disable_while_typing(bool enabled);
46 char const* const unity_input_interface = "com.canonical.Unity.Input";
47};
48
49}
50}
51
52#endif
053
=== added file 'tests/integration-tests/unity_screen_dbus_client.cpp'
--- tests/integration-tests/unity_screen_dbus_client.cpp 1970-01-01 00:00:00 +0000
+++ tests/integration-tests/unity_screen_dbus_client.cpp 2016-01-27 14:14:14 +0000
@@ -0,0 +1,112 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#include "unity_screen_dbus_client.h"
20#include "src/dbus_message_handle.h"
21
22namespace ut = usc::test;
23
24ut::UnityScreenDBusClient::UnityScreenDBusClient(std::string const& address)
25 : ut::DBusClient{
26 address,
27 "com.canonical.Unity.Screen",
28 "/com/canonical/Unity/Screen"}
29{
30 connection.add_match(
31 "type='signal',"
32 "interface='com.canonical.Unity.Screen',"
33 "member='DisplayPowerStateChange'");
34}
35
36ut::DBusAsyncReplyString ut::UnityScreenDBusClient::request_introspection()
37{
38 return invoke_with_reply<ut::DBusAsyncReplyString>("org.freedesktop.DBus.Introspectable", "Introspect",
39 DBUS_TYPE_INVALID);
40}
41
42ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_user_brightness(int32_t brightness)
43{
44 return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setUserBrightness", DBUS_TYPE_INT32,
45 &brightness, DBUS_TYPE_INVALID);
46}
47
48ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_user_auto_brightness_enable(bool enabled)
49{
50 dbus_bool_t const e = enabled ? TRUE : FALSE;
51 return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "userAutobrightnessEnable",
52 DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID);
53}
54
55ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_inactivity_timeouts(int32_t poweroff_timeout,
56 int32_t dimmer_timeout)
57{
58 return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setInactivityTimeouts", DBUS_TYPE_INT32,
59 &poweroff_timeout, DBUS_TYPE_INT32, &dimmer_timeout,
60 DBUS_TYPE_INVALID);
61}
62
63ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_touch_visualization_enabled(bool enabled)
64{
65 dbus_bool_t const e = enabled ? TRUE : FALSE;
66 return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "setTouchVisualizationEnabled",
67 DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID);
68}
69
70ut::DBusAsyncReplyBool ut::UnityScreenDBusClient::request_set_screen_power_mode(std::string const& mode, int reason)
71{
72 auto mode_cstr = mode.c_str();
73 return invoke_with_reply<ut::DBusAsyncReplyBool>(unity_screen_interface, "setScreenPowerMode", DBUS_TYPE_STRING,
74 &mode_cstr, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INVALID);
75}
76
77ut::DBusAsyncReplyInt ut::UnityScreenDBusClient::request_keep_display_on()
78{
79 return invoke_with_reply<ut::DBusAsyncReplyInt>(unity_screen_interface, "keepDisplayOn", DBUS_TYPE_INVALID);
80}
81
82ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_remove_display_on_request(int id)
83{
84 return invoke_with_reply<ut::DBusAsyncReplyVoid>(unity_screen_interface, "removeDisplayOnRequest", DBUS_TYPE_INT32,
85 &id, DBUS_TYPE_INVALID);
86}
87
88ut::DBusAsyncReply ut::UnityScreenDBusClient::request_invalid_method()
89{
90 return invoke_with_reply<ut::DBusAsyncReply>(unity_screen_interface, "invalidMethod", DBUS_TYPE_INVALID);
91}
92
93ut::DBusAsyncReply ut::UnityScreenDBusClient::request_method_with_invalid_arguments()
94{
95 char const* const str = "abcd";
96 return invoke_with_reply<ut::DBusAsyncReply>(unity_screen_interface, "setUserBrightness", DBUS_TYPE_STRING, &str,
97 DBUS_TYPE_INVALID);
98}
99
100usc::DBusMessageHandle ut::UnityScreenDBusClient::listen_for_power_state_change_signal()
101{
102 while (true)
103 {
104 dbus_connection_read_write(connection, 1);
105 auto msg = usc::DBusMessageHandle{dbus_connection_pop_message(connection)};
106
107 if (msg && dbus_message_is_signal(msg, "com.canonical.Unity.Screen", "DisplayPowerStateChange"))
108 {
109 return msg;
110 }
111 }
112}
0113
=== added file 'tests/integration-tests/unity_screen_dbus_client.h'
--- tests/integration-tests/unity_screen_dbus_client.h 1970-01-01 00:00:00 +0000
+++ tests/integration-tests/unity_screen_dbus_client.h 2016-01-27 14:14:14 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#ifndef USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_
20#define USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_
21
22#include "dbus_client.h"
23
24namespace usc
25{
26namespace test
27{
28
29class UnityScreenDBusClient : public DBusClient
30{
31public:
32 UnityScreenDBusClient(std::string const& address);
33
34 DBusAsyncReplyString request_introspection();
35 DBusAsyncReplyVoid request_set_user_brightness(int32_t brightness);
36 DBusAsyncReplyVoid request_user_auto_brightness_enable(bool enabled);
37 DBusAsyncReplyVoid request_set_inactivity_timeouts(
38 int32_t poweroff_timeout, int32_t dimmer_timeout);
39 DBusAsyncReplyVoid request_set_touch_visualization_enabled(bool enabled);
40 DBusAsyncReplyBool request_set_screen_power_mode(
41 std::string const& mode, int reason);
42
43 DBusAsyncReplyInt request_keep_display_on();
44 DBusAsyncReplyVoid request_remove_display_on_request(int id);
45 DBusAsyncReply request_invalid_method();
46 DBusAsyncReply request_method_with_invalid_arguments();
47 usc::DBusMessageHandle listen_for_power_state_change_signal();
48 char const* const unity_screen_interface = "com.canonical.Unity.Screen";
49};
50
51}
52}
53
54#endif
055
=== modified file 'tests/unit-tests/CMakeLists.txt'
--- tests/unit-tests/CMakeLists.txt 2015-02-18 14:40:29 +0000
+++ tests/unit-tests/CMakeLists.txt 2016-01-27 14:14:14 +0000
@@ -25,6 +25,7 @@
25 test_session_switcher.cpp25 test_session_switcher.cpp
26 test_screen_event_handler.cpp26 test_screen_event_handler.cpp
27 test_mir_screen.cpp27 test_mir_screen.cpp
28 test_mir_input_configuration.cpp
2829
29 advanceable_timer.cpp30 advanceable_timer.cpp
30)31)
3132
=== added file 'tests/unit-tests/test_mir_input_configuration.cpp'
--- tests/unit-tests/test_mir_input_configuration.cpp 1970-01-01 00:00:00 +0000
+++ tests/unit-tests/test_mir_input_configuration.cpp 2016-01-27 14:14:14 +0000
@@ -0,0 +1,114 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19
20#include "src/mir_input_configuration.h"
21#include "mir/input/input_device_hub.h"
22#include "mir/input/device_capability.h"
23#include "mir/input/input_device_observer.h"
24#include "mir/input/device.h"
25
26#include <gtest/gtest.h>
27#include <gmock/gmock.h>
28
29namespace mi = mir::input;
30
31using namespace ::testing;
32
33namespace
34{
35struct MockDevice : mi::Device
36{
37 MOCK_CONST_METHOD0(id, MirInputDeviceId());
38 MOCK_CONST_METHOD0(capabilities, mi::DeviceCapabilities());
39 MOCK_CONST_METHOD0(name, std::string());
40 MOCK_CONST_METHOD0(unique_id, std::string());
41 MOCK_CONST_METHOD0(pointer_configuration, mir::optional_value<mi::PointerConfiguration>());
42 MOCK_METHOD1(apply_pointer_configuration, void(mi::PointerConfiguration const&));
43 MOCK_CONST_METHOD0(touchpad_configuration, mir::optional_value<mi::TouchpadConfiguration> ());
44 MOCK_METHOD1(apply_touchpad_configuration, void(mi::TouchpadConfiguration const&));
45
46 MockDevice(mi::DeviceCapabilities caps)
47 : caps(caps)
48 {
49 ON_CALL(*this, capabilities()).WillByDefault(Return(this->caps));
50 }
51
52 mi::DeviceCapabilities caps;
53};
54
55struct MockInputDeviceHub : mi::InputDeviceHub
56{
57 MOCK_METHOD1(add_observer,void(std::shared_ptr<mi::InputDeviceObserver> const&));
58 MOCK_METHOD1(remove_observer,void(std::weak_ptr<mi::InputDeviceObserver> const&));
59};
60
61struct MirInputConfiguration : ::testing::Test
62{
63 template<typename T>
64 using shared_mock = std::shared_ptr<::testing::NiceMock<T>>;
65 shared_mock<MockInputDeviceHub> mock_hub{std::make_shared<::testing::NiceMock<MockInputDeviceHub>>()};
66 shared_mock<MockDevice> mock_mouse{
67 std::make_shared<::testing::NiceMock<MockDevice>>(mi::DeviceCapability::pointer)};
68 shared_mock<MockDevice> mock_touchpad{std::make_shared<::testing::NiceMock<MockDevice>>(
69 mi::DeviceCapability::pointer | mi::DeviceCapability::touchpad)};
70 shared_mock<MockDevice> mock_keyboard{std::make_shared<::testing::NiceMock<MockDevice>>(
71 mi::DeviceCapability::keyboard | mi::DeviceCapability::alpha_numeric)};
72
73 std::shared_ptr<mi::InputDeviceObserver> obs;
74
75 MirInputConfiguration()
76 {
77 ON_CALL(*mock_hub, add_observer(_)).WillByDefault(SaveArg<0>(&obs));
78 }
79};
80}
81
82TEST_F(MirInputConfiguration, registers_something_as_device_observer)
83{
84 EXPECT_CALL(*mock_hub, add_observer(_));
85
86 usc::MirInputConfiguration config(mock_hub);
87}
88
89TEST_F(MirInputConfiguration, configures_device_on_add)
90{
91 usc::MirInputConfiguration config(mock_hub);
92
93 EXPECT_CALL(*mock_touchpad, apply_pointer_configuration(_));
94 EXPECT_CALL(*mock_touchpad, apply_touchpad_configuration(_));
95 obs->device_added(mock_touchpad);
96}
97
98TEST_F(MirInputConfiguration, configures_mouse_on_add)
99{
100 usc::MirInputConfiguration config(mock_hub);
101
102 EXPECT_CALL(*mock_mouse, apply_pointer_configuration(_));
103 obs->device_added(mock_mouse);
104}
105
106TEST_F(MirInputConfiguration, ignores_keyboard_when_added)
107{
108 usc::MirInputConfiguration config(mock_hub);
109
110 EXPECT_CALL(*mock_keyboard, apply_touchpad_configuration(_)).Times(0);
111 EXPECT_CALL(*mock_keyboard, apply_pointer_configuration(_)).Times(0);
112 obs->device_added(mock_keyboard);
113}
114
0115
=== modified file 'tests/unit-tests/test_mir_screen.cpp'
--- tests/unit-tests/test_mir_screen.cpp 2015-09-29 13:05:56 +0000
+++ tests/unit-tests/test_mir_screen.cpp 2016-01-27 14:14:14 +0000
@@ -21,8 +21,9 @@
21#include "src/power_state_change_reason.h"21#include "src/power_state_change_reason.h"
22#include "advanceable_timer.h"22#include "advanceable_timer.h"
2323
24#include "usc/test/mock_display.h"
25
24#include <mir/compositor/compositor.h>26#include <mir/compositor/compositor.h>
25#include <mir/graphics/display.h>
26#include <mir/graphics/display_configuration.h>27#include <mir/graphics/display_configuration.h>
27#include <mir/graphics/gl_context.h>28#include <mir/graphics/gl_context.h>
28#include <mir/input/touch_visualizer.h>29#include <mir/input/touch_visualizer.h>
@@ -33,6 +34,7 @@
33#include <atomic>34#include <atomic>
3435
35namespace mg = mir::graphics;36namespace mg = mir::graphics;
37namespace ut = usc::test;
3638
37namespace39namespace
38{40{
@@ -43,63 +45,6 @@
43 MOCK_METHOD0(stop, void());45 MOCK_METHOD0(stop, void());
44};46};
4547
46struct StubDisplayConfiguration : mg::DisplayConfiguration
47{
48 StubDisplayConfiguration()
49 {
50 conf_output.power_mode = MirPowerMode::mir_power_mode_on;
51 }
52
53 void for_each_card(std::function<void(mg::DisplayConfigurationCard const&)> f) const override
54 {
55 }
56
57 void for_each_output(std::function<void(mg::DisplayConfigurationOutput const&)> f) const override
58 {
59 f(conf_output);
60 }
61
62 void for_each_output(std::function<void(mg::UserDisplayConfigurationOutput&)> f)
63 {
64 mg::UserDisplayConfigurationOutput user{conf_output};
65 f(user);
66 }
67
68 mg::DisplayConfigurationOutput conf_output;
69};
70
71struct MockDisplay : mg::Display
72{
73 void for_each_display_sync_group(std::function<void(mg::DisplaySyncGroup&)> const& f) override
74 {
75 }
76
77 std::unique_ptr<mg::DisplayConfiguration> configuration() const override
78 { return std::unique_ptr<mg::DisplayConfiguration>{new StubDisplayConfiguration{}}; }
79
80 MOCK_METHOD1(configure, void(mg::DisplayConfiguration const& conf));
81
82 void register_configuration_change_handler(
83 mg::EventHandlerRegister& ,
84 mg::DisplayConfigurationChangeHandler const& ) override {};
85
86 void register_pause_resume_handlers(
87 mg::EventHandlerRegister&,
88 mg::DisplayPauseHandler const&,
89 mg::DisplayResumeHandler const&) override
90 {
91 }
92
93 void pause() override {};
94
95 void resume() override {};
96
97 std::shared_ptr<mg::Cursor> create_hardware_cursor(std::shared_ptr<mg::CursorImage> const&) override {return{};};
98
99 std::unique_ptr<mg::GLContext> create_gl_context() override
100 { return std::unique_ptr<mg::GLContext>{};};
101};
102
103struct MockScreenHardware : usc::ScreenHardware48struct MockScreenHardware : usc::ScreenHardware
104{49{
105 MOCK_METHOD0(set_dim_backlight, void());50 MOCK_METHOD0(set_dim_backlight, void());
@@ -333,8 +278,8 @@
333 std::make_shared<testing::NiceMock<MockScreenHardware>>()};278 std::make_shared<testing::NiceMock<MockScreenHardware>>()};
334 std::shared_ptr<MockCompositor> compositor{279 std::shared_ptr<MockCompositor> compositor{
335 std::make_shared<testing::NiceMock<MockCompositor>>()};280 std::make_shared<testing::NiceMock<MockCompositor>>()};
336 std::shared_ptr<MockDisplay> display{281 std::shared_ptr<ut::MockDisplay> display{
337 std::make_shared<testing::NiceMock<MockDisplay>>()};282 std::make_shared<testing::NiceMock<ut::MockDisplay>>()};
338 std::shared_ptr<MockTouchVisualizer> touch_visualizer{283 std::shared_ptr<MockTouchVisualizer> touch_visualizer{
339 std::make_shared<testing::NiceMock<MockTouchVisualizer>>()};284 std::make_shared<testing::NiceMock<MockTouchVisualizer>>()};
340 std::shared_ptr<AdvanceableTimer> timer{285 std::shared_ptr<AdvanceableTimer> timer{
341286
=== modified file 'tests/unit-tests/test_screen_event_handler.cpp'
--- tests/unit-tests/test_screen_event_handler.cpp 2015-10-08 09:54:02 +0000
+++ tests/unit-tests/test_screen_event_handler.cpp 2016-01-27 14:14:14 +0000
@@ -28,6 +28,7 @@
28#include <gtest/gtest.h>28#include <gtest/gtest.h>
29#include <gmock/gmock.h>29#include <gmock/gmock.h>
3030
31#include "linux/input.h"
31#include <atomic>32#include <atomic>
3233
33namespace34namespace
@@ -64,6 +65,19 @@
64 screen_event_handler.handle(*power_key_up_event);65 screen_event_handler.handle(*power_key_up_event);
65 }66 }
6667
68 void press_a_key()
69 {
70 screen_event_handler.handle(*another_key_down_event);
71 }
72
73 void press_volume_keys()
74 {
75 screen_event_handler.handle(*vol_plus_key_down_event);
76 screen_event_handler.handle(*vol_plus_key_up_event);
77 screen_event_handler.handle(*vol_minus_key_down_event);
78 screen_event_handler.handle(*vol_minus_key_up_event);
79 }
80
67 void touch_screen()81 void touch_screen()
68 {82 {
69 screen_event_handler.handle(*touch_event);83 screen_event_handler.handle(*touch_event);
@@ -74,21 +88,50 @@
74 screen_event_handler.handle(*pointer_event);88 screen_event_handler.handle(*pointer_event);
75 }89 }
7690
77 static const int32_t POWER_KEY_CODE = 26;
78 mir::EventUPtr power_key_down_event = mir::events::make_event(91 mir::EventUPtr power_key_down_event = mir::events::make_event(
79 MirInputDeviceId{1}, std::chrono::nanoseconds(0),92 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
80 0, mir_keyboard_action_down,93 0, mir_keyboard_action_down,
81 POWER_KEY_CODE, 0, mir_input_event_modifier_none);94 0, KEY_POWER, mir_input_event_modifier_none);
8295
83 mir::EventUPtr power_key_up_event = mir::events::make_event(96 mir::EventUPtr power_key_up_event = mir::events::make_event(
84 MirInputDeviceId{1}, std::chrono::nanoseconds(0),97 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
85 0, mir_keyboard_action_up,98 0, mir_keyboard_action_up,
86 POWER_KEY_CODE, 0, mir_input_event_modifier_none);99 0, KEY_POWER, mir_input_event_modifier_none);
100
101 mir::EventUPtr vol_plus_key_down_event = mir::events::make_event(
102 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
103 0, mir_keyboard_action_down,
104 0, KEY_VOLUMEUP, mir_input_event_modifier_none);
105
106 mir::EventUPtr vol_plus_key_up_event = mir::events::make_event(
107 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
108 0, mir_keyboard_action_up,
109 0, KEY_VOLUMEUP, mir_input_event_modifier_none);
110
111 mir::EventUPtr vol_minus_key_down_event = mir::events::make_event(
112 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
113 0, mir_keyboard_action_down,
114 0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
115
116 mir::EventUPtr vol_minus_key_up_event = mir::events::make_event(
117 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
118 0, mir_keyboard_action_up,
119 0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
120
121 mir::EventUPtr another_key_down_event = mir::events::make_event(
122 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
123 0, mir_keyboard_action_down,
124 0, KEY_A, mir_input_event_modifier_none);
125
126 mir::EventUPtr another_key_up_event = mir::events::make_event(
127 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
128 0, mir_keyboard_action_up,
129 0, KEY_A, mir_input_event_modifier_none);
87130
88 mir::EventUPtr touch_event = mir::events::make_event(131 mir::EventUPtr touch_event = mir::events::make_event(
89 MirInputDeviceId{1}, std::chrono::nanoseconds(0),132 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
90 0, mir_input_event_modifier_none);133 0, mir_input_event_modifier_none);
91 134
92 mir::EventUPtr pointer_event = mir::events::make_event(135 mir::EventUPtr pointer_event = mir::events::make_event(
93 MirInputDeviceId{1}, std::chrono::nanoseconds(0),136 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
94 0, mir_input_event_modifier_none,137 0, mir_input_event_modifier_none,
@@ -160,13 +203,54 @@
160 touch_screen();203 touch_screen();
161}204}
162205
163TEST_F(AScreenEventHandler, keeps_display_on_temporarily_on_pointer_event)206TEST_F(AScreenEventHandler, turns_on_screen_and_filters_first_pointer_event_when_screen_is_off)
164{207{
208 mock_screen.mock_mode = MirPowerMode::mir_power_mode_off;
209 EXPECT_CALL(mock_screen,
210 set_screen_power_mode(MirPowerMode::mir_power_mode_on,
211 PowerStateChangeReason::unknown));
212
213 auto const event_filtered = screen_event_handler.handle(*pointer_event);
214 EXPECT_TRUE(event_filtered);
215}
216
217TEST_F(AScreenEventHandler, turns_on_screen_and_propagates_keys_when_screen_is_off)
218{
219 mock_screen.mock_mode = MirPowerMode::mir_power_mode_off;
220 EXPECT_CALL(mock_screen,
221 set_screen_power_mode(MirPowerMode::mir_power_mode_on,
222 PowerStateChangeReason::unknown));
223
224 auto const event_filtered = screen_event_handler.handle(*another_key_down_event);
225 EXPECT_FALSE(event_filtered);
226}
227
228TEST_F(AScreenEventHandler, keeps_display_on_temporarily_for_pointer_event_when_screen_is_on)
229{
230 mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
165 EXPECT_CALL(mock_screen, keep_display_on_temporarily());231 EXPECT_CALL(mock_screen, keep_display_on_temporarily());
166232
167 move_pointer();233 move_pointer();
168}234}
169235
236TEST_F(AScreenEventHandler, keeps_display_on_temporarily_key_event_when_screen_is_on)
237{
238 mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
239 EXPECT_CALL(mock_screen, keep_display_on_temporarily());
240
241 press_a_key();
242}
243
244TEST_F(AScreenEventHandler, does_not_affect_screen_state_for_volume_keys)
245{
246 using namespace testing;
247
248 EXPECT_CALL(mock_screen, keep_display_on_temporarily()).Times(0);
249 EXPECT_CALL(mock_screen, set_screen_power_mode(_,_)).Times(0);
250
251 press_volume_keys();
252}
253
170TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)254TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)
171{255{
172 EXPECT_CALL(mock_screen,256 EXPECT_CALL(mock_screen,
@@ -198,10 +282,12 @@
198 release_power_key();282 release_power_key();
199}283}
200284
201TEST_F(AScreenEventHandler, passes_through_all_handled_events)285TEST_F(AScreenEventHandler, passes_through_all_handled_events_when_screen_is_on)
202{286{
203 using namespace testing;287 using namespace testing;
204288
289 mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
290
205 EXPECT_FALSE(screen_event_handler.handle(*power_key_down_event));291 EXPECT_FALSE(screen_event_handler.handle(*power_key_down_event));
206 EXPECT_FALSE(screen_event_handler.handle(*power_key_up_event));292 EXPECT_FALSE(screen_event_handler.handle(*power_key_up_event));
207 EXPECT_FALSE(screen_event_handler.handle(*touch_event));293 EXPECT_FALSE(screen_event_handler.handle(*touch_event));
208294
=== modified file 'tools/png2header.py'
--- tools/png2header.py 2015-06-11 09:15:46 +0000
+++ tools/png2header.py 2016-01-27 14:14:14 +0000
@@ -67,7 +67,7 @@
67 print " unsigned char pixel_data[%d * %d * %d + 1];" % image_info67 print " unsigned char pixel_data[%d * %d * %d + 1];" % image_info
68 print "} %s = {" % variable_name68 print "} %s = {" % variable_name
69 print " %d, %d, %d," % image_info69 print " %d, %d, %d," % image_info
70 print tocstring(image.tostring())70 print tocstring(image.tobytes())
71 print "};"71 print "};"
7272
73def show_usage():73def show_usage():
@@ -82,5 +82,6 @@
82variable_name = sys.argv[2]82variable_name = sys.argv[2]
8383
84image = Image.open(image_filename)84image = Image.open(image_filename)
85premultiply(image)85if image.mode == 'RGBA':
86 premultiply(image)
86export(image, variable_name)87export(image, variable_name)

Subscribers

People subscribed via source and target branches