Merge lp:~mir-team/mir/eventloop-integration into lp:mir
- eventloop-integration
- Merge into development-branch
Status: | Work in progress |
---|---|
Proposed branch: | lp:~mir-team/mir/eventloop-integration |
Merge into: | lp:mir |
Diff against target: |
5401 lines (+2778/-885) 68 files modified
benchmarks/benchmark_multiplexing_dispatchable.cpp (+1/-1) debian/control (+1/-0) debian/mir-test-tools.install (+1/-0) include/client/mir_toolkit/mir_connection.h (+51/-0) include/client/mir_toolkit/mir_wait.h (+1/-0) include/common/mir/dispatch/simple_dispatch_thread.h (+0/-50) include/common/mir/dispatch/threaded_dispatcher.h (+75/-0) src/client/CMakeLists.txt (+1/-0) src/client/buffer_stream.cpp (+25/-6) src/client/buffer_stream.h (+10/-2) src/client/client_buffer_stream.h (+2/-0) src/client/client_buffer_stream_factory.h (+15/-5) src/client/connection_configuration.h (+6/-1) src/client/default_client_buffer_stream_factory.cpp (+27/-17) src/client/default_client_buffer_stream_factory.h (+16/-6) src/client/default_connection_configuration.cpp (+1/-1) src/client/default_connection_configuration.h (+2/-2) src/client/mir_buffer_stream_api.cpp (+23/-16) src/client/mir_connection.cpp (+52/-4) src/client/mir_connection.h (+27/-9) src/client/mir_connection_api.cpp (+60/-1) src/client/mir_prompt_session_api.cpp (+10/-3) src/client/mir_screencast.cpp (+15/-4) src/client/mir_screencast.h (+3/-0) src/client/mir_screencast_api.cpp (+20/-2) src/client/mir_surface.cpp (+20/-8) src/client/mir_surface.h (+4/-2) src/client/mir_surface_api.cpp (+12/-18) src/client/mir_wait_api.cpp (+9/-0) src/client/mir_wait_handle.cpp (+6/-0) src/client/mir_wait_handle.h (+1/-0) src/client/rpc/make_rpc_channel.h (+2/-3) src/client/rpc/make_socket_rpc_channel.cpp (+1/-1) src/client/rpc/mir_basic_rpc_channel.cpp (+7/-2) src/client/rpc/mir_basic_rpc_channel.h (+12/-5) src/client/rpc/mir_protobuf_rpc_channel.cpp (+52/-18) src/client/rpc/mir_protobuf_rpc_channel.h (+33/-14) src/client/symbols.map (+4/-0) src/client/synchronous_helper.cpp (+33/-0) src/client/synchronous_helper.h (+160/-0) src/common/dispatch/CMakeLists.txt (+1/-2) src/common/dispatch/simple_dispatch_thread.cpp (+0/-163) src/common/dispatch/threaded_dispatcher.cpp (+294/-0) src/common/symbols.map (+6/-4) src/server/input/default_input_manager.cpp (+3/-3) src/server/input/default_input_manager.h (+2/-2) tests/acceptance-tests/CMakeLists.txt (+2/-1) tests/acceptance-tests/test_client_library.cpp (+331/-105) tests/include/mir_test/test_protobuf_client.h (+2/-2) tests/include/mir_test_doubles/mock_client_buffer_stream.h (+1/-0) tests/include/mir_test_doubles/mock_client_buffer_stream_factory.h (+16/-6) tests/include/mir_test_doubles/stub_client_buffer_stream_factory.h (+5/-1) tests/include/mir_test_framework/udev_environment.h (+26/-0) tests/integration-tests/client/test_screencast.cpp (+5/-5) tests/mir_test_doubles/test_protobuf_client.cpp (+2/-2) tests/mir_test_framework/CMakeLists.txt (+3/-0) tests/mir_test_framework/udev_environment.cpp (+66/-1) tests/mir_test_framework/udev_recordings/laptop-keyboard-hello.evemu (+272/-0) tests/unit-tests/client/test_client_buffer_stream.cpp (+2/-2) tests/unit-tests/client/test_client_mir_surface.cpp (+1/-1) tests/unit-tests/client/test_mir_connection.cpp (+162/-11) tests/unit-tests/client/test_mir_screencast.cpp (+10/-1) tests/unit-tests/client/test_protobuf_rpc_channel.cpp (+295/-62) tests/unit-tests/dispatch/CMakeLists.txt (+1/-1) tests/unit-tests/dispatch/test_multiplexing_dispatchable.cpp (+21/-18) tests/unit-tests/dispatch/test_simple_dispatch_thread.cpp (+0/-291) tests/unit-tests/dispatch/test_threaded_dispatcher.cpp (+403/-0) tools/valgrind_suppressions_generic (+45/-0) |
To merge this branch: | bzr merge lp:~mir-team/mir/eventloop-integration |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Mir development team | Pending | ||
Review via email: mp+245926@code.launchpad.net |
Commit message
Add a client-driven MirConnection dispatch option.
Lots of clients aren't appreciative of our devil-may-care approach to calling their code on threads of our choosing. For them, we offer mir_connection_
This will simplify XMir, make a Mir backend for Plymouth feasible, and greatly please Ryan.
Description of the change
Add a client-driven MirConnection dispatch option.
Lots of clients aren't appreciative of our devil-may-care approach to calling their code on threads of our choosing. For them, we offer mir_connection_
This will simplify XMir, make a Mir backend for Plymouth feasible, and greatly please Ryan.
Chris Halse Rogers (raof) wrote : | # |
Looks like I'll be breaking this up a bit more, but now actually works!
Bounce off CI to fully test that it fully really fully does fully work.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:2387
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
- 2387. By Chris Halse Rogers
-
Add valgrind suppressions for GDBus bollocks.
- 2386. By Chris Halse Rogers
-
Free the surface_spec in ClientLibrary test.
Now doesn't leak!
- 2385. By Chris Halse Rogers
-
Don't call a synchronous method from a manually-dispatched async callback.
This fails for... some reason. Don't know at the moment.
- 2384. By Chris Halse Rogers
-
Initialise ProtobufRpcChan
nel::prioritise _next_request. Thanks, valgrind.
- 2383. By Chris Halse Rogers
-
Minor improvements to synchronous helper
- 2382. By Chris Halse Rogers
-
Use make_synchronou
s_call helper for all synchronous RPC calls - 2381. By Chris Halse Rogers
-
Add helper infrastructure for making synchronous RPC calls
- 2380. By Chris Halse Rogers
-
Enable getting a MirConnection out of a MirScreencast
- 2379. By Chris Halse Rogers
-
We treat MirBufferStream as a ClientBufferStream internally - make sure the pointers we return *are* ClientBufferStreams
- 2378. By Chris Halse Rogers
-
Add a way to get the MirConnection associated with a MirSurface
Preview Diff
1 | === modified file 'benchmarks/benchmark_multiplexing_dispatchable.cpp' | |||
2 | --- benchmarks/benchmark_multiplexing_dispatchable.cpp 2015-04-24 15:36:12 +0000 | |||
3 | +++ benchmarks/benchmark_multiplexing_dispatchable.cpp 2015-05-14 07:50:26 +0000 | |||
4 | @@ -17,9 +17,9 @@ | |||
5 | 17 | */ | 17 | */ |
6 | 18 | 18 | ||
7 | 19 | #include "mir/dispatch/multiplexing_dispatchable.h" | 19 | #include "mir/dispatch/multiplexing_dispatchable.h" |
8 | 20 | #include "mir/dispatch/simple_dispatch_thread.h" | ||
9 | 21 | 20 | ||
10 | 22 | #include <iostream> | 21 | #include <iostream> |
11 | 22 | #include <thread> | ||
12 | 23 | #include <vector> | 23 | #include <vector> |
13 | 24 | #include <memory> | 24 | #include <memory> |
14 | 25 | #include <chrono> | 25 | #include <chrono> |
15 | 26 | 26 | ||
16 | === modified file 'debian/control' | |||
17 | --- debian/control 2015-05-08 15:40:20 +0000 | |||
18 | +++ debian/control 2015-05-14 07:50:26 +0000 | |||
19 | @@ -245,6 +245,7 @@ | |||
20 | 245 | Pre-Depends: ${misc:Pre-Depends} | 245 | Pre-Depends: ${misc:Pre-Depends} |
21 | 246 | Depends: ${misc:Depends}, | 246 | Depends: ${misc:Depends}, |
22 | 247 | ${shlibs:Depends}, | 247 | ${shlibs:Depends}, |
23 | 248 | umockdev, | ||
24 | 248 | Recommends: mir-demos, | 249 | Recommends: mir-demos, |
25 | 249 | Description: Display Server for Ubuntu - stress tests and other test tools | 250 | Description: Display Server for Ubuntu - stress tests and other test tools |
26 | 250 | Mir is a display server running on linux systems, with a focus on efficiency, | 251 | Mir is a display server running on linux systems, with a focus on efficiency, |
27 | 251 | 252 | ||
28 | === modified file 'debian/mir-test-tools.install' | |||
29 | --- debian/mir-test-tools.install 2015-04-09 06:20:31 +0000 | |||
30 | +++ debian/mir-test-tools.install 2015-05-14 07:50:26 +0000 | |||
31 | @@ -8,3 +8,4 @@ | |||
32 | 8 | usr/lib/*/mir/server-platform/graphics-dummy.so | 8 | usr/lib/*/mir/server-platform/graphics-dummy.so |
33 | 9 | usr/lib/*/mir/server-platform/input-stub.so | 9 | usr/lib/*/mir/server-platform/input-stub.so |
34 | 10 | usr/lib/*/mir/client-platform/dummy.so | 10 | usr/lib/*/mir/client-platform/dummy.so |
35 | 11 | usr/share/mir/udev_recordings | ||
36 | 11 | 12 | ||
37 | === modified file 'include/client/mir_toolkit/mir_connection.h' | |||
38 | --- include/client/mir_toolkit/mir_connection.h 2015-03-31 02:35:42 +0000 | |||
39 | +++ include/client/mir_toolkit/mir_connection.h 2015-05-14 07:50:26 +0000 | |||
40 | @@ -63,6 +63,35 @@ | |||
41 | 63 | MirConnection *mir_connect_sync(char const *server, char const *app_name); | 63 | MirConnection *mir_connect_sync(char const *server, char const *app_name); |
42 | 64 | 64 | ||
43 | 65 | /** | 65 | /** |
44 | 66 | * Request a connection to the Mir server. | ||
45 | 67 | * | ||
46 | 68 | * The client is responsible for handling event consumption via | ||
47 | 69 | * mir_connection_dispatch(). Events will be available when the fd returned | ||
48 | 70 | * by mir_connection_get_event_fd() becomes readable. | ||
49 | 71 | * | ||
50 | 72 | * All callbacks for this MirConnection and any objects created on it will be | ||
51 | 73 | * called from the thread calling mir_connection_dispatch(). | ||
52 | 74 | * | ||
53 | 75 | * \param [in] server A string specifying the server to connect to. | ||
54 | 76 | * Connection strings can either be path to the socket file on | ||
55 | 77 | * the filesystem, or an open file descriptor fd:// | ||
56 | 78 | * \param [in] app_name A name referring to the application | ||
57 | 79 | * \param [in] callback Callback function to be invoked when request | ||
58 | 80 | * completes. mir_connection_is_valid() will return false | ||
59 | 81 | * until this callback has completed. | ||
60 | 82 | * \param [in,out] context User data passed to the callback function | ||
61 | 83 | * \returns The resulting MirConnection | ||
62 | 84 | * \todo Currently manual dispatch interacts awkwardly with *_sync() calls; | ||
63 | 85 | * Synchronous calls do *not* automatically dispatch, so unless client | ||
64 | 86 | * code has a separate thread running dispatch, any *_sync() call will | ||
65 | 87 | * deadlock. This restriction will be fixed in a later release. | ||
66 | 88 | */ | ||
67 | 89 | MirConnection* mir_connect_with_manual_dispatch(char const* server, | ||
68 | 90 | char const* app_name, | ||
69 | 91 | mir_connected_callback callback, | ||
70 | 92 | void* context); | ||
71 | 93 | |||
72 | 94 | /** | ||
73 | 66 | * Test for a valid connection | 95 | * Test for a valid connection |
74 | 67 | * \param [in] connection The connection | 96 | * \param [in] connection The connection |
75 | 68 | * \return True if the supplied connection is valid, or | 97 | * \return True if the supplied connection is valid, or |
76 | @@ -87,6 +116,28 @@ | |||
77 | 87 | void mir_connection_release(MirConnection *connection); | 116 | void mir_connection_release(MirConnection *connection); |
78 | 88 | 117 | ||
79 | 89 | /** | 118 | /** |
80 | 119 | * \brief Get the notification fd for this connection | ||
81 | 120 | * \param [in] connection The connection. This connection must have been created by | ||
82 | 121 | * mir_connect_with_manual_dispatch(). | ||
83 | 122 | * \return A file descriptor that supports select/poll/epoll and similar | ||
84 | 123 | * APIs that becomes readable when there are events to dispatch, | ||
85 | 124 | * or -1 if \ref connection was not created by | ||
86 | 125 | * mir_connect_with_manual_dispatch(); | ||
87 | 126 | * \note This fd is owned by the MirConnection. Do not close the fd yourself. | ||
88 | 127 | * The fd remains valid until mir_connection_release() returns. | ||
89 | 128 | */ | ||
90 | 129 | int mir_connection_get_event_fd(MirConnection* connection); | ||
91 | 130 | |||
92 | 131 | /** | ||
93 | 132 | * \brief Dispatch a single pending event on the connection | ||
94 | 133 | * \param [in] connection The connection. This connection must have been created by | ||
95 | 134 | * mir_connect_with_manual_dispatch(). | ||
96 | 135 | * \note It is an error to call this on a \ref connection not created by | ||
97 | 136 | * mir_connect_with_manual_dispatch(). | ||
98 | 137 | */ | ||
99 | 138 | void mir_connection_dispatch(MirConnection* connection); | ||
100 | 139 | |||
101 | 140 | /** | ||
102 | 90 | * Query platform-specific data and/or file descriptors that are required to | 141 | * Query platform-specific data and/or file descriptors that are required to |
103 | 91 | * initialize GL/EGL features. | 142 | * initialize GL/EGL features. |
104 | 92 | * \param [in] connection The connection | 143 | * \param [in] connection The connection |
105 | 93 | 144 | ||
106 | === modified file 'include/client/mir_toolkit/mir_wait.h' | |||
107 | --- include/client/mir_toolkit/mir_wait.h 2014-03-31 14:36:08 +0000 | |||
108 | +++ include/client/mir_toolkit/mir_wait.h 2015-05-14 07:50:26 +0000 | |||
109 | @@ -46,6 +46,7 @@ | |||
110 | 46 | */ | 46 | */ |
111 | 47 | void mir_wait_for_one(MirWaitHandle *wait_handle); | 47 | void mir_wait_for_one(MirWaitHandle *wait_handle); |
112 | 48 | 48 | ||
113 | 49 | bool mir_wait_handle_ready(MirWaitHandle* wait_handle); | ||
114 | 49 | 50 | ||
115 | 50 | #ifdef __cplusplus | 51 | #ifdef __cplusplus |
116 | 51 | } | 52 | } |
117 | 52 | 53 | ||
118 | === removed file 'include/common/mir/dispatch/simple_dispatch_thread.h' | |||
119 | --- include/common/mir/dispatch/simple_dispatch_thread.h 2015-04-23 18:29:35 +0000 | |||
120 | +++ include/common/mir/dispatch/simple_dispatch_thread.h 1970-01-01 00:00:00 +0000 | |||
121 | @@ -1,50 +0,0 @@ | |||
122 | 1 | /* | ||
123 | 2 | * Copyright © 2015 Canonical Ltd. | ||
124 | 3 | * | ||
125 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
126 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
127 | 6 | * as published by the Free Software Foundation. | ||
128 | 7 | * | ||
129 | 8 | * This program is distributed in the hope that it will be useful, | ||
130 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
131 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
132 | 11 | * GNU Lesser General Public License for more details. | ||
133 | 12 | * | ||
134 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
135 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
136 | 15 | * | ||
137 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
138 | 17 | */ | ||
139 | 18 | |||
140 | 19 | #ifndef MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
141 | 20 | #define MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
142 | 21 | |||
143 | 22 | #include <memory> | ||
144 | 23 | #include <thread> | ||
145 | 24 | #include "mir/fd.h" | ||
146 | 25 | |||
147 | 26 | namespace mir | ||
148 | 27 | { | ||
149 | 28 | namespace dispatch | ||
150 | 29 | { | ||
151 | 30 | class Dispatchable; | ||
152 | 31 | |||
153 | 32 | |||
154 | 33 | class SimpleDispatchThread | ||
155 | 34 | { | ||
156 | 35 | public: | ||
157 | 36 | SimpleDispatchThread(std::shared_ptr<Dispatchable> const& dispatchee); | ||
158 | 37 | SimpleDispatchThread(std::shared_ptr<Dispatchable> const& dispatchee, | ||
159 | 38 | std::function<void()> const& exception_handler); | ||
160 | 39 | ~SimpleDispatchThread() noexcept; | ||
161 | 40 | |||
162 | 41 | private: | ||
163 | 42 | Fd shutdown_fd; | ||
164 | 43 | std::thread eventloop; | ||
165 | 44 | }; | ||
166 | 45 | |||
167 | 46 | } | ||
168 | 47 | } | ||
169 | 48 | |||
170 | 49 | |||
171 | 50 | #endif // MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
172 | 51 | 0 | ||
173 | === added file 'include/common/mir/dispatch/threaded_dispatcher.h' | |||
174 | --- include/common/mir/dispatch/threaded_dispatcher.h 1970-01-01 00:00:00 +0000 | |||
175 | +++ include/common/mir/dispatch/threaded_dispatcher.h 2015-05-14 07:50:26 +0000 | |||
176 | @@ -0,0 +1,75 @@ | |||
177 | 1 | /* | ||
178 | 2 | * Copyright © 2015 Canonical Ltd. | ||
179 | 3 | * | ||
180 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
181 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
182 | 6 | * as published by the Free Software Foundation. | ||
183 | 7 | * | ||
184 | 8 | * This program is distributed in the hope that it will be useful, | ||
185 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
186 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
187 | 11 | * GNU Lesser General Public License for more details. | ||
188 | 12 | * | ||
189 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
190 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
191 | 15 | * | ||
192 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
193 | 17 | */ | ||
194 | 18 | |||
195 | 19 | #ifndef MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
196 | 20 | #define MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
197 | 21 | |||
198 | 22 | #include <string> | ||
199 | 23 | #include <memory> | ||
200 | 24 | #include <thread> | ||
201 | 25 | #include <vector> | ||
202 | 26 | #include <mutex> | ||
203 | 27 | #include <condition_variable> | ||
204 | 28 | |||
205 | 29 | #include "mir/dispatch/multiplexing_dispatchable.h" | ||
206 | 30 | #include "mir/fd.h" | ||
207 | 31 | |||
208 | 32 | namespace mir | ||
209 | 33 | { | ||
210 | 34 | namespace dispatch | ||
211 | 35 | { | ||
212 | 36 | class Dispatchable; | ||
213 | 37 | |||
214 | 38 | class ThreadedDispatcher | ||
215 | 39 | { | ||
216 | 40 | public: | ||
217 | 41 | ThreadedDispatcher(std::string const& name, std::shared_ptr<Dispatchable> const& dispatchee); | ||
218 | 42 | ThreadedDispatcher(std::string const& name, | ||
219 | 43 | std::shared_ptr<Dispatchable> const& dispatchee, | ||
220 | 44 | std::function<void()> const& exception_handler); | ||
221 | 45 | ~ThreadedDispatcher() noexcept; | ||
222 | 46 | |||
223 | 47 | void add_thread(); | ||
224 | 48 | void remove_thread(); | ||
225 | 49 | |||
226 | 50 | private: | ||
227 | 51 | class ThreadShutdownRequestHandler; | ||
228 | 52 | friend class ThreadShutdownRequestHandler; | ||
229 | 53 | |||
230 | 54 | std::string const name_base; | ||
231 | 55 | |||
232 | 56 | std::shared_ptr<ThreadShutdownRequestHandler> thread_exiter; | ||
233 | 57 | std::shared_ptr<MultiplexingDispatchable> dispatcher; | ||
234 | 58 | |||
235 | 59 | std::mutex thread_pool_mutex; | ||
236 | 60 | std::vector<std::thread> threadpool; | ||
237 | 61 | |||
238 | 62 | std::function<void()> const exception_handler; | ||
239 | 63 | |||
240 | 64 | static void dispatch_loop(std::string const& name, | ||
241 | 65 | std::shared_ptr<ThreadShutdownRequestHandler> thread_register, | ||
242 | 66 | std::shared_ptr<Dispatchable> dispatcher, | ||
243 | 67 | std::function<void()> const& exception_handler); | ||
244 | 68 | |||
245 | 69 | }; | ||
246 | 70 | |||
247 | 71 | } | ||
248 | 72 | } | ||
249 | 73 | |||
250 | 74 | |||
251 | 75 | #endif // MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_ | ||
252 | 0 | 76 | ||
253 | === modified file 'src/client/CMakeLists.txt' | |||
254 | --- src/client/CMakeLists.txt 2015-05-08 09:01:55 +0000 | |||
255 | +++ src/client/CMakeLists.txt 2015-05-14 07:50:26 +0000 | |||
256 | @@ -70,6 +70,7 @@ | |||
257 | 70 | buffer_stream.cpp | 70 | buffer_stream.cpp |
258 | 71 | mir_buffer_stream_api.cpp | 71 | mir_buffer_stream_api.cpp |
259 | 72 | default_client_buffer_stream_factory.cpp | 72 | default_client_buffer_stream_factory.cpp |
260 | 73 | synchronous_helper.cpp | ||
261 | 73 | ${MIR_CLIENT_SOURCES} | 74 | ${MIR_CLIENT_SOURCES} |
262 | 74 | ) | 75 | ) |
263 | 75 | 76 | ||
264 | 76 | 77 | ||
265 | === modified file 'src/client/buffer_stream.cpp' | |||
266 | --- src/client/buffer_stream.cpp 2015-04-23 14:09:57 +0000 | |||
267 | +++ src/client/buffer_stream.cpp 2015-05-14 07:50:26 +0000 | |||
268 | @@ -87,13 +87,16 @@ | |||
269 | 87 | // TODO: It seems like a bit of a wart that we have to pass the Logger specifically here...perhaps | 87 | // TODO: It seems like a bit of a wart that we have to pass the Logger specifically here...perhaps |
270 | 88 | // due to the lack of an easily mockable client configuration interface (passing around | 88 | // due to the lack of an easily mockable client configuration interface (passing around |
271 | 89 | // connection can complicate unit tests ala MirSurface and test_client_mir_surface.cpp) | 89 | // connection can complicate unit tests ala MirSurface and test_client_mir_surface.cpp) |
273 | 90 | mcl::BufferStream::BufferStream(mp::DisplayServer& server, | 90 | mcl::BufferStream::BufferStream( |
274 | 91 | MirConnection* allocating_connection, | ||
275 | 92 | mp::DisplayServer& server, | ||
276 | 91 | mcl::BufferStreamMode mode, | 93 | mcl::BufferStreamMode mode, |
277 | 92 | std::shared_ptr<mcl::ClientPlatform> const& client_platform, | 94 | std::shared_ptr<mcl::ClientPlatform> const& client_platform, |
278 | 93 | mp::BufferStream const& protobuf_bs, | 95 | mp::BufferStream const& protobuf_bs, |
279 | 94 | std::shared_ptr<mcl::PerfReport> const& perf_report, | 96 | std::shared_ptr<mcl::PerfReport> const& perf_report, |
280 | 95 | std::string const& surface_name) | 97 | std::string const& surface_name) |
282 | 96 | : display_server(server), | 98 | : connection{allocating_connection}, |
283 | 99 | display_server(server), | ||
284 | 97 | mode(mode), | 100 | mode(mode), |
285 | 98 | client_platform(client_platform), | 101 | client_platform(client_platform), |
286 | 99 | protobuf_bs(protobuf_bs), | 102 | protobuf_bs(protobuf_bs), |
287 | @@ -106,13 +109,16 @@ | |||
288 | 106 | perf_report->name_surface(surface_name.c_str()); | 109 | perf_report->name_surface(surface_name.c_str()); |
289 | 107 | } | 110 | } |
290 | 108 | 111 | ||
292 | 109 | mcl::BufferStream::BufferStream(mp::DisplayServer& server, | 112 | mcl::BufferStream::BufferStream( |
293 | 113 | MirConnection* allocating_connection, | ||
294 | 114 | mp::DisplayServer& server, | ||
295 | 110 | std::shared_ptr<mcl::ClientPlatform> const& client_platform, | 115 | std::shared_ptr<mcl::ClientPlatform> const& client_platform, |
296 | 111 | mp::BufferStreamParameters const& parameters, | 116 | mp::BufferStreamParameters const& parameters, |
297 | 112 | std::shared_ptr<mcl::PerfReport> const& perf_report, | 117 | std::shared_ptr<mcl::PerfReport> const& perf_report, |
298 | 113 | mir_buffer_stream_callback callback, | 118 | mir_buffer_stream_callback callback, |
299 | 114 | void *context) | 119 | void *context) |
301 | 115 | : display_server(server), | 120 | : connection{allocating_connection}, |
302 | 121 | display_server(server), | ||
303 | 116 | mode(BufferStreamMode::Producer), | 122 | mode(BufferStreamMode::Producer), |
304 | 117 | client_platform(client_platform), | 123 | client_platform(client_platform), |
305 | 118 | buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size}, | 124 | buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size}, |
306 | @@ -146,7 +152,11 @@ | |||
307 | 146 | egl_native_window_ = client_platform->create_egl_native_window(this); | 152 | egl_native_window_ = client_platform->create_egl_native_window(this); |
308 | 147 | 153 | ||
309 | 148 | if (callback) | 154 | if (callback) |
311 | 149 | callback(reinterpret_cast<MirBufferStream*>(this), context); | 155 | { |
312 | 156 | // Fun fact! The offset of mcl::ClientBufferStream's vtable in *this is *not* 0! | ||
313 | 157 | auto cbs_object = static_cast<mcl::ClientBufferStream*>(this); | ||
314 | 158 | callback(reinterpret_cast<MirBufferStream*>(cbs_object), context); | ||
315 | 159 | } | ||
316 | 150 | create_wait_handle.result_received(); | 160 | create_wait_handle.result_received(); |
317 | 151 | } | 161 | } |
318 | 152 | 162 | ||
319 | @@ -382,7 +392,11 @@ | |||
320 | 382 | mir_buffer_stream_callback callback, void* context) | 392 | mir_buffer_stream_callback callback, void* context) |
321 | 383 | { | 393 | { |
322 | 384 | if (callback) | 394 | if (callback) |
324 | 385 | callback(reinterpret_cast<MirBufferStream*>(this), context); | 395 | { |
325 | 396 | // Fun fact! The offset of mcl::ClientBufferStream's vtable in *this is *not* 0! | ||
326 | 397 | auto cbs_object = static_cast<mcl::ClientBufferStream*>(this); | ||
327 | 398 | callback(reinterpret_cast<MirBufferStream*>(cbs_object), context); | ||
328 | 399 | } | ||
329 | 386 | release_wait_handle.result_received(); | 400 | release_wait_handle.result_received(); |
330 | 387 | } | 401 | } |
331 | 388 | 402 | ||
332 | @@ -403,3 +417,8 @@ | |||
333 | 403 | { | 417 | { |
334 | 404 | buffer_depository.set_max_buffers(cache_size); | 418 | buffer_depository.set_max_buffers(cache_size); |
335 | 405 | } | 419 | } |
336 | 420 | |||
337 | 421 | MirConnection* mcl::BufferStream::get_connection() const | ||
338 | 422 | { | ||
339 | 423 | return connection; | ||
340 | 424 | } | ||
341 | 406 | 425 | ||
342 | === modified file 'src/client/buffer_stream.h' | |||
343 | --- src/client/buffer_stream.h 2015-04-23 14:09:57 +0000 | |||
344 | +++ src/client/buffer_stream.h 2015-05-14 07:50:26 +0000 | |||
345 | @@ -57,14 +57,18 @@ | |||
346 | 57 | class BufferStream : public EGLNativeSurface, public ClientBufferStream | 57 | class BufferStream : public EGLNativeSurface, public ClientBufferStream |
347 | 58 | { | 58 | { |
348 | 59 | public: | 59 | public: |
350 | 60 | BufferStream(mir::protobuf::DisplayServer& server, | 60 | BufferStream( |
351 | 61 | MirConnection* allocating_connection, | ||
352 | 62 | mir::protobuf::DisplayServer& server, | ||
353 | 61 | BufferStreamMode mode, | 63 | BufferStreamMode mode, |
354 | 62 | std::shared_ptr<ClientPlatform> const& native_window_factory, | 64 | std::shared_ptr<ClientPlatform> const& native_window_factory, |
355 | 63 | protobuf::BufferStream const& protobuf_bs, | 65 | protobuf::BufferStream const& protobuf_bs, |
356 | 64 | std::shared_ptr<PerfReport> const& perf_report, | 66 | std::shared_ptr<PerfReport> const& perf_report, |
357 | 65 | std::string const& surface_name); | 67 | std::string const& surface_name); |
358 | 66 | // For surfaceless buffer streams | 68 | // For surfaceless buffer streams |
360 | 67 | BufferStream(mir::protobuf::DisplayServer& server, | 69 | BufferStream( |
361 | 70 | MirConnection* allocating_connection, | ||
362 | 71 | mir::protobuf::DisplayServer& server, | ||
363 | 68 | std::shared_ptr<ClientPlatform> const& native_window_factory, | 72 | std::shared_ptr<ClientPlatform> const& native_window_factory, |
364 | 69 | mir::protobuf::BufferStreamParameters const& parameters, | 73 | mir::protobuf::BufferStreamParameters const& parameters, |
365 | 70 | std::shared_ptr<PerfReport> const& perf_report, | 74 | std::shared_ptr<PerfReport> const& perf_report, |
366 | @@ -100,6 +104,8 @@ | |||
367 | 100 | 104 | ||
368 | 101 | frontend::BufferStreamId rpc_id() const override; | 105 | frontend::BufferStreamId rpc_id() const override; |
369 | 102 | bool valid() const override; | 106 | bool valid() const override; |
370 | 107 | |||
371 | 108 | MirConnection* get_connection() const override; | ||
372 | 103 | 109 | ||
373 | 104 | protected: | 110 | protected: |
374 | 105 | BufferStream(BufferStream const&) = delete; | 111 | BufferStream(BufferStream const&) = delete; |
375 | @@ -116,6 +122,8 @@ | |||
376 | 116 | 122 | ||
377 | 117 | mutable std::mutex mutex; // Protects all members of *this | 123 | mutable std::mutex mutex; // Protects all members of *this |
378 | 118 | 124 | ||
379 | 125 | MirConnection* const connection; | ||
380 | 126 | |||
381 | 119 | mir::protobuf::DisplayServer& display_server; | 127 | mir::protobuf::DisplayServer& display_server; |
382 | 120 | 128 | ||
383 | 121 | BufferStreamMode const mode; | 129 | BufferStreamMode const mode; |
384 | 122 | 130 | ||
385 | === modified file 'src/client/client_buffer_stream.h' | |||
386 | --- src/client/client_buffer_stream.h 2015-04-01 20:00:19 +0000 | |||
387 | +++ src/client/client_buffer_stream.h 2015-05-14 07:50:26 +0000 | |||
388 | @@ -63,6 +63,8 @@ | |||
389 | 63 | virtual MirWaitHandle* release(mir_buffer_stream_callback callback, void* context) = 0; | 63 | virtual MirWaitHandle* release(mir_buffer_stream_callback callback, void* context) = 0; |
390 | 64 | 64 | ||
391 | 65 | virtual bool valid() const = 0; | 65 | virtual bool valid() const = 0; |
392 | 66 | |||
393 | 67 | virtual MirConnection* get_connection() const = 0; | ||
394 | 66 | 68 | ||
395 | 67 | protected: | 69 | protected: |
396 | 68 | ClientBufferStream() = default; | 70 | ClientBufferStream() = default; |
397 | 69 | 71 | ||
398 | === modified file 'src/client/client_buffer_stream_factory.h' | |||
399 | --- src/client/client_buffer_stream_factory.h 2015-04-01 20:00:19 +0000 | |||
400 | +++ src/client/client_buffer_stream_factory.h 2015-05-14 07:50:26 +0000 | |||
401 | @@ -25,6 +25,8 @@ | |||
402 | 25 | 25 | ||
403 | 26 | #include <memory> | 26 | #include <memory> |
404 | 27 | 27 | ||
405 | 28 | class MirConnection; | ||
406 | 29 | |||
407 | 28 | namespace mir | 30 | namespace mir |
408 | 29 | { | 31 | { |
409 | 30 | namespace client | 32 | namespace client |
410 | @@ -34,13 +36,21 @@ | |||
411 | 34 | class ClientBufferStreamFactory | 36 | class ClientBufferStreamFactory |
412 | 35 | { | 37 | { |
413 | 36 | public: | 38 | public: |
418 | 37 | virtual std::shared_ptr<ClientBufferStream> make_consumer_stream(protobuf::DisplayServer& server, | 39 | virtual std::shared_ptr<ClientBufferStream> make_consumer_stream( |
419 | 38 | protobuf::BufferStream const& protobuf_bs, std::string const& surface_name) = 0; | 40 | MirConnection* allocating_connection, |
420 | 39 | virtual std::shared_ptr<ClientBufferStream> make_producer_stream(protobuf::DisplayServer& server, | 41 | protobuf::DisplayServer& server, |
421 | 40 | protobuf::BufferStream const& protobuf_bs, std::string const& surface_name) = 0; | 42 | protobuf::BufferStream const& protobuf_bs, |
422 | 43 | std::string const& surface_name) = 0; | ||
423 | 44 | virtual std::shared_ptr<ClientBufferStream> make_producer_stream( | ||
424 | 45 | MirConnection* allocating_connection, | ||
425 | 46 | protobuf::DisplayServer& server, | ||
426 | 47 | protobuf::BufferStream const& protobuf_bs, | ||
427 | 48 | std::string const& surface_name) = 0; | ||
428 | 41 | 49 | ||
429 | 42 | // For creating buffer stream owned by client. | 50 | // For creating buffer stream owned by client. |
431 | 43 | virtual ClientBufferStream* make_producer_stream(protobuf::DisplayServer& server, | 51 | virtual ClientBufferStream* make_producer_stream( |
432 | 52 | MirConnection* allocating_connection, | ||
433 | 53 | protobuf::DisplayServer& server, | ||
434 | 44 | protobuf::BufferStreamParameters const& params, | 54 | protobuf::BufferStreamParameters const& params, |
435 | 45 | mir_buffer_stream_callback callback, void* context) = 0; | 55 | mir_buffer_stream_callback callback, void* context) = 0; |
436 | 46 | 56 | ||
437 | 47 | 57 | ||
438 | === modified file 'src/client/connection_configuration.h' | |||
439 | --- src/client/connection_configuration.h 2015-01-21 07:34:50 +0000 | |||
440 | +++ src/client/connection_configuration.h 2015-05-14 07:50:26 +0000 | |||
441 | @@ -49,13 +49,18 @@ | |||
442 | 49 | class EventSink; | 49 | class EventSink; |
443 | 50 | class EventHandlerRegister; | 50 | class EventHandlerRegister; |
444 | 51 | 51 | ||
445 | 52 | namespace rpc | ||
446 | 53 | { | ||
447 | 54 | class MirBasicRpcChannel; | ||
448 | 55 | } | ||
449 | 56 | |||
450 | 52 | class ConnectionConfiguration | 57 | class ConnectionConfiguration |
451 | 53 | { | 58 | { |
452 | 54 | public: | 59 | public: |
453 | 55 | virtual ~ConnectionConfiguration() = default; | 60 | virtual ~ConnectionConfiguration() = default; |
454 | 56 | 61 | ||
455 | 57 | virtual std::shared_ptr<ConnectionSurfaceMap> the_surface_map() = 0; | 62 | virtual std::shared_ptr<ConnectionSurfaceMap> the_surface_map() = 0; |
457 | 58 | virtual std::shared_ptr<google::protobuf::RpcChannel> the_rpc_channel() = 0; | 63 | virtual std::shared_ptr<rpc::MirBasicRpcChannel> the_rpc_channel() = 0; |
458 | 59 | virtual std::shared_ptr<mir::logging::Logger> the_logger() = 0; | 64 | virtual std::shared_ptr<mir::logging::Logger> the_logger() = 0; |
459 | 60 | virtual std::shared_ptr<ClientPlatformFactory> the_client_platform_factory() = 0; | 65 | virtual std::shared_ptr<ClientPlatformFactory> the_client_platform_factory() = 0; |
460 | 61 | virtual std::shared_ptr<input::receiver::InputPlatform> the_input_platform() = 0; | 66 | virtual std::shared_ptr<input::receiver::InputPlatform> the_input_platform() = 0; |
461 | 62 | 67 | ||
462 | === modified file 'src/client/default_client_buffer_stream_factory.cpp' | |||
463 | --- src/client/default_client_buffer_stream_factory.cpp 2015-04-01 20:00:19 +0000 | |||
464 | +++ src/client/default_client_buffer_stream_factory.cpp 2015-05-14 07:50:26 +0000 | |||
465 | @@ -57,21 +57,31 @@ | |||
466 | 57 | { | 57 | { |
467 | 58 | } | 58 | } |
468 | 59 | 59 | ||
486 | 60 | std::shared_ptr<mcl::ClientBufferStream> mcl::DefaultClientBufferStreamFactory::make_consumer_stream(mp::DisplayServer& server, | 60 | std::shared_ptr<mcl::ClientBufferStream> mcl::DefaultClientBufferStreamFactory::make_consumer_stream( |
487 | 61 | mp::BufferStream const& protobuf_bs, std::string const& surface_name) | 61 | MirConnection* allocating_connection, |
488 | 62 | { | 62 | mp::DisplayServer& server, |
489 | 63 | return std::make_shared<mcl::BufferStream>(server, mcl::BufferStreamMode::Consumer, client_platform, protobuf_bs, make_perf_report(logger), surface_name); | 63 | mp::BufferStream const& protobuf_bs, |
490 | 64 | } | 64 | std::string const& surface_name) |
491 | 65 | 65 | { | |
492 | 66 | std::shared_ptr<mcl::ClientBufferStream> mcl::DefaultClientBufferStreamFactory::make_producer_stream(mp::DisplayServer& server, | 66 | return std::make_shared<mcl::BufferStream>(allocating_connection, server, mcl::BufferStreamMode::Consumer, client_platform, protobuf_bs, make_perf_report(logger), surface_name); |
493 | 67 | mp::BufferStream const& protobuf_bs, std::string const& surface_name) | 67 | } |
494 | 68 | { | 68 | |
495 | 69 | return std::make_shared<mcl::BufferStream>(server, mcl::BufferStreamMode::Producer, client_platform, protobuf_bs, make_perf_report(logger), surface_name); | 69 | std::shared_ptr<mcl::ClientBufferStream> mcl::DefaultClientBufferStreamFactory::make_producer_stream( |
496 | 70 | } | 70 | MirConnection* allocating_connection, |
497 | 71 | 71 | mp::DisplayServer& server, | |
498 | 72 | 72 | mp::BufferStream const& protobuf_bs, | |
499 | 73 | mcl::ClientBufferStream* mcl::DefaultClientBufferStreamFactory::make_producer_stream(mp::DisplayServer& server, | 73 | std::string const& surface_name) |
500 | 74 | mp::BufferStreamParameters const& params, mir_buffer_stream_callback callback, void* context) | 74 | { |
501 | 75 | { | 75 | return std::make_shared<mcl::BufferStream>(allocating_connection, server, mcl::BufferStreamMode::Producer, client_platform, protobuf_bs, make_perf_report(logger), surface_name); |
502 | 76 | return new mcl::BufferStream(server, client_platform, params, make_perf_report(logger), callback, context); | 76 | } |
503 | 77 | |||
504 | 78 | |||
505 | 79 | mcl::ClientBufferStream* mcl::DefaultClientBufferStreamFactory::make_producer_stream( | ||
506 | 80 | MirConnection* allocating_connection, | ||
507 | 81 | mp::DisplayServer& server, | ||
508 | 82 | mp::BufferStreamParameters const& params, | ||
509 | 83 | mir_buffer_stream_callback callback, | ||
510 | 84 | void* context) | ||
511 | 85 | { | ||
512 | 86 | return new mcl::BufferStream(allocating_connection, server, client_platform, params, make_perf_report(logger), callback, context); | ||
513 | 77 | } | 87 | } |
514 | 78 | 88 | ||
515 | === modified file 'src/client/default_client_buffer_stream_factory.h' | |||
516 | --- src/client/default_client_buffer_stream_factory.h 2015-04-01 20:00:19 +0000 | |||
517 | +++ src/client/default_client_buffer_stream_factory.h 2015-05-14 07:50:26 +0000 | |||
518 | @@ -21,6 +21,8 @@ | |||
519 | 21 | 21 | ||
520 | 22 | #include "client_buffer_stream_factory.h" | 22 | #include "client_buffer_stream_factory.h" |
521 | 23 | 23 | ||
522 | 24 | class MirConnection; | ||
523 | 25 | |||
524 | 24 | namespace mir | 26 | namespace mir |
525 | 25 | { | 27 | { |
526 | 26 | namespace logging | 28 | namespace logging |
527 | @@ -40,14 +42,22 @@ | |||
528 | 40 | std::shared_ptr<logging::Logger> const& logger); | 42 | std::shared_ptr<logging::Logger> const& logger); |
529 | 41 | virtual ~DefaultClientBufferStreamFactory() = default; | 43 | virtual ~DefaultClientBufferStreamFactory() = default; |
530 | 42 | 44 | ||
535 | 43 | std::shared_ptr<ClientBufferStream> make_consumer_stream(protobuf::DisplayServer& server, | 45 | std::shared_ptr<ClientBufferStream> make_consumer_stream( |
536 | 44 | protobuf::BufferStream const& protobuf_bs, std::string const& surface_name); | 46 | MirConnection* allocating_connection, |
537 | 45 | std::shared_ptr<ClientBufferStream> make_producer_stream(protobuf::DisplayServer& server, | 47 | protobuf::DisplayServer& server, |
538 | 46 | protobuf::BufferStream const& protobuf_bs, std::string const& surface_name); | 48 | protobuf::BufferStream const& protobuf_bs, |
539 | 49 | std::string const& surface_name) override; | ||
540 | 50 | std::shared_ptr<ClientBufferStream> make_producer_stream( | ||
541 | 51 | MirConnection* allocating_connection, | ||
542 | 52 | protobuf::DisplayServer& server, | ||
543 | 53 | protobuf::BufferStream const& protobuf_bs, | ||
544 | 54 | std::string const& surface_name) override; | ||
545 | 47 | 55 | ||
547 | 48 | ClientBufferStream* make_producer_stream(protobuf::DisplayServer& server, | 56 | ClientBufferStream* make_producer_stream( |
548 | 57 | MirConnection* allocating_connection, | ||
549 | 58 | protobuf::DisplayServer& server, | ||
550 | 49 | protobuf::BufferStreamParameters const& params, | 59 | protobuf::BufferStreamParameters const& params, |
552 | 50 | mir_buffer_stream_callback callback, void* context); | 60 | mir_buffer_stream_callback callback, void* context) override; |
553 | 51 | 61 | ||
554 | 52 | private: | 62 | private: |
555 | 53 | std::shared_ptr<ClientPlatform> const client_platform; | 63 | std::shared_ptr<ClientPlatform> const client_platform; |
556 | 54 | 64 | ||
557 | === modified file 'src/client/default_connection_configuration.cpp' | |||
558 | --- src/client/default_connection_configuration.cpp 2015-03-31 02:35:42 +0000 | |||
559 | +++ src/client/default_connection_configuration.cpp 2015-05-14 07:50:26 +0000 | |||
560 | @@ -85,7 +85,7 @@ | |||
561 | 85 | }); | 85 | }); |
562 | 86 | } | 86 | } |
563 | 87 | 87 | ||
565 | 88 | std::shared_ptr<google::protobuf::RpcChannel> | 88 | std::shared_ptr<mcl::rpc::MirBasicRpcChannel> |
566 | 89 | mcl::DefaultConnectionConfiguration::the_rpc_channel() | 89 | mcl::DefaultConnectionConfiguration::the_rpc_channel() |
567 | 90 | { | 90 | { |
568 | 91 | return rpc_channel( | 91 | return rpc_channel( |
569 | 92 | 92 | ||
570 | === modified file 'src/client/default_connection_configuration.h' | |||
571 | --- src/client/default_connection_configuration.h 2015-01-21 07:34:50 +0000 | |||
572 | +++ src/client/default_connection_configuration.h 2015-05-14 07:50:26 +0000 | |||
573 | @@ -51,7 +51,7 @@ | |||
574 | 51 | DefaultConnectionConfiguration(std::string const& socket_file); | 51 | DefaultConnectionConfiguration(std::string const& socket_file); |
575 | 52 | 52 | ||
576 | 53 | std::shared_ptr<ConnectionSurfaceMap> the_surface_map() override; | 53 | std::shared_ptr<ConnectionSurfaceMap> the_surface_map() override; |
578 | 54 | std::shared_ptr<google::protobuf::RpcChannel> the_rpc_channel() override; | 54 | std::shared_ptr<rpc::MirBasicRpcChannel> the_rpc_channel() override; |
579 | 55 | std::shared_ptr<mir::logging::Logger> the_logger() override; | 55 | std::shared_ptr<mir::logging::Logger> the_logger() override; |
580 | 56 | std::shared_ptr<ClientPlatformFactory> the_client_platform_factory() override; | 56 | std::shared_ptr<ClientPlatformFactory> the_client_platform_factory() override; |
581 | 57 | std::shared_ptr<input::receiver::InputPlatform> the_input_platform() override; | 57 | std::shared_ptr<input::receiver::InputPlatform> the_input_platform() override; |
582 | @@ -66,7 +66,7 @@ | |||
583 | 66 | virtual std::shared_ptr<input::receiver::InputReceiverReport> the_input_receiver_report(); | 66 | virtual std::shared_ptr<input::receiver::InputReceiverReport> the_input_receiver_report(); |
584 | 67 | 67 | ||
585 | 68 | protected: | 68 | protected: |
587 | 69 | CachedPtr<google::protobuf::RpcChannel> rpc_channel; | 69 | CachedPtr<rpc::MirBasicRpcChannel> rpc_channel; |
588 | 70 | CachedPtr<mir::logging::Logger> logger; | 70 | CachedPtr<mir::logging::Logger> logger; |
589 | 71 | CachedPtr<ClientPlatformFactory> client_platform_factory; | 71 | CachedPtr<ClientPlatformFactory> client_platform_factory; |
590 | 72 | CachedPtr<input::receiver::InputPlatform> input_platform; | 72 | CachedPtr<input::receiver::InputPlatform> input_platform; |
591 | 73 | 73 | ||
592 | === modified file 'src/client/mir_buffer_stream_api.cpp' | |||
593 | --- src/client/mir_buffer_stream_api.cpp 2015-03-31 02:35:42 +0000 | |||
594 | +++ src/client/mir_buffer_stream_api.cpp 2015-05-14 07:50:26 +0000 | |||
595 | @@ -28,6 +28,8 @@ | |||
596 | 28 | 28 | ||
597 | 29 | #include "mir/uncaught.h" | 29 | #include "mir/uncaught.h" |
598 | 30 | 30 | ||
599 | 31 | #include "synchronous_helper.h" | ||
600 | 32 | |||
601 | 31 | #include <stdexcept> | 33 | #include <stdexcept> |
602 | 32 | #include <boost/throw_exception.hpp> | 34 | #include <boost/throw_exception.hpp> |
603 | 33 | 35 | ||
604 | @@ -49,13 +51,6 @@ | |||
605 | 49 | mcl::ClientBufferStream *bs = reinterpret_cast<mcl::ClientBufferStream*>(stream); | 51 | mcl::ClientBufferStream *bs = reinterpret_cast<mcl::ClientBufferStream*>(stream); |
606 | 50 | delete bs; | 52 | delete bs; |
607 | 51 | } | 53 | } |
608 | 52 | // assign_result is compatible with all 2-parameter callbacks | ||
609 | 53 | void assign_result(void* result, void** context) | ||
610 | 54 | { | ||
611 | 55 | if (context) | ||
612 | 56 | *context = result; | ||
613 | 57 | } | ||
614 | 58 | |||
615 | 59 | } | 54 | } |
616 | 60 | 55 | ||
617 | 61 | 56 | ||
618 | @@ -74,7 +69,7 @@ | |||
619 | 74 | params.set_pixel_format(format); | 69 | params.set_pixel_format(format); |
620 | 75 | params.set_buffer_usage(buffer_usage); | 70 | params.set_buffer_usage(buffer_usage); |
621 | 76 | 71 | ||
623 | 77 | return connection->get_client_buffer_stream_factory()->make_producer_stream(connection->display_server(), params, callback, context) | 72 | return connection->get_client_buffer_stream_factory()->make_producer_stream(connection, connection->display_server(), params, callback, context) |
624 | 78 | ->get_create_wait_handle(); | 73 | ->get_create_wait_handle(); |
625 | 79 | } | 74 | } |
626 | 80 | catch (std::exception const& ex) | 75 | catch (std::exception const& ex) |
627 | @@ -89,10 +84,14 @@ | |||
628 | 89 | MirBufferUsage buffer_usage) | 84 | MirBufferUsage buffer_usage) |
629 | 90 | try | 85 | try |
630 | 91 | { | 86 | { |
635 | 92 | mcl::BufferStream *stream = nullptr; | 87 | MirBufferStream* stream = nullptr; |
636 | 93 | mir_connection_create_buffer_stream(connection, width, height, format, buffer_usage, | 88 | make_synchronous_call(connection, |
637 | 94 | reinterpret_cast<mir_buffer_stream_callback>(assign_result), &stream)->wait_for_all(); | 89 | mir_connection_create_buffer_stream, |
638 | 95 | return reinterpret_cast<MirBufferStream*>(dynamic_cast<mcl::ClientBufferStream*>(stream)); | 90 | connection, |
639 | 91 | width, height, format, buffer_usage, | ||
640 | 92 | &assign_result<MirBufferStream>, | ||
641 | 93 | &stream); | ||
642 | 94 | return stream; | ||
643 | 96 | } | 95 | } |
644 | 97 | catch (std::exception const& ex) | 96 | catch (std::exception const& ex) |
645 | 98 | { | 97 | { |
646 | @@ -113,7 +112,11 @@ | |||
647 | 113 | void mir_buffer_stream_release_sync(MirBufferStream *buffer_stream) | 112 | void mir_buffer_stream_release_sync(MirBufferStream *buffer_stream) |
648 | 114 | { | 113 | { |
649 | 115 | mcl::ClientBufferStream *bs = reinterpret_cast<mcl::ClientBufferStream*>(buffer_stream); | 114 | mcl::ClientBufferStream *bs = reinterpret_cast<mcl::ClientBufferStream*>(buffer_stream); |
651 | 116 | bs->release(nullptr, nullptr)->wait_for_all(); | 115 | make_synchronous_call(bs->get_connection(), |
652 | 116 | std::mem_fn(&mcl::ClientBufferStream::release), | ||
653 | 117 | bs, | ||
654 | 118 | &assign_result<MirBufferStream>, | ||
655 | 119 | static_cast<void*>(nullptr)); | ||
656 | 117 | delete bs; | 120 | delete bs; |
657 | 118 | } | 121 | } |
658 | 119 | 122 | ||
659 | @@ -148,9 +151,13 @@ | |||
660 | 148 | 151 | ||
661 | 149 | void mir_buffer_stream_swap_buffers_sync(MirBufferStream* buffer_stream) | 152 | void mir_buffer_stream_swap_buffers_sync(MirBufferStream* buffer_stream) |
662 | 150 | { | 153 | { |
666 | 151 | mir_wait_for(mir_buffer_stream_swap_buffers(buffer_stream, | 154 | mcl::ClientBufferStream *bs = reinterpret_cast<mcl::ClientBufferStream*>(buffer_stream); |
667 | 152 | reinterpret_cast<mir_buffer_stream_callback>(assign_result), | 155 | make_synchronous_call( |
668 | 153 | nullptr)); | 156 | bs->get_connection(), |
669 | 157 | &mir_buffer_stream_swap_buffers, | ||
670 | 158 | buffer_stream, | ||
671 | 159 | &assign_result<MirBufferStream>, | ||
672 | 160 | static_cast<void*>(nullptr)); | ||
673 | 154 | } | 161 | } |
674 | 155 | 162 | ||
675 | 156 | void mir_buffer_stream_get_graphics_region( | 163 | void mir_buffer_stream_get_graphics_region( |
676 | 157 | 164 | ||
677 | === modified file 'src/client/mir_connection.cpp' | |||
678 | --- src/client/mir_connection.cpp 2015-04-01 19:39:19 +0000 | |||
679 | +++ src/client/mir_connection.cpp 2015-05-14 07:50:26 +0000 | |||
680 | @@ -24,8 +24,10 @@ | |||
681 | 24 | #include "mir/client_platform.h" | 24 | #include "mir/client_platform.h" |
682 | 25 | #include "mir/client_platform_factory.h" | 25 | #include "mir/client_platform_factory.h" |
683 | 26 | #include "rpc/mir_basic_rpc_channel.h" | 26 | #include "rpc/mir_basic_rpc_channel.h" |
684 | 27 | #include "rpc/mir_protobuf_rpc_channel.h" | ||
685 | 27 | #include "mir/dispatch/dispatchable.h" | 28 | #include "mir/dispatch/dispatchable.h" |
687 | 28 | #include "mir/dispatch/simple_dispatch_thread.h" | 29 | #include "mir/dispatch/multiplexing_dispatchable.h" |
688 | 30 | #include "mir/dispatch/threaded_dispatcher.h" | ||
689 | 29 | #include "connection_configuration.h" | 31 | #include "connection_configuration.h" |
690 | 30 | #include "display_configuration.h" | 32 | #include "display_configuration.h" |
691 | 31 | #include "connection_surface_map.h" | 33 | #include "connection_surface_map.h" |
692 | @@ -33,6 +35,7 @@ | |||
693 | 33 | 35 | ||
694 | 34 | #include "mir/events/event_builders.h" | 36 | #include "mir/events/event_builders.h" |
695 | 35 | #include "mir/logging/logger.h" | 37 | #include "mir/logging/logger.h" |
696 | 38 | #include "mir/require.h" | ||
697 | 36 | 39 | ||
698 | 37 | #include <algorithm> | 40 | #include <algorithm> |
699 | 38 | #include <cstddef> | 41 | #include <cstddef> |
700 | @@ -42,6 +45,7 @@ | |||
701 | 42 | #include <boost/exception/diagnostic_information.hpp> | 45 | #include <boost/exception/diagnostic_information.hpp> |
702 | 43 | 46 | ||
703 | 44 | namespace mcl = mir::client; | 47 | namespace mcl = mir::client; |
704 | 48 | namespace mclr = mir::client::rpc; | ||
705 | 45 | namespace md = mir::dispatch; | 49 | namespace md = mir::dispatch; |
706 | 46 | namespace mircv = mir::input::receiver; | 50 | namespace mircv = mir::input::receiver; |
707 | 47 | namespace mev = mir::events; | 51 | namespace mev = mir::events; |
708 | @@ -99,10 +103,15 @@ | |||
709 | 99 | { | 103 | { |
710 | 100 | } | 104 | } |
711 | 101 | 105 | ||
712 | 106 | MirConnection::MirConnection(mir::client::ConnectionConfiguration& conf) : | ||
713 | 107 | MirConnection(conf, DispatchType::automatic) | ||
714 | 108 | { | ||
715 | 109 | } | ||
716 | 110 | |||
717 | 102 | MirConnection::MirConnection( | 111 | MirConnection::MirConnection( |
719 | 103 | mir::client::ConnectionConfiguration& conf) : | 112 | mir::client::ConnectionConfiguration& conf, DispatchType dispatch) : |
720 | 104 | deregisterer{this}, | 113 | deregisterer{this}, |
722 | 105 | channel(conf.the_rpc_channel()), | 114 | channel{conf.the_rpc_channel()}, |
723 | 106 | server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), | 115 | server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), |
724 | 107 | debug(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), | 116 | debug(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), |
725 | 108 | logger(conf.the_logger()), | 117 | logger(conf.the_logger()), |
726 | @@ -113,7 +122,11 @@ | |||
727 | 113 | lifecycle_control(conf.the_lifecycle_control()), | 122 | lifecycle_control(conf.the_lifecycle_control()), |
728 | 114 | surface_map(conf.the_surface_map()), | 123 | surface_map(conf.the_surface_map()), |
729 | 115 | event_handler_register(conf.the_event_handler_register()), | 124 | event_handler_register(conf.the_event_handler_register()), |
731 | 116 | eventloop{new md::SimpleDispatchThread{std::dynamic_pointer_cast<md::Dispatchable>(channel)}} | 125 | dispatcher{std::shared_ptr<md::MultiplexingDispatchable>(new md::MultiplexingDispatchable{channel})}, |
732 | 126 | eventloop{dispatch == DispatchType::automatic ? | ||
733 | 127 | new md::ThreadedDispatcher{"I/O loop", dispatcher} : | ||
734 | 128 | nullptr | ||
735 | 129 | } | ||
736 | 117 | { | 130 | { |
737 | 118 | connect_result.set_error("connect not called"); | 131 | connect_result.set_error("connect not called"); |
738 | 119 | { | 132 | { |
739 | @@ -325,6 +338,36 @@ | |||
740 | 325 | return &disconnect_wait_handle; | 338 | return &disconnect_wait_handle; |
741 | 326 | } | 339 | } |
742 | 327 | 340 | ||
743 | 341 | mir::Fd MirConnection::watch_fd() const | ||
744 | 342 | { | ||
745 | 343 | return eventloop ? mir::Fd{} : dispatcher->watch_fd(); | ||
746 | 344 | } | ||
747 | 345 | |||
748 | 346 | void MirConnection::dispatch() | ||
749 | 347 | { | ||
750 | 348 | mir::require(!eventloop); | ||
751 | 349 | |||
752 | 350 | dispatcher->dispatch(md::FdEvent::readable); | ||
753 | 351 | } | ||
754 | 352 | |||
755 | 353 | void MirConnection::add_dispatchee(std::shared_ptr<mir::dispatch::Dispatchable> const& dispatchee) | ||
756 | 354 | { | ||
757 | 355 | dispatcher->add_watch(dispatchee); | ||
758 | 356 | if (eventloop) | ||
759 | 357 | { | ||
760 | 358 | eventloop->add_thread(); | ||
761 | 359 | } | ||
762 | 360 | } | ||
763 | 361 | |||
764 | 362 | void MirConnection::remove_dispatchee(std::shared_ptr<mir::dispatch::Dispatchable> const& dispatchee) | ||
765 | 363 | { | ||
766 | 364 | dispatcher->remove_watch(dispatchee); | ||
767 | 365 | if (eventloop) | ||
768 | 366 | { | ||
769 | 367 | eventloop->remove_thread(); | ||
770 | 368 | } | ||
771 | 369 | } | ||
772 | 370 | |||
773 | 328 | void MirConnection::done_platform_operation( | 371 | void MirConnection::done_platform_operation( |
774 | 329 | mir_platform_operation_callback callback, void* context) | 372 | mir_platform_operation_callback callback, void* context) |
775 | 330 | { | 373 | { |
776 | @@ -568,3 +611,8 @@ | |||
777 | 568 | { | 611 | { |
778 | 569 | return logger; | 612 | return logger; |
779 | 570 | } | 613 | } |
780 | 614 | |||
781 | 615 | void MirConnection::process_next_request_first() | ||
782 | 616 | { | ||
783 | 617 | channel->process_next_request_first(); | ||
784 | 618 | } | ||
785 | 571 | 619 | ||
786 | === modified file 'src/client/mir_connection.h' | |||
787 | --- src/client/mir_connection.h 2015-03-31 02:35:42 +0000 | |||
788 | +++ src/client/mir_connection.h 2015-05-14 07:50:26 +0000 | |||
789 | @@ -26,6 +26,8 @@ | |||
790 | 26 | 26 | ||
791 | 27 | #include <mutex> | 27 | #include <mutex> |
792 | 28 | 28 | ||
793 | 29 | #include "rpc/mir_basic_rpc_channel.h" | ||
794 | 30 | |||
795 | 29 | #include "mir_protobuf.pb.h" | 31 | #include "mir_protobuf.pb.h" |
796 | 30 | 32 | ||
797 | 31 | #include "mir_toolkit/mir_client_library.h" | 33 | #include "mir_toolkit/mir_client_library.h" |
798 | @@ -36,6 +38,8 @@ | |||
799 | 36 | 38 | ||
800 | 37 | #include "mir_wait_handle.h" | 39 | #include "mir_wait_handle.h" |
801 | 38 | 40 | ||
802 | 41 | #include "mir/fd.h" | ||
803 | 42 | |||
804 | 39 | namespace mir | 43 | namespace mir |
805 | 40 | { | 44 | { |
806 | 41 | class SharedLibrary; | 45 | class SharedLibrary; |
807 | @@ -51,10 +55,6 @@ | |||
808 | 51 | class LifecycleControl; | 55 | class LifecycleControl; |
809 | 52 | class EventHandlerRegister; | 56 | class EventHandlerRegister; |
810 | 53 | 57 | ||
811 | 54 | namespace rpc | ||
812 | 55 | { | ||
813 | 56 | class MirBasicRpcChannel; | ||
814 | 57 | } | ||
815 | 58 | } | 58 | } |
816 | 59 | 59 | ||
817 | 60 | namespace input | 60 | namespace input |
818 | @@ -72,9 +72,17 @@ | |||
819 | 72 | 72 | ||
820 | 73 | namespace dispatch | 73 | namespace dispatch |
821 | 74 | { | 74 | { |
825 | 75 | class SimpleDispatchThread; | 75 | class ThreadedDispatcher; |
826 | 76 | } | 76 | class Dispatchable; |
827 | 77 | } | 77 | class MultiplexingDispatchable; |
828 | 78 | } | ||
829 | 79 | } | ||
830 | 80 | |||
831 | 81 | enum class DispatchType | ||
832 | 82 | { | ||
833 | 83 | automatic, | ||
834 | 84 | manual | ||
835 | 85 | }; | ||
836 | 78 | 86 | ||
837 | 79 | struct MirConnection : mir::client::ClientContext | 87 | struct MirConnection : mir::client::ClientContext |
838 | 80 | { | 88 | { |
839 | @@ -82,6 +90,7 @@ | |||
840 | 82 | MirConnection(std::string const& error_message); | 90 | MirConnection(std::string const& error_message); |
841 | 83 | 91 | ||
842 | 84 | MirConnection(mir::client::ConnectionConfiguration& conf); | 92 | MirConnection(mir::client::ConnectionConfiguration& conf); |
843 | 93 | MirConnection(mir::client::ConnectionConfiguration &conf, DispatchType dispatch); | ||
844 | 85 | ~MirConnection() noexcept; | 94 | ~MirConnection() noexcept; |
845 | 86 | 95 | ||
846 | 87 | MirConnection(MirConnection const &) = delete; | 96 | MirConnection(MirConnection const &) = delete; |
847 | @@ -107,6 +116,12 @@ | |||
848 | 107 | 116 | ||
849 | 108 | MirWaitHandle* disconnect(); | 117 | MirWaitHandle* disconnect(); |
850 | 109 | 118 | ||
851 | 119 | mir::Fd watch_fd() const; | ||
852 | 120 | void dispatch(); | ||
853 | 121 | |||
854 | 122 | void add_dispatchee(std::shared_ptr<mir::dispatch::Dispatchable> const& dispatchee); | ||
855 | 123 | void remove_dispatchee(std::shared_ptr<mir::dispatch::Dispatchable> const& dispatchee); | ||
856 | 124 | |||
857 | 110 | MirWaitHandle* platform_operation( | 125 | MirWaitHandle* platform_operation( |
858 | 111 | MirPlatformMessage const* request, | 126 | MirPlatformMessage const* request, |
859 | 112 | mir_platform_operation_callback callback, void* context); | 127 | mir_platform_operation_callback callback, void* context); |
860 | @@ -140,6 +155,7 @@ | |||
861 | 140 | mir::protobuf::DisplayServer& display_server(); | 155 | mir::protobuf::DisplayServer& display_server(); |
862 | 141 | std::shared_ptr<mir::logging::Logger> const& the_logger() const; | 156 | std::shared_ptr<mir::logging::Logger> const& the_logger() const; |
863 | 142 | 157 | ||
864 | 158 | void process_next_request_first(); | ||
865 | 143 | private: | 159 | private: |
866 | 144 | void populate_server_package(MirPlatformPackage& platform_package) override; | 160 | void populate_server_package(MirPlatformPackage& platform_package) override; |
867 | 145 | // MUST be first data member so it is destroyed last. | 161 | // MUST be first data member so it is destroyed last. |
868 | @@ -152,7 +168,7 @@ | |||
869 | 152 | 168 | ||
870 | 153 | std::mutex mutex; // Protects all members of *this (except release_wait_handles) | 169 | std::mutex mutex; // Protects all members of *this (except release_wait_handles) |
871 | 154 | 170 | ||
873 | 155 | std::shared_ptr<google::protobuf::RpcChannel> const channel; | 171 | std::shared_ptr<mir::client::rpc::MirBasicRpcChannel> const channel; |
874 | 156 | mir::protobuf::DisplayServer::Stub server; | 172 | mir::protobuf::DisplayServer::Stub server; |
875 | 157 | mir::protobuf::Debug::Stub debug; | 173 | mir::protobuf::Debug::Stub debug; |
876 | 158 | std::shared_ptr<mir::logging::Logger> const logger; | 174 | std::shared_ptr<mir::logging::Logger> const logger; |
877 | @@ -189,7 +205,9 @@ | |||
878 | 189 | 205 | ||
879 | 190 | std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register; | 206 | std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register; |
880 | 191 | 207 | ||
882 | 192 | std::unique_ptr<mir::dispatch::SimpleDispatchThread> const eventloop; | 208 | std::shared_ptr<mir::dispatch::MultiplexingDispatchable> const dispatcher; |
883 | 209 | std::unique_ptr<mir::dispatch::ThreadedDispatcher> const eventloop; | ||
884 | 210 | |||
885 | 193 | 211 | ||
886 | 194 | std::shared_ptr<mir::client::ClientBufferStreamFactory> buffer_stream_factory; | 212 | std::shared_ptr<mir::client::ClientBufferStreamFactory> buffer_stream_factory; |
887 | 195 | 213 | ||
888 | 196 | 214 | ||
889 | === modified file 'src/client/mir_connection_api.cpp' | |||
890 | --- src/client/mir_connection_api.cpp 2015-03-31 02:35:42 +0000 | |||
891 | +++ src/client/mir_connection_api.cpp 2015-05-14 07:50:26 +0000 | |||
892 | @@ -39,6 +39,7 @@ | |||
893 | 39 | #include <unordered_set> | 39 | #include <unordered_set> |
894 | 40 | #include <cstddef> | 40 | #include <cstddef> |
895 | 41 | #include <cstring> | 41 | #include <cstring> |
896 | 42 | #include <poll.h> | ||
897 | 42 | 43 | ||
898 | 43 | namespace mcl = mir::client; | 44 | namespace mcl = mir::client; |
899 | 44 | 45 | ||
900 | @@ -98,7 +99,20 @@ | |||
901 | 98 | try | 99 | try |
902 | 99 | { | 100 | { |
903 | 100 | auto wait_handle = connection->disconnect(); | 101 | auto wait_handle = connection->disconnect(); |
905 | 101 | wait_handle->wait_for_all(); | 102 | if (connection->watch_fd() != mir::Fd::invalid) |
906 | 103 | { | ||
907 | 104 | pollfd fd; | ||
908 | 105 | fd.fd = connection->watch_fd(); | ||
909 | 106 | fd.events = POLLIN; | ||
910 | 107 | while(!wait_handle->ready() && (poll(&fd, 1, -1) > 0)) | ||
911 | 108 | { | ||
912 | 109 | connection->dispatch(); | ||
913 | 110 | } | ||
914 | 111 | } | ||
915 | 112 | else | ||
916 | 113 | { | ||
917 | 114 | wait_handle->wait_for_all(); | ||
918 | 115 | } | ||
919 | 102 | } | 116 | } |
920 | 103 | catch (std::exception const& ex) | 117 | catch (std::exception const& ex) |
921 | 104 | { | 118 | { |
922 | @@ -165,6 +179,41 @@ | |||
923 | 165 | return conn; | 179 | return conn; |
924 | 166 | } | 180 | } |
925 | 167 | 181 | ||
926 | 182 | MirConnection* mir_connect_with_manual_dispatch( | ||
927 | 183 | char const* server, | ||
928 | 184 | char const* app_name, | ||
929 | 185 | mir_connected_callback callback, | ||
930 | 186 | void* context) | ||
931 | 187 | { | ||
932 | 188 | try | ||
933 | 189 | { | ||
934 | 190 | std::string sock; | ||
935 | 191 | if (server) | ||
936 | 192 | sock = server; | ||
937 | 193 | else | ||
938 | 194 | { | ||
939 | 195 | auto socket_env = getenv("MIR_SOCKET"); | ||
940 | 196 | if (socket_env) | ||
941 | 197 | sock = socket_env; | ||
942 | 198 | else | ||
943 | 199 | sock = mir::default_server_socket; | ||
944 | 200 | } | ||
945 | 201 | |||
946 | 202 | mcl::DefaultConnectionConfiguration conf{sock}; | ||
947 | 203 | |||
948 | 204 | std::unique_ptr<MirConnection> connection{new MirConnection(conf, DispatchType::manual)}; | ||
949 | 205 | connection->connect(app_name, callback, context); | ||
950 | 206 | return connection.release(); | ||
951 | 207 | } | ||
952 | 208 | catch (std::exception const& x) | ||
953 | 209 | { | ||
954 | 210 | MirConnection* error_connection = new MirConnection(x.what()); | ||
955 | 211 | mcl::ErrorConnections::instance().insert(error_connection); | ||
956 | 212 | callback(error_connection, context); | ||
957 | 213 | return error_connection; | ||
958 | 214 | } | ||
959 | 215 | } | ||
960 | 216 | |||
961 | 168 | bool mir_connection_is_valid(MirConnection* connection) | 217 | bool mir_connection_is_valid(MirConnection* connection) |
962 | 169 | { | 218 | { |
963 | 170 | return MirConnection::is_valid(connection); | 219 | return MirConnection::is_valid(connection); |
964 | @@ -187,6 +236,16 @@ | |||
965 | 187 | } | 236 | } |
966 | 188 | } | 237 | } |
967 | 189 | 238 | ||
968 | 239 | int mir_connection_get_event_fd(MirConnection* connection) | ||
969 | 240 | { | ||
970 | 241 | return connection->watch_fd(); | ||
971 | 242 | } | ||
972 | 243 | |||
973 | 244 | void mir_connection_dispatch(MirConnection* connection) | ||
974 | 245 | { | ||
975 | 246 | connection->dispatch(); | ||
976 | 247 | } | ||
977 | 248 | |||
978 | 190 | void mir_connection_get_platform( | 249 | void mir_connection_get_platform( |
979 | 191 | MirConnection* connection, | 250 | MirConnection* connection, |
980 | 192 | MirPlatformPackage* platform_package) | 251 | MirPlatformPackage* platform_package) |
981 | 193 | 252 | ||
982 | === modified file 'src/client/mir_prompt_session_api.cpp' | |||
983 | --- src/client/mir_prompt_session_api.cpp 2015-03-31 02:35:42 +0000 | |||
984 | +++ src/client/mir_prompt_session_api.cpp 2015-05-14 07:50:26 +0000 | |||
985 | @@ -24,6 +24,8 @@ | |||
986 | 24 | 24 | ||
987 | 25 | #include "mir/uncaught.h" | 25 | #include "mir/uncaught.h" |
988 | 26 | 26 | ||
989 | 27 | #include "synchronous_helper.h" | ||
990 | 28 | |||
991 | 27 | #include <stdexcept> | 29 | #include <stdexcept> |
992 | 28 | #include <boost/throw_exception.hpp> | 30 | #include <boost/throw_exception.hpp> |
993 | 29 | 31 | ||
994 | @@ -44,9 +46,14 @@ | |||
995 | 44 | if (state_change_callback) | 46 | if (state_change_callback) |
996 | 45 | prompt_session->register_prompt_session_state_change_callback(state_change_callback, context); | 47 | prompt_session->register_prompt_session_state_change_callback(state_change_callback, context); |
997 | 46 | 48 | ||
1001 | 47 | mir_wait_for(prompt_session->start(application_pid, | 49 | make_synchronous_call( |
1002 | 48 | null_callback, | 50 | connection, |
1003 | 49 | nullptr)); | 51 | std::mem_fn(&MirPromptSession::start), |
1004 | 52 | prompt_session, | ||
1005 | 53 | application_pid, | ||
1006 | 54 | &assign_result<MirPromptSession>, | ||
1007 | 55 | static_cast<void*>(nullptr)); | ||
1008 | 56 | |||
1009 | 50 | return prompt_session; | 57 | return prompt_session; |
1010 | 51 | } | 58 | } |
1011 | 52 | catch (std::exception const& ex) | 59 | catch (std::exception const& ex) |
1012 | 53 | 60 | ||
1013 | === modified file 'src/client/mir_screencast.cpp' | |||
1014 | --- src/client/mir_screencast.cpp 2015-04-25 11:38:31 +0000 | |||
1015 | +++ src/client/mir_screencast.cpp 2015-05-14 07:50:26 +0000 | |||
1016 | @@ -30,13 +30,15 @@ | |||
1017 | 30 | namespace geom = mir::geometry; | 30 | namespace geom = mir::geometry; |
1018 | 31 | 31 | ||
1019 | 32 | MirScreencast::MirScreencast( | 32 | MirScreencast::MirScreencast( |
1020 | 33 | MirConnection* allocating_connection, | ||
1021 | 33 | geom::Rectangle const& region, | 34 | geom::Rectangle const& region, |
1022 | 34 | geom::Size const& size, | 35 | geom::Size const& size, |
1023 | 35 | MirPixelFormat pixel_format, | 36 | MirPixelFormat pixel_format, |
1024 | 36 | mir::protobuf::DisplayServer& server, | 37 | mir::protobuf::DisplayServer& server, |
1025 | 37 | std::shared_ptr<mcl::ClientBufferStreamFactory> const& buffer_stream_factory, | 38 | std::shared_ptr<mcl::ClientBufferStreamFactory> const& buffer_stream_factory, |
1026 | 38 | mir_screencast_callback callback, void* context) | 39 | mir_screencast_callback callback, void* context) |
1028 | 39 | : server(server), | 40 | : allocating_connection{allocating_connection}, |
1029 | 41 | server(server), | ||
1030 | 40 | output_size{size}, | 42 | output_size{size}, |
1031 | 41 | buffer_stream_factory{buffer_stream_factory} | 43 | buffer_stream_factory{buffer_stream_factory} |
1032 | 42 | { | 44 | { |
1033 | @@ -102,12 +104,16 @@ | |||
1034 | 102 | } | 104 | } |
1035 | 103 | 105 | ||
1036 | 104 | void MirScreencast::screencast_created( | 106 | void MirScreencast::screencast_created( |
1038 | 105 | mir_screencast_callback callback, void* context) | 107 | mir_screencast_callback callback, |
1039 | 108 | void* context) | ||
1040 | 106 | { | 109 | { |
1041 | 107 | if (!protobuf_screencast.has_error()) | 110 | if (!protobuf_screencast.has_error()) |
1042 | 108 | { | 111 | { |
1045 | 109 | buffer_stream = buffer_stream_factory->make_consumer_stream(server, | 112 | buffer_stream = buffer_stream_factory->make_consumer_stream( |
1046 | 110 | protobuf_screencast.buffer_stream(), "MirScreencast"); | 113 | allocating_connection, |
1047 | 114 | server, | ||
1048 | 115 | protobuf_screencast.buffer_stream(), | ||
1049 | 116 | "MirScreencast"); | ||
1050 | 111 | } | 117 | } |
1051 | 112 | 118 | ||
1052 | 113 | callback(this, context); | 119 | callback(this, context); |
1053 | @@ -125,3 +131,8 @@ | |||
1054 | 125 | { | 131 | { |
1055 | 126 | return buffer_stream.get(); | 132 | return buffer_stream.get(); |
1056 | 127 | } | 133 | } |
1057 | 134 | |||
1058 | 135 | MirConnection* MirScreencast::get_connection() | ||
1059 | 136 | { | ||
1060 | 137 | return allocating_connection; | ||
1061 | 138 | } | ||
1062 | 128 | 139 | ||
1063 | === modified file 'src/client/mir_screencast.h' | |||
1064 | --- src/client/mir_screencast.h 2015-03-31 02:35:42 +0000 | |||
1065 | +++ src/client/mir_screencast.h 2015-05-14 07:50:26 +0000 | |||
1066 | @@ -41,6 +41,7 @@ | |||
1067 | 41 | { | 41 | { |
1068 | 42 | public: | 42 | public: |
1069 | 43 | MirScreencast( | 43 | MirScreencast( |
1070 | 44 | MirConnection* allocating_connection, | ||
1071 | 44 | mir::geometry::Rectangle const& region, | 45 | mir::geometry::Rectangle const& region, |
1072 | 45 | mir::geometry::Size const& size, | 46 | mir::geometry::Size const& size, |
1073 | 46 | MirPixelFormat pixel_format, | 47 | MirPixelFormat pixel_format, |
1074 | @@ -60,12 +61,14 @@ | |||
1075 | 60 | 61 | ||
1076 | 61 | mir::client::ClientBufferStream* get_buffer_stream(); | 62 | mir::client::ClientBufferStream* get_buffer_stream(); |
1077 | 62 | 63 | ||
1078 | 64 | MirConnection* get_connection(); | ||
1079 | 63 | private: | 65 | private: |
1080 | 64 | void screencast_created( | 66 | void screencast_created( |
1081 | 65 | mir_screencast_callback callback, void* context); | 67 | mir_screencast_callback callback, void* context); |
1082 | 66 | void released( | 68 | void released( |
1083 | 67 | mir_screencast_callback callback, void* context); | 69 | mir_screencast_callback callback, void* context); |
1084 | 68 | 70 | ||
1085 | 71 | MirConnection* const allocating_connection; | ||
1086 | 69 | mir::protobuf::DisplayServer& server; | 72 | mir::protobuf::DisplayServer& server; |
1087 | 70 | mir::geometry::Size const output_size; | 73 | mir::geometry::Size const output_size; |
1088 | 71 | std::shared_ptr<mir::client::ClientBufferStreamFactory> const buffer_stream_factory; | 74 | std::shared_ptr<mir::client::ClientBufferStreamFactory> const buffer_stream_factory; |
1089 | 72 | 75 | ||
1090 | === modified file 'src/client/mir_screencast_api.cpp' | |||
1091 | --- src/client/mir_screencast_api.cpp 2015-03-31 02:35:42 +0000 | |||
1092 | +++ src/client/mir_screencast_api.cpp 2015-05-14 07:50:26 +0000 | |||
1093 | @@ -25,6 +25,8 @@ | |||
1094 | 25 | 25 | ||
1095 | 26 | #include "mir/uncaught.h" | 26 | #include "mir/uncaught.h" |
1096 | 27 | 27 | ||
1097 | 28 | #include "synchronous_helper.h" | ||
1098 | 29 | |||
1099 | 28 | #include <stdexcept> | 30 | #include <stdexcept> |
1100 | 29 | #include <boost/throw_exception.hpp> | 31 | #include <boost/throw_exception.hpp> |
1101 | 30 | 32 | ||
1102 | @@ -56,6 +58,7 @@ | |||
1103 | 56 | 58 | ||
1104 | 57 | std::unique_ptr<MirScreencast> screencast_uptr{ | 59 | std::unique_ptr<MirScreencast> screencast_uptr{ |
1105 | 58 | new MirScreencast{ | 60 | new MirScreencast{ |
1106 | 61 | connection, | ||
1107 | 59 | region, | 62 | region, |
1108 | 60 | size, | 63 | size, |
1109 | 61 | parameters->pixel_format, | 64 | parameters->pixel_format, |
1110 | @@ -63,7 +66,18 @@ | |||
1111 | 63 | connection->get_client_buffer_stream_factory(), | 66 | connection->get_client_buffer_stream_factory(), |
1112 | 64 | null_callback, nullptr}}; | 67 | null_callback, nullptr}}; |
1113 | 65 | 68 | ||
1115 | 66 | screencast_uptr->creation_wait_handle()->wait_for_all(); | 69 | |
1116 | 70 | if (connection->watch_fd() != mir::Fd::invalid) | ||
1117 | 71 | { | ||
1118 | 72 | dispatch_connection_until(connection, [&screencast_uptr]() | ||
1119 | 73 | { | ||
1120 | 74 | return screencast_uptr->creation_wait_handle()->ready(); | ||
1121 | 75 | }); | ||
1122 | 76 | } | ||
1123 | 77 | else | ||
1124 | 78 | { | ||
1125 | 79 | screencast_uptr->creation_wait_handle()->wait_for_all(); | ||
1126 | 80 | } | ||
1127 | 67 | 81 | ||
1128 | 68 | if (screencast_uptr->valid()) | 82 | if (screencast_uptr->valid()) |
1129 | 69 | { | 83 | { |
1130 | @@ -82,7 +96,11 @@ | |||
1131 | 82 | 96 | ||
1132 | 83 | void mir_screencast_release_sync(MirScreencast* screencast) | 97 | void mir_screencast_release_sync(MirScreencast* screencast) |
1133 | 84 | { | 98 | { |
1135 | 85 | screencast->release(null_callback, nullptr)->wait_for_all(); | 99 | make_synchronous_call(screencast->get_connection(), |
1136 | 100 | std::mem_fn(&MirScreencast::release), | ||
1137 | 101 | screencast, | ||
1138 | 102 | &assign_result<MirScreencast>, | ||
1139 | 103 | static_cast<void*>(nullptr)); | ||
1140 | 86 | delete screencast; | 104 | delete screencast; |
1141 | 87 | } | 105 | } |
1142 | 88 | 106 | ||
1143 | 89 | 107 | ||
1144 | === modified file 'src/client/mir_surface.cpp' | |||
1145 | --- src/client/mir_surface.cpp 2015-04-28 10:30:44 +0000 | |||
1146 | +++ src/client/mir_surface.cpp 2015-05-14 07:50:26 +0000 | |||
1147 | @@ -23,7 +23,7 @@ | |||
1148 | 23 | #include "cursor_configuration.h" | 23 | #include "cursor_configuration.h" |
1149 | 24 | #include "client_buffer_stream_factory.h" | 24 | #include "client_buffer_stream_factory.h" |
1150 | 25 | #include "mir_connection.h" | 25 | #include "mir_connection.h" |
1152 | 26 | #include "mir/dispatch/simple_dispatch_thread.h" | 26 | #include "mir/dispatch/threaded_dispatcher.h" |
1153 | 27 | #include "mir/input/input_platform.h" | 27 | #include "mir/input/input_platform.h" |
1154 | 28 | #include "mir/input/xkb_mapper.h" | 28 | #include "mir/input/xkb_mapper.h" |
1155 | 29 | 29 | ||
1156 | @@ -179,7 +179,10 @@ | |||
1157 | 179 | 179 | ||
1158 | 180 | std::lock_guard<decltype(mutex)> lock(mutex); | 180 | std::lock_guard<decltype(mutex)> lock(mutex); |
1159 | 181 | 181 | ||
1161 | 182 | input_thread.reset(); | 182 | if (input_dispatcher) |
1162 | 183 | { | ||
1163 | 184 | connection->remove_dispatchee(input_dispatcher); | ||
1164 | 185 | } | ||
1165 | 183 | 186 | ||
1166 | 184 | for (auto i = 0, end = surface.fd_size(); i != end; ++i) | 187 | for (auto i = 0, end = surface.fd_size(); i != end; ++i) |
1167 | 185 | close(surface.fd(i)); | 188 | close(surface.fd(i)); |
1168 | @@ -220,6 +223,11 @@ | |||
1169 | 220 | return false; | 223 | return false; |
1170 | 221 | } | 224 | } |
1171 | 222 | 225 | ||
1172 | 226 | MirConnection* MirSurface::get_connection() const | ||
1173 | 227 | { | ||
1174 | 228 | return connection; | ||
1175 | 229 | } | ||
1176 | 230 | |||
1177 | 223 | MirWaitHandle* MirSurface::get_create_wait_handle() | 231 | MirWaitHandle* MirSurface::get_create_wait_handle() |
1178 | 224 | { | 232 | { |
1179 | 225 | return &create_wait_handle; | 233 | return &create_wait_handle; |
1180 | @@ -252,7 +260,7 @@ | |||
1181 | 252 | std::lock_guard<decltype(mutex)> lock(mutex); | 260 | std::lock_guard<decltype(mutex)> lock(mutex); |
1182 | 253 | 261 | ||
1183 | 254 | buffer_stream = buffer_stream_factory-> | 262 | buffer_stream = buffer_stream_factory-> |
1185 | 255 | make_producer_stream(*server, surface.buffer_stream(), name); | 263 | make_producer_stream(connection, *server, surface.buffer_stream(), name); |
1186 | 256 | 264 | ||
1187 | 257 | for(int i = 0; i < surface.attributes_size(); i++) | 265 | for(int i = 0; i < surface.attributes_size(); i++) |
1188 | 258 | { | 266 | { |
1189 | @@ -458,7 +466,11 @@ | |||
1190 | 458 | { | 466 | { |
1191 | 459 | std::lock_guard<decltype(mutex)> lock(mutex); | 467 | std::lock_guard<decltype(mutex)> lock(mutex); |
1192 | 460 | 468 | ||
1194 | 461 | input_thread.reset(); | 469 | if (input_dispatcher) |
1195 | 470 | { | ||
1196 | 471 | connection->remove_dispatchee(input_dispatcher); | ||
1197 | 472 | input_dispatcher.reset(); | ||
1198 | 473 | } | ||
1199 | 462 | 474 | ||
1200 | 463 | if (callback) | 475 | if (callback) |
1201 | 464 | { | 476 | { |
1202 | @@ -468,10 +480,10 @@ | |||
1203 | 468 | 480 | ||
1204 | 469 | if (surface.fd_size() > 0 && handle_event_callback) | 481 | if (surface.fd_size() > 0 && handle_event_callback) |
1205 | 470 | { | 482 | { |
1210 | 471 | auto input_dispatcher = input_platform->create_input_receiver(surface.fd(0), | 483 | input_dispatcher = input_platform->create_input_receiver(surface.fd(0), |
1211 | 472 | keymapper, | 484 | keymapper, |
1212 | 473 | handle_event_callback); | 485 | handle_event_callback); |
1213 | 474 | input_thread = std::make_shared<md::SimpleDispatchThread>(input_dispatcher); | 486 | connection->add_dispatchee(input_dispatcher); |
1214 | 475 | } | 487 | } |
1215 | 476 | } | 488 | } |
1216 | 477 | } | 489 | } |
1217 | 478 | 490 | ||
1218 | === modified file 'src/client/mir_surface.h' | |||
1219 | --- src/client/mir_surface.h 2015-04-28 08:59:22 +0000 | |||
1220 | +++ src/client/mir_surface.h 2015-05-14 07:50:26 +0000 | |||
1221 | @@ -39,7 +39,7 @@ | |||
1222 | 39 | { | 39 | { |
1223 | 40 | namespace dispatch | 40 | namespace dispatch |
1224 | 41 | { | 41 | { |
1226 | 42 | class SimpleDispatchThread; | 42 | class Dispatchable; |
1227 | 43 | } | 43 | } |
1228 | 44 | namespace input | 44 | namespace input |
1229 | 45 | { | 45 | { |
1230 | @@ -153,6 +153,8 @@ | |||
1231 | 153 | MirWaitHandle* modify(MirSurfaceSpec const& changes); | 153 | MirWaitHandle* modify(MirSurfaceSpec const& changes); |
1232 | 154 | 154 | ||
1233 | 155 | static bool is_valid(MirSurface* query); | 155 | static bool is_valid(MirSurface* query); |
1234 | 156 | |||
1235 | 157 | MirConnection* get_connection() const; | ||
1236 | 156 | private: | 158 | private: |
1237 | 157 | mutable std::mutex mutex; // Protects all members of *this | 159 | mutable std::mutex mutex; // Protects all members of *this |
1238 | 158 | 160 | ||
1239 | @@ -191,7 +193,7 @@ | |||
1240 | 191 | MirOrientation orientation = mir_orientation_normal; | 193 | MirOrientation orientation = mir_orientation_normal; |
1241 | 192 | 194 | ||
1242 | 193 | std::function<void(MirEvent const*)> handle_event_callback; | 195 | std::function<void(MirEvent const*)> handle_event_callback; |
1244 | 194 | std::shared_ptr<mir::dispatch::SimpleDispatchThread> input_thread; | 196 | std::shared_ptr<mir::dispatch::Dispatchable> input_dispatcher; |
1245 | 195 | }; | 197 | }; |
1246 | 196 | 198 | ||
1247 | 197 | #endif /* MIR_CLIENT_PRIVATE_MIR_WAIT_HANDLE_H_ */ | 199 | #endif /* MIR_CLIENT_PRIVATE_MIR_WAIT_HANDLE_H_ */ |
1248 | 198 | 200 | ||
1249 | === modified file 'src/client/mir_surface_api.cpp' | |||
1250 | --- src/client/mir_surface_api.cpp 2015-04-30 12:27:33 +0000 | |||
1251 | +++ src/client/mir_surface_api.cpp 2015-05-14 07:50:26 +0000 | |||
1252 | @@ -26,24 +26,13 @@ | |||
1253 | 26 | #include "mir_surface.h" | 26 | #include "mir_surface.h" |
1254 | 27 | #include "error_connections.h" | 27 | #include "error_connections.h" |
1255 | 28 | #include "mir/uncaught.h" | 28 | #include "mir/uncaught.h" |
1256 | 29 | #include "synchronous_helper.h" | ||
1257 | 29 | 30 | ||
1258 | 30 | #include <boost/exception/diagnostic_information.hpp> | 31 | #include <boost/exception/diagnostic_information.hpp> |
1259 | 31 | #include <functional> | 32 | #include <functional> |
1260 | 32 | 33 | ||
1261 | 33 | namespace mcl = mir::client; | 34 | namespace mcl = mir::client; |
1262 | 34 | 35 | ||
1263 | 35 | namespace | ||
1264 | 36 | { | ||
1265 | 37 | |||
1266 | 38 | // assign_result is compatible with all 2-parameter callbacks | ||
1267 | 39 | void assign_result(void* result, void** context) | ||
1268 | 40 | { | ||
1269 | 41 | if (context) | ||
1270 | 42 | *context = result; | ||
1271 | 43 | } | ||
1272 | 44 | |||
1273 | 45 | } | ||
1274 | 46 | |||
1275 | 47 | MirSurfaceSpec* mir_connection_create_spec_for_normal_surface(MirConnection* connection, | 36 | MirSurfaceSpec* mir_connection_create_spec_for_normal_surface(MirConnection* connection, |
1276 | 48 | int width, int height, | 37 | int width, int height, |
1277 | 49 | MirPixelFormat format) | 38 | MirPixelFormat format) |
1278 | @@ -128,9 +117,12 @@ | |||
1279 | 128 | { | 117 | { |
1280 | 129 | MirSurface* surface = nullptr; | 118 | MirSurface* surface = nullptr; |
1281 | 130 | 119 | ||
1285 | 131 | mir_wait_for(mir_surface_create(requested_specification, | 120 | make_synchronous_call( |
1286 | 132 | reinterpret_cast<mir_surface_callback>(assign_result), | 121 | requested_specification->connection, |
1287 | 133 | &surface)); | 122 | &mir_surface_create, |
1288 | 123 | requested_specification, | ||
1289 | 124 | &assign_result<MirSurface>, | ||
1290 | 125 | &surface); | ||
1291 | 134 | 126 | ||
1292 | 135 | return surface; | 127 | return surface; |
1293 | 136 | } | 128 | } |
1294 | @@ -364,9 +356,11 @@ | |||
1295 | 364 | 356 | ||
1296 | 365 | void mir_surface_release_sync(MirSurface* surface) | 357 | void mir_surface_release_sync(MirSurface* surface) |
1297 | 366 | { | 358 | { |
1301 | 367 | mir_wait_for(mir_surface_release(surface, | 359 | make_synchronous_call(surface->get_connection(), |
1302 | 368 | reinterpret_cast<mir_surface_callback>(assign_result), | 360 | mir_surface_release, |
1303 | 369 | nullptr)); | 361 | surface, |
1304 | 362 | &assign_result<MirSurface>, | ||
1305 | 363 | static_cast<void*>(nullptr)); | ||
1306 | 370 | } | 364 | } |
1307 | 371 | 365 | ||
1308 | 372 | int mir_surface_get_id(MirSurface* /*surface*/) | 366 | int mir_surface_get_id(MirSurface* /*surface*/) |
1309 | 373 | 367 | ||
1310 | === modified file 'src/client/mir_wait_api.cpp' | |||
1311 | --- src/client/mir_wait_api.cpp 2014-03-31 14:36:08 +0000 | |||
1312 | +++ src/client/mir_wait_api.cpp 2015-05-14 07:50:26 +0000 | |||
1313 | @@ -30,3 +30,12 @@ | |||
1314 | 30 | if (wait_handle) | 30 | if (wait_handle) |
1315 | 31 | wait_handle->wait_for_one(); | 31 | wait_handle->wait_for_one(); |
1316 | 32 | } | 32 | } |
1317 | 33 | |||
1318 | 34 | bool mir_wait_handle_ready(MirWaitHandle* wait_handle) | ||
1319 | 35 | { | ||
1320 | 36 | if (wait_handle) | ||
1321 | 37 | { | ||
1322 | 38 | return wait_handle->ready(); | ||
1323 | 39 | } | ||
1324 | 40 | return true; | ||
1325 | 41 | } | ||
1326 | 33 | 42 | ||
1327 | === modified file 'src/client/mir_wait_handle.cpp' | |||
1328 | --- src/client/mir_wait_handle.cpp 2015-01-21 07:34:50 +0000 | |||
1329 | +++ src/client/mir_wait_handle.cpp 2015-05-14 07:50:26 +0000 | |||
1330 | @@ -74,3 +74,9 @@ | |||
1331 | 74 | --expecting; | 74 | --expecting; |
1332 | 75 | } | 75 | } |
1333 | 76 | 76 | ||
1334 | 77 | bool MirWaitHandle::ready() | ||
1335 | 78 | { | ||
1336 | 79 | std::lock_guard<std::mutex> lock{guard}; | ||
1337 | 80 | |||
1338 | 81 | return received == expecting; | ||
1339 | 82 | } | ||
1340 | 77 | 83 | ||
1341 | === modified file 'src/client/mir_wait_handle.h' | |||
1342 | --- src/client/mir_wait_handle.h 2013-10-03 03:44:08 +0000 | |||
1343 | +++ src/client/mir_wait_handle.h 2015-05-14 07:50:26 +0000 | |||
1344 | @@ -39,6 +39,7 @@ | |||
1345 | 39 | void wait_for_all(); | 39 | void wait_for_all(); |
1346 | 40 | void wait_for_one(); | 40 | void wait_for_one(); |
1347 | 41 | void wait_for_pending(std::chrono::milliseconds limit); | 41 | void wait_for_pending(std::chrono::milliseconds limit); |
1348 | 42 | bool ready(); | ||
1349 | 42 | 43 | ||
1350 | 43 | private: | 44 | private: |
1351 | 44 | std::mutex guard; | 45 | std::mutex guard; |
1352 | 45 | 46 | ||
1353 | === modified file 'src/client/rpc/make_rpc_channel.h' | |||
1354 | --- src/client/rpc/make_rpc_channel.h 2015-01-21 07:34:50 +0000 | |||
1355 | +++ src/client/rpc/make_rpc_channel.h 2015-05-14 07:50:26 +0000 | |||
1356 | @@ -20,8 +20,6 @@ | |||
1357 | 20 | 20 | ||
1358 | 21 | #include <memory> | 21 | #include <memory> |
1359 | 22 | 22 | ||
1360 | 23 | namespace google { namespace protobuf { class RpcChannel; } } | ||
1361 | 24 | |||
1362 | 25 | namespace mir | 23 | namespace mir |
1363 | 26 | { | 24 | { |
1364 | 27 | namespace client | 25 | namespace client |
1365 | @@ -34,8 +32,9 @@ | |||
1366 | 34 | namespace rpc | 32 | namespace rpc |
1367 | 35 | { | 33 | { |
1368 | 36 | class RpcReport; | 34 | class RpcReport; |
1369 | 35 | class MirBasicRpcChannel; | ||
1370 | 37 | 36 | ||
1372 | 38 | std::shared_ptr<google::protobuf::RpcChannel> | 37 | std::shared_ptr<MirBasicRpcChannel> |
1373 | 39 | make_rpc_channel(std::string const& name, | 38 | make_rpc_channel(std::string const& name, |
1374 | 40 | std::shared_ptr<SurfaceMap> const& map, | 39 | std::shared_ptr<SurfaceMap> const& map, |
1375 | 41 | std::shared_ptr<DisplayConfiguration> const& disp_conf, | 40 | std::shared_ptr<DisplayConfiguration> const& disp_conf, |
1376 | 42 | 41 | ||
1377 | === modified file 'src/client/rpc/make_socket_rpc_channel.cpp' | |||
1378 | --- src/client/rpc/make_socket_rpc_channel.cpp 2015-03-31 02:35:42 +0000 | |||
1379 | +++ src/client/rpc/make_socket_rpc_channel.cpp 2015-05-14 07:50:26 +0000 | |||
1380 | @@ -40,7 +40,7 @@ | |||
1381 | 40 | } const fd_prefix("fd://"); | 40 | } const fd_prefix("fd://"); |
1382 | 41 | } | 41 | } |
1383 | 42 | 42 | ||
1385 | 43 | std::shared_ptr<google::protobuf::RpcChannel> | 43 | std::shared_ptr<mclr::MirBasicRpcChannel> |
1386 | 44 | mclr::make_rpc_channel(std::string const& name, | 44 | mclr::make_rpc_channel(std::string const& name, |
1387 | 45 | std::shared_ptr<mcl::SurfaceMap> const& map, | 45 | std::shared_ptr<mcl::SurfaceMap> const& map, |
1388 | 46 | std::shared_ptr<mcl::DisplayConfiguration> const& disp_conf, | 46 | std::shared_ptr<mcl::DisplayConfiguration> const& disp_conf, |
1389 | 47 | 47 | ||
1390 | === modified file 'src/client/rpc/mir_basic_rpc_channel.cpp' | |||
1391 | --- src/client/rpc/mir_basic_rpc_channel.cpp 2015-01-21 07:34:50 +0000 | |||
1392 | +++ src/client/rpc/mir_basic_rpc_channel.cpp 2015-05-14 07:50:26 +0000 | |||
1393 | @@ -38,13 +38,19 @@ | |||
1394 | 38 | void mclrd::PendingCallCache::save_completion_details( | 38 | void mclrd::PendingCallCache::save_completion_details( |
1395 | 39 | mir::protobuf::wire::Invocation const& invoke, | 39 | mir::protobuf::wire::Invocation const& invoke, |
1396 | 40 | google::protobuf::Message* response, | 40 | google::protobuf::Message* response, |
1398 | 41 | std::shared_ptr<google::protobuf::Closure> const& complete) | 41 | google::protobuf::Closure* complete) |
1399 | 42 | { | 42 | { |
1400 | 43 | std::unique_lock<std::mutex> lock(mutex); | 43 | std::unique_lock<std::mutex> lock(mutex); |
1401 | 44 | 44 | ||
1402 | 45 | pending_calls[invoke.id()] = PendingCall(response, complete); | 45 | pending_calls[invoke.id()] = PendingCall(response, complete); |
1403 | 46 | } | 46 | } |
1404 | 47 | 47 | ||
1405 | 48 | google::protobuf::Message* mclrd::PendingCallCache::message_for_result(mir::protobuf::wire::Result& result) | ||
1406 | 49 | { | ||
1407 | 50 | std::unique_lock<std::mutex> lock(mutex); | ||
1408 | 51 | return pending_calls.at(result.id()).response; | ||
1409 | 52 | } | ||
1410 | 53 | |||
1411 | 48 | void mclrd::PendingCallCache::complete_response(mir::protobuf::wire::Result& result) | 54 | void mclrd::PendingCallCache::complete_response(mir::protobuf::wire::Result& result) |
1412 | 49 | { | 55 | { |
1413 | 50 | PendingCall completion; | 56 | PendingCall completion; |
1414 | @@ -66,7 +72,6 @@ | |||
1415 | 66 | else | 72 | else |
1416 | 67 | { | 73 | { |
1417 | 68 | rpc_report->complete_response(result); | 74 | rpc_report->complete_response(result); |
1418 | 69 | completion.response->ParseFromString(result.response()); | ||
1419 | 70 | completion.complete->Run(); | 75 | completion.complete->Run(); |
1420 | 71 | } | 76 | } |
1421 | 72 | } | 77 | } |
1422 | 73 | 78 | ||
1423 | === modified file 'src/client/rpc/mir_basic_rpc_channel.h' | |||
1424 | --- src/client/rpc/mir_basic_rpc_channel.h 2015-01-21 07:34:50 +0000 | |||
1425 | +++ src/client/rpc/mir_basic_rpc_channel.h 2015-05-14 07:50:26 +0000 | |||
1426 | @@ -19,6 +19,8 @@ | |||
1427 | 19 | #ifndef MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ | 19 | #ifndef MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ |
1428 | 20 | #define MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ | 20 | #define MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ |
1429 | 21 | 21 | ||
1430 | 22 | #include "mir/dispatch/dispatchable.h" | ||
1431 | 23 | |||
1432 | 22 | #include <google/protobuf/service.h> | 24 | #include <google/protobuf/service.h> |
1433 | 23 | #include <google/protobuf/descriptor.h> | 25 | #include <google/protobuf/descriptor.h> |
1434 | 24 | 26 | ||
1435 | @@ -57,8 +59,10 @@ | |||
1436 | 57 | void save_completion_details( | 59 | void save_completion_details( |
1437 | 58 | mir::protobuf::wire::Invocation const& invoke, | 60 | mir::protobuf::wire::Invocation const& invoke, |
1438 | 59 | google::protobuf::Message* response, | 61 | google::protobuf::Message* response, |
1441 | 60 | std::shared_ptr<google::protobuf::Closure> const& complete); | 62 | google::protobuf::Closure* complete); |
1442 | 61 | 63 | ||
1443 | 64 | |||
1444 | 65 | google::protobuf::Message* message_for_result(mir::protobuf::wire::Result& result); | ||
1445 | 62 | 66 | ||
1446 | 63 | void complete_response(mir::protobuf::wire::Result& result); | 67 | void complete_response(mir::protobuf::wire::Result& result); |
1447 | 64 | 68 | ||
1448 | @@ -72,14 +76,14 @@ | |||
1449 | 72 | { | 76 | { |
1450 | 73 | PendingCall( | 77 | PendingCall( |
1451 | 74 | google::protobuf::Message* response, | 78 | google::protobuf::Message* response, |
1453 | 75 | std::shared_ptr<google::protobuf::Closure> const& target) | 79 | google::protobuf::Closure* target) |
1454 | 76 | : response(response), complete(target) {} | 80 | : response(response), complete(target) {} |
1455 | 77 | 81 | ||
1456 | 78 | PendingCall() | 82 | PendingCall() |
1457 | 79 | : response(0), complete() {} | 83 | : response(0), complete() {} |
1458 | 80 | 84 | ||
1459 | 81 | google::protobuf::Message* response; | 85 | google::protobuf::Message* response; |
1461 | 82 | std::shared_ptr<google::protobuf::Closure> complete; | 86 | google::protobuf::Closure* complete; |
1462 | 83 | }; | 87 | }; |
1463 | 84 | 88 | ||
1464 | 85 | std::mutex mutable mutex; | 89 | std::mutex mutable mutex; |
1465 | @@ -88,12 +92,15 @@ | |||
1466 | 88 | }; | 92 | }; |
1467 | 89 | } | 93 | } |
1468 | 90 | 94 | ||
1470 | 91 | class MirBasicRpcChannel : public google::protobuf::RpcChannel | 95 | class MirBasicRpcChannel |
1471 | 96 | : public google::protobuf::RpcChannel, | ||
1472 | 97 | public mir::dispatch::Dispatchable | ||
1473 | 92 | { | 98 | { |
1474 | 93 | public: | 99 | public: |
1475 | 94 | MirBasicRpcChannel(); | 100 | MirBasicRpcChannel(); |
1476 | 95 | ~MirBasicRpcChannel(); | 101 | ~MirBasicRpcChannel(); |
1477 | 96 | 102 | ||
1478 | 103 | virtual void process_next_request_first() = 0; | ||
1479 | 97 | protected: | 104 | protected: |
1480 | 98 | mir::protobuf::wire::Invocation invocation_for( | 105 | mir::protobuf::wire::Invocation invocation_for( |
1481 | 99 | google::protobuf::MethodDescriptor const* method, | 106 | google::protobuf::MethodDescriptor const* method, |
1482 | 100 | 107 | ||
1483 | === modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp' | |||
1484 | --- src/client/rpc/mir_protobuf_rpc_channel.cpp 2015-05-01 14:47:55 +0000 | |||
1485 | +++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2015-05-14 07:50:26 +0000 | |||
1486 | @@ -60,7 +60,9 @@ | |||
1487 | 60 | lifecycle_control(lifecycle_control), | 60 | lifecycle_control(lifecycle_control), |
1488 | 61 | event_sink(event_sink), | 61 | event_sink(event_sink), |
1489 | 62 | disconnected(false), | 62 | disconnected(false), |
1491 | 63 | transport{std::move(transport)} | 63 | transport{std::move(transport)}, |
1492 | 64 | delayed_processor{std::make_shared<md::ActionQueue>()}, | ||
1493 | 65 | multiplexer{this->transport, delayed_processor} | ||
1494 | 64 | { | 66 | { |
1495 | 65 | class NullDeleter | 67 | class NullDeleter |
1496 | 66 | { | 68 | { |
1497 | @@ -105,8 +107,7 @@ | |||
1498 | 105 | } | 107 | } |
1499 | 106 | } | 108 | } |
1500 | 107 | 109 | ||
1503 | 108 | void mclr::MirProtobufRpcChannel::receive_file_descriptors(google::protobuf::Message* response, | 110 | void mclr::MirProtobufRpcChannel::receive_file_descriptors(google::protobuf::Message* response) |
1502 | 109 | google::protobuf::Closure* complete) | ||
1504 | 110 | { | 111 | { |
1505 | 111 | auto const message_type = response->GetTypeName(); | 112 | auto const message_type = response->GetTypeName(); |
1506 | 112 | 113 | ||
1507 | @@ -163,7 +164,6 @@ | |||
1508 | 163 | receive_any_file_descriptors_for(platform); | 164 | receive_any_file_descriptors_for(platform); |
1509 | 164 | receive_any_file_descriptors_for(socket_fd); | 165 | receive_any_file_descriptors_for(socket_fd); |
1510 | 165 | receive_any_file_descriptors_for(platform_operation_message); | 166 | receive_any_file_descriptors_for(platform_operation_message); |
1511 | 166 | complete->Run(); | ||
1512 | 167 | } | 167 | } |
1513 | 168 | 168 | ||
1514 | 169 | void mclr::MirProtobufRpcChannel::CallMethod( | 169 | void mclr::MirProtobufRpcChannel::CallMethod( |
1515 | @@ -193,10 +193,13 @@ | |||
1516 | 193 | 193 | ||
1517 | 194 | rpc_report->invocation_requested(invocation); | 194 | rpc_report->invocation_requested(invocation); |
1518 | 195 | 195 | ||
1521 | 196 | std::shared_ptr<google::protobuf::Closure> callback( | 196 | pending_calls.save_completion_details(invocation, response, complete); |
1520 | 197 | google::protobuf::NewPermanentCallback(this, &MirProtobufRpcChannel::receive_file_descriptors, response, complete)); | ||
1522 | 198 | 197 | ||
1524 | 199 | pending_calls.save_completion_details(invocation, response, callback); | 198 | if (prioritise_next_request) |
1525 | 199 | { | ||
1526 | 200 | id_to_wait_for = invocation.id(); | ||
1527 | 201 | prioritise_next_request = false; | ||
1528 | 202 | } | ||
1529 | 200 | 203 | ||
1530 | 201 | send_message(invocation, invocation, fds); | 204 | send_message(invocation, invocation, fds); |
1531 | 202 | } | 205 | } |
1532 | @@ -317,7 +320,7 @@ | |||
1533 | 317 | */ | 320 | */ |
1534 | 318 | std::lock_guard<decltype(read_mutex)> lock(read_mutex); | 321 | std::lock_guard<decltype(read_mutex)> lock(read_mutex); |
1535 | 319 | 322 | ||
1537 | 320 | mir::protobuf::wire::Result result; | 323 | auto result = std::make_unique<mir::protobuf::wire::Result>(); |
1538 | 321 | try | 324 | try |
1539 | 322 | { | 325 | { |
1540 | 323 | uint16_t message_size; | 326 | uint16_t message_size; |
1541 | @@ -327,9 +330,9 @@ | |||
1542 | 327 | body_bytes.resize(message_size); | 330 | body_bytes.resize(message_size); |
1543 | 328 | transport->receive_data(body_bytes.data(), message_size); | 331 | transport->receive_data(body_bytes.data(), message_size); |
1544 | 329 | 332 | ||
1546 | 330 | result.ParseFromArray(body_bytes.data(), message_size); | 333 | result->ParseFromArray(body_bytes.data(), message_size); |
1547 | 331 | 334 | ||
1549 | 332 | rpc_report->result_receipt_succeeded(result); | 335 | rpc_report->result_receipt_succeeded(*result); |
1550 | 333 | } | 336 | } |
1551 | 334 | catch (std::exception const& x) | 337 | catch (std::exception const& x) |
1552 | 335 | { | 338 | { |
1553 | @@ -339,14 +342,39 @@ | |||
1554 | 339 | 342 | ||
1555 | 340 | try | 343 | try |
1556 | 341 | { | 344 | { |
1558 | 342 | for (int i = 0; i != result.events_size(); ++i) | 345 | for (int i = 0; i != result->events_size(); ++i) |
1559 | 343 | { | 346 | { |
1561 | 344 | process_event_sequence(result.events(i)); | 347 | process_event_sequence(result->events(i)); |
1562 | 345 | } | 348 | } |
1563 | 346 | 349 | ||
1565 | 347 | if (result.has_id()) | 350 | if (result->has_id()) |
1566 | 348 | { | 351 | { |
1568 | 349 | pending_calls.complete_response(result); | 352 | auto result_message = pending_calls.message_for_result(*result); |
1569 | 353 | result_message->ParseFromString(result->response()); | ||
1570 | 354 | receive_file_descriptors(result_message); | ||
1571 | 355 | |||
1572 | 356 | if (id_to_wait_for) | ||
1573 | 357 | { | ||
1574 | 358 | if (result->id() == id_to_wait_for.value()) | ||
1575 | 359 | { | ||
1576 | 360 | pending_calls.complete_response(*result); | ||
1577 | 361 | multiplexer.add_watch(delayed_processor); | ||
1578 | 362 | } | ||
1579 | 363 | else | ||
1580 | 364 | { | ||
1581 | 365 | // It's too difficult to convince C++ to move this lambda everywhere, so | ||
1582 | 366 | // just give up and let it pretend its a shared_ptr. | ||
1583 | 367 | std::shared_ptr<mir::protobuf::wire::Result> appeaser{std::move(result)}; | ||
1584 | 368 | delayed_processor->enqueue([delayed_result = std::move(appeaser), this]() mutable | ||
1585 | 369 | { | ||
1586 | 370 | pending_calls.complete_response(*delayed_result); | ||
1587 | 371 | }); | ||
1588 | 372 | } | ||
1589 | 373 | } | ||
1590 | 374 | else | ||
1591 | 375 | { | ||
1592 | 376 | pending_calls.complete_response(*result); | ||
1593 | 377 | } | ||
1594 | 350 | } | 378 | } |
1595 | 351 | } | 379 | } |
1596 | 352 | catch (std::exception const& x) | 380 | catch (std::exception const& x) |
1597 | @@ -354,7 +382,7 @@ | |||
1598 | 354 | // TODO: This is dangerous as an error in result processing could cause a wait handle | 382 | // TODO: This is dangerous as an error in result processing could cause a wait handle |
1599 | 355 | // to never fire. Could perhaps fix by catching and setting error on the response before invoking | 383 | // to never fire. Could perhaps fix by catching and setting error on the response before invoking |
1600 | 356 | // callback ~racarr | 384 | // callback ~racarr |
1602 | 357 | rpc_report->result_processing_failed(result, x); | 385 | rpc_report->result_processing_failed(*result, x); |
1603 | 358 | } | 386 | } |
1604 | 359 | } | 387 | } |
1605 | 360 | 388 | ||
1606 | @@ -365,15 +393,21 @@ | |||
1607 | 365 | 393 | ||
1608 | 366 | mir::Fd mir::client::rpc::MirProtobufRpcChannel::watch_fd() const | 394 | mir::Fd mir::client::rpc::MirProtobufRpcChannel::watch_fd() const |
1609 | 367 | { | 395 | { |
1611 | 368 | return transport->watch_fd(); | 396 | return multiplexer.watch_fd(); |
1612 | 369 | } | 397 | } |
1613 | 370 | 398 | ||
1614 | 371 | bool mir::client::rpc::MirProtobufRpcChannel::dispatch(md::FdEvents events) | 399 | bool mir::client::rpc::MirProtobufRpcChannel::dispatch(md::FdEvents events) |
1615 | 372 | { | 400 | { |
1617 | 373 | return transport->dispatch(events); | 401 | return multiplexer.dispatch(events); |
1618 | 374 | } | 402 | } |
1619 | 375 | 403 | ||
1620 | 376 | md::FdEvents mclr::MirProtobufRpcChannel::relevant_events() const | 404 | md::FdEvents mclr::MirProtobufRpcChannel::relevant_events() const |
1621 | 377 | { | 405 | { |
1623 | 378 | return transport->relevant_events(); | 406 | return multiplexer.relevant_events(); |
1624 | 407 | } | ||
1625 | 408 | |||
1626 | 409 | void mclr::MirProtobufRpcChannel::process_next_request_first() | ||
1627 | 410 | { | ||
1628 | 411 | prioritise_next_request = true; | ||
1629 | 412 | multiplexer.remove_watch(delayed_processor); | ||
1630 | 379 | } | 413 | } |
1631 | 380 | 414 | ||
1632 | === modified file 'src/client/rpc/mir_protobuf_rpc_channel.h' | |||
1633 | --- src/client/rpc/mir_protobuf_rpc_channel.h 2015-03-31 02:35:42 +0000 | |||
1634 | +++ src/client/rpc/mir_protobuf_rpc_channel.h 2015-05-14 07:50:26 +0000 | |||
1635 | @@ -22,23 +22,21 @@ | |||
1636 | 22 | #include "mir_basic_rpc_channel.h" | 22 | #include "mir_basic_rpc_channel.h" |
1637 | 23 | #include "stream_transport.h" | 23 | #include "stream_transport.h" |
1638 | 24 | #include "mir/dispatch/dispatchable.h" | 24 | #include "mir/dispatch/dispatchable.h" |
1639 | 25 | #include "mir/dispatch/multiplexing_dispatchable.h" | ||
1640 | 26 | #include "mir/dispatch/action_queue.h" | ||
1641 | 27 | |||
1642 | 28 | #include "mir_protobuf_wire.pb.h" | ||
1643 | 25 | 29 | ||
1644 | 26 | #include <google/protobuf/service.h> | 30 | #include <google/protobuf/service.h> |
1645 | 27 | #include <google/protobuf/descriptor.h> | 31 | #include <google/protobuf/descriptor.h> |
1646 | 28 | 32 | ||
1647 | 29 | #include <thread> | 33 | #include <thread> |
1648 | 30 | #include <atomic> | 34 | #include <atomic> |
1649 | 35 | #include <list> | ||
1650 | 36 | #include <experimental/optional> | ||
1651 | 31 | 37 | ||
1652 | 32 | namespace mir | 38 | namespace mir |
1653 | 33 | { | 39 | { |
1654 | 34 | namespace protobuf | ||
1655 | 35 | { | ||
1656 | 36 | namespace wire | ||
1657 | 37 | { | ||
1658 | 38 | class Invocation; | ||
1659 | 39 | class Result; | ||
1660 | 40 | } | ||
1661 | 41 | } | ||
1662 | 42 | 40 | ||
1663 | 43 | namespace client | 41 | namespace client |
1664 | 44 | { | 42 | { |
1665 | @@ -53,8 +51,7 @@ | |||
1666 | 53 | 51 | ||
1667 | 54 | class MirProtobufRpcChannel : | 52 | class MirProtobufRpcChannel : |
1668 | 55 | public MirBasicRpcChannel, | 53 | public MirBasicRpcChannel, |
1671 | 56 | public StreamTransport::Observer, | 54 | public StreamTransport::Observer |
1670 | 57 | public dispatch::Dispatchable | ||
1672 | 58 | { | 55 | { |
1673 | 59 | public: | 56 | public: |
1674 | 60 | MirProtobufRpcChannel(std::unique_ptr<StreamTransport> transport, | 57 | MirProtobufRpcChannel(std::unique_ptr<StreamTransport> transport, |
1675 | @@ -74,6 +71,20 @@ | |||
1676 | 74 | Fd watch_fd() const override; | 71 | Fd watch_fd() const override; |
1677 | 75 | bool dispatch(mir::dispatch::FdEvents events) override; | 72 | bool dispatch(mir::dispatch::FdEvents events) override; |
1678 | 76 | mir::dispatch::FdEvents relevant_events() const override; | 73 | mir::dispatch::FdEvents relevant_events() const override; |
1679 | 74 | |||
1680 | 75 | /** | ||
1681 | 76 | * \brief Switch the RpcChannel into out-of-order mode | ||
1682 | 77 | * | ||
1683 | 78 | * The first CallMethod after this method is called will be processed | ||
1684 | 79 | * out of order - no server responses will be processed until the response | ||
1685 | 80 | * for the next CallMethod is processed. | ||
1686 | 81 | * | ||
1687 | 82 | * After the response for the next CallMethod is processed, normal processing | ||
1688 | 83 | * is resumed. | ||
1689 | 84 | * | ||
1690 | 85 | * No messages are discarded, only delayed. | ||
1691 | 86 | */ | ||
1692 | 87 | void process_next_request_first() override; | ||
1693 | 77 | private: | 88 | private: |
1694 | 78 | virtual void CallMethod(const google::protobuf::MethodDescriptor* method, google::protobuf::RpcController*, | 89 | virtual void CallMethod(const google::protobuf::MethodDescriptor* method, google::protobuf::RpcController*, |
1695 | 79 | const google::protobuf::Message* parameters, google::protobuf::Message* response, | 90 | const google::protobuf::Message* parameters, google::protobuf::Message* response, |
1696 | @@ -86,7 +97,7 @@ | |||
1697 | 86 | detail::SendBuffer header_bytes; | 97 | detail::SendBuffer header_bytes; |
1698 | 87 | detail::SendBuffer body_bytes; | 98 | detail::SendBuffer body_bytes; |
1699 | 88 | 99 | ||
1701 | 89 | void receive_file_descriptors(google::protobuf::Message* response, google::protobuf::Closure* complete); | 100 | void receive_file_descriptors(google::protobuf::Message* response); |
1702 | 90 | template<class MessageType> | 101 | template<class MessageType> |
1703 | 91 | void receive_any_file_descriptors_for(MessageType* response); | 102 | void receive_any_file_descriptors_for(MessageType* response); |
1704 | 92 | void send_message(mir::protobuf::wire::Invocation const& body, | 103 | void send_message(mir::protobuf::wire::Invocation const& body, |
1705 | @@ -106,14 +117,22 @@ | |||
1706 | 106 | std::mutex read_mutex; | 117 | std::mutex read_mutex; |
1707 | 107 | std::mutex write_mutex; | 118 | std::mutex write_mutex; |
1708 | 108 | 119 | ||
1709 | 120 | bool prioritise_next_request{false}; | ||
1710 | 121 | std::experimental::optional<uint32_t> id_to_wait_for; | ||
1711 | 122 | |||
1712 | 109 | /* We use the guarantee that the transport's destructor blocks until | 123 | /* We use the guarantee that the transport's destructor blocks until |
1713 | 110 | * pending processing has finished to ensure that on_data_available() | 124 | * pending processing has finished to ensure that on_data_available() |
1714 | 111 | * isn't called after the members it relies on are destroyed. | 125 | * isn't called after the members it relies on are destroyed. |
1715 | 112 | * | 126 | * |
1718 | 113 | * This means the transport field must appear after any field used | 127 | * This means that anything that owns a reference to the transport |
1719 | 114 | * by on_data_available. For simplicity, put it last. | 128 | * needs to be after anything that can be accessed from on_data_available(). |
1720 | 129 | * | ||
1721 | 130 | * For simplicity's sake keep all of the dispatch infrastructure at the | ||
1722 | 131 | * end to guarantee this. | ||
1723 | 115 | */ | 132 | */ |
1725 | 116 | std::unique_ptr<StreamTransport> transport; | 133 | std::shared_ptr<StreamTransport> const transport; |
1726 | 134 | std::shared_ptr<mir::dispatch::ActionQueue> const delayed_processor; | ||
1727 | 135 | mir::dispatch::MultiplexingDispatchable multiplexer; | ||
1728 | 117 | }; | 136 | }; |
1729 | 118 | 137 | ||
1730 | 119 | } | 138 | } |
1731 | 120 | 139 | ||
1732 | === modified file 'src/client/symbols.map' | |||
1733 | --- src/client/symbols.map 2015-05-07 19:41:08 +0000 | |||
1734 | +++ src/client/symbols.map 2015-05-14 07:50:26 +0000 | |||
1735 | @@ -196,6 +196,10 @@ | |||
1736 | 196 | mir_buffer_stream_release; | 196 | mir_buffer_stream_release; |
1737 | 197 | mir_buffer_stream_release_sync; | 197 | mir_buffer_stream_release_sync; |
1738 | 198 | mir_buffer_stream_is_valid; | 198 | mir_buffer_stream_is_valid; |
1739 | 199 | mir_connect_with_manual_dispatch; | ||
1740 | 200 | mir_connection_get_event_fd; | ||
1741 | 201 | mir_connection_dispatch; | ||
1742 | 202 | mir_wait_handle_ready; | ||
1743 | 199 | } MIR_CLIENT_8.3; | 203 | } MIR_CLIENT_8.3; |
1744 | 200 | 204 | ||
1745 | 201 | MIR_CLIENT_DETAIL_8 { | 205 | MIR_CLIENT_DETAIL_8 { |
1746 | 202 | 206 | ||
1747 | === added file 'src/client/synchronous_helper.cpp' | |||
1748 | --- src/client/synchronous_helper.cpp 1970-01-01 00:00:00 +0000 | |||
1749 | +++ src/client/synchronous_helper.cpp 2015-05-14 07:50:26 +0000 | |||
1750 | @@ -0,0 +1,33 @@ | |||
1751 | 1 | /* | ||
1752 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1753 | 3 | * | ||
1754 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1755 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1756 | 6 | * as published by the Free Software Foundation. | ||
1757 | 7 | * | ||
1758 | 8 | * This program is distributed in the hope that it will be useful, | ||
1759 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1760 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1761 | 11 | * GNU Lesser General Public License for more details. | ||
1762 | 12 | * | ||
1763 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1764 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1765 | 15 | * | ||
1766 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
1767 | 17 | */ | ||
1768 | 18 | |||
1769 | 19 | #include "synchronous_helper.h" | ||
1770 | 20 | |||
1771 | 21 | #include <poll.h> | ||
1772 | 22 | |||
1773 | 23 | void dispatch_connection_until(MirConnection* connection, std::function<bool()> predicate) | ||
1774 | 24 | { | ||
1775 | 25 | pollfd fd; | ||
1776 | 26 | fd.fd = connection->watch_fd(); | ||
1777 | 27 | fd.events = POLLIN; | ||
1778 | 28 | while(!predicate() && (poll(&fd, 1, -1) > 0)) | ||
1779 | 29 | { | ||
1780 | 30 | connection->dispatch(); | ||
1781 | 31 | } | ||
1782 | 32 | } | ||
1783 | 33 | |||
1784 | 0 | 34 | ||
1785 | === added file 'src/client/synchronous_helper.h' | |||
1786 | --- src/client/synchronous_helper.h 1970-01-01 00:00:00 +0000 | |||
1787 | +++ src/client/synchronous_helper.h 2015-05-14 07:50:26 +0000 | |||
1788 | @@ -0,0 +1,160 @@ | |||
1789 | 1 | /* | ||
1790 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1791 | 3 | * | ||
1792 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1793 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1794 | 6 | * as published by the Free Software Foundation. | ||
1795 | 7 | * | ||
1796 | 8 | * This program is distributed in the hope that it will be useful, | ||
1797 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1798 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1799 | 11 | * GNU Lesser General Public License for more details. | ||
1800 | 12 | * | ||
1801 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1802 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1803 | 15 | * | ||
1804 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
1805 | 17 | */ | ||
1806 | 18 | |||
1807 | 19 | #ifndef MIR_CLIENT_SYNCHRONOUS_H_ | ||
1808 | 20 | #define MIR_CLIENT_SYNCHRONOUS_H_ | ||
1809 | 21 | |||
1810 | 22 | #include "mir_connection.h" | ||
1811 | 23 | #include "mir_wait_handle.h" | ||
1812 | 24 | |||
1813 | 25 | #include <functional> | ||
1814 | 26 | #include <type_traits> | ||
1815 | 27 | |||
1816 | 28 | template<typename Result> | ||
1817 | 29 | void assign_result(Result* result, void* ctx) | ||
1818 | 30 | { | ||
1819 | 31 | auto assignee = reinterpret_cast<Result**>(ctx); | ||
1820 | 32 | if (assignee) | ||
1821 | 33 | { | ||
1822 | 34 | *assignee = result; | ||
1823 | 35 | } | ||
1824 | 36 | } | ||
1825 | 37 | |||
1826 | 38 | template<typename Callback> | ||
1827 | 39 | struct SynchronousContext | ||
1828 | 40 | { | ||
1829 | 41 | Callback real_callback; | ||
1830 | 42 | bool complete; | ||
1831 | 43 | void* userdata; | ||
1832 | 44 | }; | ||
1833 | 45 | |||
1834 | 46 | template<typename Callable, class Tuple, std::size_t...I> | ||
1835 | 47 | void apply_substituting_last_arg( | ||
1836 | 48 | Callable&& function, | ||
1837 | 49 | Tuple&& args, | ||
1838 | 50 | std::index_sequence<I...>, | ||
1839 | 51 | void* context) | ||
1840 | 52 | { | ||
1841 | 53 | return std::forward<Callable>(function)( | ||
1842 | 54 | std::get<I>(std::forward<Tuple>(args))..., | ||
1843 | 55 | context); | ||
1844 | 56 | } | ||
1845 | 57 | |||
1846 | 58 | |||
1847 | 59 | template<typename... Args> | ||
1848 | 60 | void synchronous_wrapper(Args... args) | ||
1849 | 61 | { | ||
1850 | 62 | std::tuple<Args...> arguments{args...}; | ||
1851 | 63 | constexpr std::size_t arg_count = sizeof...(Args); | ||
1852 | 64 | |||
1853 | 65 | auto wrapped_context = reinterpret_cast<SynchronousContext<void(*)(Args...)>*>(std::get<arg_count - 1>(arguments)); | ||
1854 | 66 | if (wrapped_context->real_callback) | ||
1855 | 67 | { | ||
1856 | 68 | apply_substituting_last_arg( | ||
1857 | 69 | wrapped_context->real_callback, | ||
1858 | 70 | std::forward_as_tuple(args...), | ||
1859 | 71 | std::make_index_sequence<arg_count - 1>(), | ||
1860 | 72 | wrapped_context->userdata); | ||
1861 | 73 | } | ||
1862 | 74 | wrapped_context->complete = true; | ||
1863 | 75 | } | ||
1864 | 76 | |||
1865 | 77 | |||
1866 | 78 | template<typename Callable, typename Tuple, std::size_t...I> | ||
1867 | 79 | constexpr decltype(auto) call_impl(Callable&& function, Tuple&& args, std::index_sequence<I...>) | ||
1868 | 80 | { | ||
1869 | 81 | return std::forward<Callable>(function)(std::get<I>(std::forward<Tuple>((args)))...); | ||
1870 | 82 | } | ||
1871 | 83 | |||
1872 | 84 | template<typename Callable, typename Tuple> | ||
1873 | 85 | constexpr decltype(auto) apply(Callable&& function, Tuple&& args) | ||
1874 | 86 | { | ||
1875 | 87 | return call_impl( | ||
1876 | 88 | std::forward<Callable>(function), | ||
1877 | 89 | std::forward<Tuple>(args), | ||
1878 | 90 | std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>{}>{}); | ||
1879 | 91 | } | ||
1880 | 92 | |||
1881 | 93 | void dispatch_connection_until(MirConnection* connection, std::function<bool()> predicate); | ||
1882 | 94 | |||
1883 | 95 | |||
1884 | 96 | /** | ||
1885 | 97 | * \brief Make a synchronous RPC call | ||
1886 | 98 | * | ||
1887 | 99 | * This wrapper takes care of manually dispatching the MirConnection if it is in | ||
1888 | 100 | * manual dispatch mode, or waiting for the operation to complete if in automatic | ||
1889 | 101 | * dispatch mode. | ||
1890 | 102 | * | ||
1891 | 103 | * Given a function mir_foo_do_thing(MirFoo* target, int arg, foo_callback callback, void* context) | ||
1892 | 104 | * the correct way to call this function is | ||
1893 | 105 | * make_synchronous_call(connection, | ||
1894 | 106 | * &mir_foo_do_thing, | ||
1895 | 107 | * target, | ||
1896 | 108 | * arg, | ||
1897 | 109 | * callback, | ||
1898 | 110 | * static_cast<void*>(context)); | ||
1899 | 111 | * | ||
1900 | 112 | * The last two parameters must be the callback function and the void* to pass to that callback. | ||
1901 | 113 | * The last argument must have a pointer type; NULL or nullptr must be explicitly cast to | ||
1902 | 114 | * void*. | ||
1903 | 115 | */ | ||
1904 | 116 | template<typename Callable, typename... Args> | ||
1905 | 117 | void make_synchronous_call(MirConnection* connection, | ||
1906 | 118 | Callable&& function, | ||
1907 | 119 | Args&&... args) | ||
1908 | 120 | { | ||
1909 | 121 | static_assert( | ||
1910 | 122 | std::is_same<typename std::result_of<Callable(Args...)>::type, MirWaitHandle*>::value, | ||
1911 | 123 | "Second parameter must be a function that returns a MirWaitHandle*"); | ||
1912 | 124 | |||
1913 | 125 | if (connection->watch_fd() != mir::Fd::invalid) | ||
1914 | 126 | { | ||
1915 | 127 | std::tuple<Args...> arguments{args...}; | ||
1916 | 128 | constexpr int arg_count = sizeof...(Args); | ||
1917 | 129 | auto callback = std::get<arg_count - 2>(arguments); | ||
1918 | 130 | auto context = std::get<arg_count - 1>(arguments); | ||
1919 | 131 | |||
1920 | 132 | static_assert( | ||
1921 | 133 | std::is_pointer<typename std::tuple_element<arg_count - 1, std::tuple<Args...>>::type>::value, | ||
1922 | 134 | "The final argument must be a pointer type"); | ||
1923 | 135 | static_assert( | ||
1924 | 136 | std::is_pointer<typename std::tuple_element<arg_count - 2, std::tuple<Args...>>::type>::value, | ||
1925 | 137 | "The second last argument must be a function pointer"); | ||
1926 | 138 | |||
1927 | 139 | SynchronousContext<decltype(callback)> wrapper_context { | ||
1928 | 140 | callback, | ||
1929 | 141 | false, | ||
1930 | 142 | context | ||
1931 | 143 | }; | ||
1932 | 144 | |||
1933 | 145 | std::get<arg_count - 2>(arguments) = &synchronous_wrapper; | ||
1934 | 146 | std::get<arg_count - 1>(arguments) = | ||
1935 | 147 | reinterpret_cast<typename std::tuple_element<arg_count - 1, std::tuple<Args...>>::type>(&wrapper_context); | ||
1936 | 148 | |||
1937 | 149 | connection->process_next_request_first(); | ||
1938 | 150 | apply(std::forward<Callable>(function), arguments); | ||
1939 | 151 | |||
1940 | 152 | dispatch_connection_until(connection, [&wrapper_context](){ return wrapper_context.complete; }); | ||
1941 | 153 | } | ||
1942 | 154 | else | ||
1943 | 155 | { | ||
1944 | 156 | mir_wait_for(std::forward<Callable>(function)(std::forward<Args>(args)...)); | ||
1945 | 157 | } | ||
1946 | 158 | } | ||
1947 | 159 | |||
1948 | 160 | #endif // MIR_CLIENT_SYNCHRONOUS_H_ | ||
1949 | 0 | 161 | ||
1950 | === modified file 'src/common/dispatch/CMakeLists.txt' | |||
1951 | --- src/common/dispatch/CMakeLists.txt 2015-04-09 06:20:31 +0000 | |||
1952 | +++ src/common/dispatch/CMakeLists.txt 2015-05-14 07:50:26 +0000 | |||
1953 | @@ -17,10 +17,9 @@ | |||
1954 | 17 | list( | 17 | list( |
1955 | 18 | APPEND MIR_COMMON_SOURCES | 18 | APPEND MIR_COMMON_SOURCES |
1956 | 19 | ${CMAKE_CURRENT_SOURCE_DIR}/action_queue.cpp | 19 | ${CMAKE_CURRENT_SOURCE_DIR}/action_queue.cpp |
1957 | 20 | ${CMAKE_CURRENT_SOURCE_DIR}/simple_dispatch_thread.cpp | ||
1958 | 21 | ${CMAKE_CURRENT_SOURCE_DIR}/multiplexing_dispatchable.cpp | 20 | ${CMAKE_CURRENT_SOURCE_DIR}/multiplexing_dispatchable.cpp |
1959 | 22 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp | 21 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp |
1961 | 23 | ${CMAKE_CURRENT_SOURCE_DIR}/action_queue.cpp | 22 | ${CMAKE_CURRENT_SOURCE_DIR}/threaded_dispatcher.cpp |
1962 | 24 | ) | 23 | ) |
1963 | 25 | 24 | ||
1964 | 26 | set(MIR_COMMON_SOURCES ${MIR_COMMON_SOURCES} PARENT_SCOPE) | 25 | set(MIR_COMMON_SOURCES ${MIR_COMMON_SOURCES} PARENT_SCOPE) |
1965 | 27 | 26 | ||
1966 | === removed file 'src/common/dispatch/simple_dispatch_thread.cpp' | |||
1967 | --- src/common/dispatch/simple_dispatch_thread.cpp 2015-04-30 17:41:03 +0000 | |||
1968 | +++ src/common/dispatch/simple_dispatch_thread.cpp 1970-01-01 00:00:00 +0000 | |||
1969 | @@ -1,163 +0,0 @@ | |||
1970 | 1 | /* | ||
1971 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1972 | 3 | * | ||
1973 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1974 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1975 | 6 | * as published by the Free Software Foundation. | ||
1976 | 7 | * | ||
1977 | 8 | * This program is distributed in the hope that it will be useful, | ||
1978 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1979 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1980 | 11 | * GNU Lesser General Public License for more details. | ||
1981 | 12 | * | ||
1982 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1983 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1984 | 15 | * | ||
1985 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
1986 | 17 | */ | ||
1987 | 18 | |||
1988 | 19 | #include "mir/dispatch/simple_dispatch_thread.h" | ||
1989 | 20 | #include "mir/dispatch/dispatchable.h" | ||
1990 | 21 | #include "mir/logging/logger.h" | ||
1991 | 22 | #include "utils.h" | ||
1992 | 23 | #include "mir/signal_blocker.h" | ||
1993 | 24 | |||
1994 | 25 | #include <sys/epoll.h> | ||
1995 | 26 | #include <unistd.h> | ||
1996 | 27 | #include <system_error> | ||
1997 | 28 | #include <array> | ||
1998 | 29 | #include <signal.h> | ||
1999 | 30 | #include <boost/exception/all.hpp> | ||
2000 | 31 | |||
2001 | 32 | namespace md = mir::dispatch; | ||
2002 | 33 | |||
2003 | 34 | namespace | ||
2004 | 35 | { | ||
2005 | 36 | |||
2006 | 37 | void wait_for_events_forever(std::shared_ptr<md::Dispatchable> const& dispatchee, mir::Fd shutdown_fd) | ||
2007 | 38 | { | ||
2008 | 39 | auto epoll_fd = mir::Fd{epoll_create1(0)}; | ||
2009 | 40 | if (epoll_fd == mir::Fd::invalid) | ||
2010 | 41 | { | ||
2011 | 42 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2012 | 43 | std::system_category(), | ||
2013 | 44 | "Failed to create epoll IO monitor"})); | ||
2014 | 45 | } | ||
2015 | 46 | epoll_event event; | ||
2016 | 47 | memset(&event, 0, sizeof(event)); | ||
2017 | 48 | |||
2018 | 49 | enum fd_names : uint32_t { | ||
2019 | 50 | shutdown, | ||
2020 | 51 | dispatchee_fd | ||
2021 | 52 | }; | ||
2022 | 53 | |||
2023 | 54 | // We only care when the shutdown pipe has been closed | ||
2024 | 55 | event.data.u32 = fd_names::shutdown; | ||
2025 | 56 | event.events = EPOLLRDHUP; | ||
2026 | 57 | epoll_ctl(epoll_fd, EPOLL_CTL_ADD, shutdown_fd, &event); | ||
2027 | 58 | |||
2028 | 59 | // Ask the dispatchee what it events it's interested in... | ||
2029 | 60 | event.data.u32 = fd_names::dispatchee_fd; | ||
2030 | 61 | event.events = md::fd_event_to_epoll(dispatchee->relevant_events()); | ||
2031 | 62 | epoll_ctl(epoll_fd, EPOLL_CTL_ADD, dispatchee->watch_fd(), &event); | ||
2032 | 63 | |||
2033 | 64 | for (;;) | ||
2034 | 65 | { | ||
2035 | 66 | std::array<epoll_event,2> events; | ||
2036 | 67 | auto const num_available_events = | ||
2037 | 68 | epoll_wait(epoll_fd, events.data(), events.size(), -1); | ||
2038 | 69 | |||
2039 | 70 | if (num_available_events == 1) | ||
2040 | 71 | { | ||
2041 | 72 | if (events[0].data.u32 == fd_names::dispatchee_fd) | ||
2042 | 73 | { | ||
2043 | 74 | if (!dispatchee->dispatch(md::epoll_to_fd_event(events[0]))) | ||
2044 | 75 | { | ||
2045 | 76 | // No need to keep looping, the Dispatchable's not going to produce any more events. | ||
2046 | 77 | return; | ||
2047 | 78 | } | ||
2048 | 79 | } | ||
2049 | 80 | else if (events[0].data.u32 == fd_names::shutdown) | ||
2050 | 81 | { | ||
2051 | 82 | // The only thing we do with the shutdown fd is to close it. | ||
2052 | 83 | return; | ||
2053 | 84 | } | ||
2054 | 85 | } | ||
2055 | 86 | else if (num_available_events > 1) | ||
2056 | 87 | { | ||
2057 | 88 | // Because we only have two fds in the epoll, if there is more than one | ||
2058 | 89 | // event pending then one of them must be a shutdown event. | ||
2059 | 90 | // So, shutdown. | ||
2060 | 91 | return; | ||
2061 | 92 | } | ||
2062 | 93 | else if (num_available_events < 0) | ||
2063 | 94 | { | ||
2064 | 95 | // Although we have blocked signals in this thread, we can still | ||
2065 | 96 | // get interrupted by SIGSTOP (which is unblockable and non-fatal). | ||
2066 | 97 | if (errno != EINTR) | ||
2067 | 98 | { | ||
2068 | 99 | BOOST_THROW_EXCEPTION((std::system_error{ | ||
2069 | 100 | errno, std::system_category(), "Failed to wait for epoll events"})); | ||
2070 | 101 | } | ||
2071 | 102 | } | ||
2072 | 103 | } | ||
2073 | 104 | } | ||
2074 | 105 | |||
2075 | 106 | } | ||
2076 | 107 | |||
2077 | 108 | md::SimpleDispatchThread::SimpleDispatchThread(std::shared_ptr<md::Dispatchable> const& dispatchee) | ||
2078 | 109 | : SimpleDispatchThread(dispatchee, []{}) | ||
2079 | 110 | {} | ||
2080 | 111 | |||
2081 | 112 | md::SimpleDispatchThread::SimpleDispatchThread( | ||
2082 | 113 | std::shared_ptr<md::Dispatchable> const& dispatchee, | ||
2083 | 114 | std::function<void()> const& exception_handler) | ||
2084 | 115 | { | ||
2085 | 116 | int pipefds[2]; | ||
2086 | 117 | if (pipe(pipefds) < 0) | ||
2087 | 118 | { | ||
2088 | 119 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2089 | 120 | std::system_category(), | ||
2090 | 121 | "Failed to create shutdown pipe for IO thread"})); | ||
2091 | 122 | } | ||
2092 | 123 | shutdown_fd = mir::Fd{pipefds[1]}; | ||
2093 | 124 | mir::Fd const terminate_fd = mir::Fd{pipefds[0]}; | ||
2094 | 125 | { | ||
2095 | 126 | // The newly spawned thread inherits the current signal mask; block everything | ||
2096 | 127 | // before creating the new thread so that there's no race between thread start | ||
2097 | 128 | // and signal blocking. | ||
2098 | 129 | mir::SignalBlocker block_signals; | ||
2099 | 130 | eventloop = std::thread{ | ||
2100 | 131 | [exception_handler, dispatchee, terminate_fd]() | ||
2101 | 132 | { | ||
2102 | 133 | try | ||
2103 | 134 | { | ||
2104 | 135 | wait_for_events_forever(dispatchee, terminate_fd); | ||
2105 | 136 | } | ||
2106 | 137 | catch(...) | ||
2107 | 138 | { | ||
2108 | 139 | exception_handler(); | ||
2109 | 140 | } | ||
2110 | 141 | }}; | ||
2111 | 142 | } | ||
2112 | 143 | } | ||
2113 | 144 | |||
2114 | 145 | md::SimpleDispatchThread::~SimpleDispatchThread() noexcept | ||
2115 | 146 | { | ||
2116 | 147 | shutdown_fd = mir::Fd{}; | ||
2117 | 148 | if (eventloop.get_id() == std::this_thread::get_id()) | ||
2118 | 149 | { | ||
2119 | 150 | // We're being destroyed from within the dispatch callback | ||
2120 | 151 | // Attempting to join the eventloop will result in a trivial deadlock. | ||
2121 | 152 | // | ||
2122 | 153 | // The std::thread destructor will call std::terminate() for us, let's | ||
2123 | 154 | // leave a useful message. | ||
2124 | 155 | mir::logging::log(mir::logging::Severity::critical, | ||
2125 | 156 | "Destroying SimpleDispatchThread from within a dispatch callback. This is a programming error.", | ||
2126 | 157 | "Dispatch"); | ||
2127 | 158 | } | ||
2128 | 159 | else if (eventloop.joinable()) | ||
2129 | 160 | { | ||
2130 | 161 | eventloop.join(); | ||
2131 | 162 | } | ||
2132 | 163 | } | ||
2133 | 164 | 0 | ||
2134 | === added file 'src/common/dispatch/threaded_dispatcher.cpp' | |||
2135 | --- src/common/dispatch/threaded_dispatcher.cpp 1970-01-01 00:00:00 +0000 | |||
2136 | +++ src/common/dispatch/threaded_dispatcher.cpp 2015-05-14 07:50:26 +0000 | |||
2137 | @@ -0,0 +1,294 @@ | |||
2138 | 1 | /* | ||
2139 | 2 | * Copyright © 2015 Canonical Ltd. | ||
2140 | 3 | * | ||
2141 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2142 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
2143 | 6 | * as published by the Free Software Foundation. | ||
2144 | 7 | * | ||
2145 | 8 | * This program is distributed in the hope that it will be useful, | ||
2146 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2147 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2148 | 11 | * GNU Lesser General Public License for more details. | ||
2149 | 12 | * | ||
2150 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2151 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2152 | 15 | * | ||
2153 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
2154 | 17 | */ | ||
2155 | 18 | |||
2156 | 19 | #include "mir/dispatch/threaded_dispatcher.h" | ||
2157 | 20 | #include "mir/dispatch/dispatchable.h" | ||
2158 | 21 | #include "mir/thread_name.h" | ||
2159 | 22 | |||
2160 | 23 | #include "mir/raii.h" | ||
2161 | 24 | #include "mir/logging/logger.h" | ||
2162 | 25 | |||
2163 | 26 | #include <fcntl.h> | ||
2164 | 27 | #include <poll.h> | ||
2165 | 28 | #include <unistd.h> | ||
2166 | 29 | #include <system_error> | ||
2167 | 30 | #include <signal.h> | ||
2168 | 31 | #include <boost/exception/all.hpp> | ||
2169 | 32 | #include <algorithm> | ||
2170 | 33 | #include <unordered_map> | ||
2171 | 34 | #include <sys/eventfd.h> | ||
2172 | 35 | |||
2173 | 36 | namespace md = mir::dispatch; | ||
2174 | 37 | |||
2175 | 38 | class md::ThreadedDispatcher::ThreadShutdownRequestHandler : public md::Dispatchable | ||
2176 | 39 | { | ||
2177 | 40 | public: | ||
2178 | 41 | ThreadShutdownRequestHandler() | ||
2179 | 42 | : event_semaphore{eventfd(0, EFD_CLOEXEC | EFD_SEMAPHORE)}, | ||
2180 | 43 | shutting_down{false} | ||
2181 | 44 | { | ||
2182 | 45 | if (event_semaphore == mir::Fd::invalid) | ||
2183 | 46 | { | ||
2184 | 47 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2185 | 48 | std::system_category(), | ||
2186 | 49 | "Failed to create shutdown eventfd"})); | ||
2187 | 50 | } | ||
2188 | 51 | } | ||
2189 | 52 | |||
2190 | 53 | mir::Fd watch_fd() const override | ||
2191 | 54 | { | ||
2192 | 55 | return event_semaphore; | ||
2193 | 56 | } | ||
2194 | 57 | |||
2195 | 58 | bool dispatch(md::FdEvents events) override | ||
2196 | 59 | { | ||
2197 | 60 | if (events & md::FdEvent::error) | ||
2198 | 61 | { | ||
2199 | 62 | return false; | ||
2200 | 63 | } | ||
2201 | 64 | |||
2202 | 65 | eventfd_t dummy; | ||
2203 | 66 | if (eventfd_read(event_semaphore, &dummy) < 0) | ||
2204 | 67 | { | ||
2205 | 68 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2206 | 69 | std::system_category(), | ||
2207 | 70 | "Failed to clear shutdown notification"})); | ||
2208 | 71 | } | ||
2209 | 72 | std::lock_guard<decltype(running_flag_guard)> lock{running_flag_guard}; | ||
2210 | 73 | *running_flags.at(std::this_thread::get_id()) = false; | ||
2211 | 74 | |||
2212 | 75 | return true; | ||
2213 | 76 | } | ||
2214 | 77 | |||
2215 | 78 | md::FdEvents relevant_events() const override | ||
2216 | 79 | { | ||
2217 | 80 | return md::FdEvent::readable; | ||
2218 | 81 | } | ||
2219 | 82 | |||
2220 | 83 | std::thread::id terminate_one_thread() | ||
2221 | 84 | { | ||
2222 | 85 | // First we tell a thread to die, any thread... | ||
2223 | 86 | if (eventfd_write(event_semaphore, 1) < 0) | ||
2224 | 87 | { | ||
2225 | 88 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2226 | 89 | std::system_category(), | ||
2227 | 90 | "Failed to trigger thread shutdown"})); | ||
2228 | 91 | } | ||
2229 | 92 | |||
2230 | 93 | // ...now we wait for a thread to die and tell us its ID... | ||
2231 | 94 | // We wait for a surprisingly long time because our threads are potentially blocked | ||
2232 | 95 | // in client code that we don't control. | ||
2233 | 96 | // | ||
2234 | 97 | // If the client is entirely unresponsive for a whole minute, it deserves to die. | ||
2235 | 98 | std::unique_lock<decltype(terminating_thread_mutex)> lock{terminating_thread_mutex}; | ||
2236 | 99 | if (!thread_terminating.wait_for (lock, | ||
2237 | 100 | std::chrono::seconds{60}, | ||
2238 | 101 | [this]() { return !terminating_threads.empty(); })) | ||
2239 | 102 | { | ||
2240 | 103 | BOOST_THROW_EXCEPTION((std::runtime_error{"Thread failed to shutdown"})); | ||
2241 | 104 | } | ||
2242 | 105 | |||
2243 | 106 | auto killed_thread_id = terminating_threads.back(); | ||
2244 | 107 | terminating_threads.pop_back(); | ||
2245 | 108 | return killed_thread_id; | ||
2246 | 109 | } | ||
2247 | 110 | |||
2248 | 111 | void terminate_all_threads_async() | ||
2249 | 112 | { | ||
2250 | 113 | eventfd_t thread_count; | ||
2251 | 114 | { | ||
2252 | 115 | std::lock_guard<std::mutex> lock(running_flag_guard); | ||
2253 | 116 | thread_count = running_flags.size(); | ||
2254 | 117 | shutting_down = true; | ||
2255 | 118 | } | ||
2256 | 119 | if (eventfd_write(event_semaphore, thread_count) < 0) | ||
2257 | 120 | { | ||
2258 | 121 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2259 | 122 | std::system_category(), | ||
2260 | 123 | "Failed to trigger thread shutdown"})); | ||
2261 | 124 | } | ||
2262 | 125 | } | ||
2263 | 126 | |||
2264 | 127 | void register_thread(bool& run_flag) | ||
2265 | 128 | { | ||
2266 | 129 | std::lock_guard<decltype(running_flag_guard)> lock{running_flag_guard}; | ||
2267 | 130 | |||
2268 | 131 | running_flags[std::this_thread::get_id()] = &run_flag; | ||
2269 | 132 | if (shutting_down) | ||
2270 | 133 | { | ||
2271 | 134 | if (eventfd_write(event_semaphore, 1) < 0) | ||
2272 | 135 | { | ||
2273 | 136 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2274 | 137 | std::system_category(), | ||
2275 | 138 | "Failed to trigger thread shutdown"})); | ||
2276 | 139 | } | ||
2277 | 140 | } | ||
2278 | 141 | } | ||
2279 | 142 | |||
2280 | 143 | void unregister_thread() | ||
2281 | 144 | { | ||
2282 | 145 | { | ||
2283 | 146 | std::lock_guard<decltype(terminating_thread_mutex)> lock{terminating_thread_mutex}; | ||
2284 | 147 | terminating_threads.push_back(std::this_thread::get_id()); | ||
2285 | 148 | } | ||
2286 | 149 | thread_terminating.notify_one(); | ||
2287 | 150 | { | ||
2288 | 151 | std::lock_guard<decltype(running_flag_guard)> lock{running_flag_guard}; | ||
2289 | 152 | |||
2290 | 153 | if (running_flags.erase(std::this_thread::get_id()) != 1) | ||
2291 | 154 | { | ||
2292 | 155 | BOOST_THROW_EXCEPTION((std::logic_error{"Attempted to unregister a not-registered thread"})); | ||
2293 | 156 | } | ||
2294 | 157 | } | ||
2295 | 158 | } | ||
2296 | 159 | |||
2297 | 160 | private: | ||
2298 | 161 | mir::Fd event_semaphore; | ||
2299 | 162 | |||
2300 | 163 | std::mutex terminating_thread_mutex; | ||
2301 | 164 | std::condition_variable thread_terminating; | ||
2302 | 165 | std::vector<std::thread::id> terminating_threads; | ||
2303 | 166 | |||
2304 | 167 | std::mutex running_flag_guard; | ||
2305 | 168 | std::unordered_map<std::thread::id, bool*> running_flags; | ||
2306 | 169 | bool shutting_down; | ||
2307 | 170 | }; | ||
2308 | 171 | |||
2309 | 172 | md::ThreadedDispatcher::ThreadedDispatcher(std::string const& name, std::shared_ptr<Dispatchable> const& dispatchee) | ||
2310 | 173 | : ThreadedDispatcher(name, dispatchee, [](){ throw; }) | ||
2311 | 174 | { | ||
2312 | 175 | } | ||
2313 | 176 | |||
2314 | 177 | md::ThreadedDispatcher::ThreadedDispatcher(std::string const& name, | ||
2315 | 178 | std::shared_ptr<md::Dispatchable> const& dispatchee, | ||
2316 | 179 | std::function<void()> const& exception_handler) | ||
2317 | 180 | : name_base{name}, | ||
2318 | 181 | thread_exiter{std::make_shared<ThreadShutdownRequestHandler>()}, | ||
2319 | 182 | dispatcher{std::make_shared<MultiplexingDispatchable>()}, | ||
2320 | 183 | exception_handler{exception_handler} | ||
2321 | 184 | { | ||
2322 | 185 | |||
2323 | 186 | // We rely on exactly one thread at a time getting a shutdown message | ||
2324 | 187 | dispatcher->add_watch(thread_exiter, md::DispatchReentrancy::sequential); | ||
2325 | 188 | |||
2326 | 189 | // But our target dispatchable is welcome to be dispatched on as many threads | ||
2327 | 190 | // as desired. | ||
2328 | 191 | dispatcher->add_watch(dispatchee, md::DispatchReentrancy::reentrant); | ||
2329 | 192 | |||
2330 | 193 | threadpool.emplace_back(&dispatch_loop, name_base, thread_exiter, dispatcher, exception_handler); | ||
2331 | 194 | } | ||
2332 | 195 | |||
2333 | 196 | md::ThreadedDispatcher::~ThreadedDispatcher() noexcept | ||
2334 | 197 | { | ||
2335 | 198 | std::lock_guard<decltype(thread_pool_mutex)> lock{thread_pool_mutex}; | ||
2336 | 199 | |||
2337 | 200 | thread_exiter->terminate_all_threads_async(); | ||
2338 | 201 | |||
2339 | 202 | for (auto& thread : threadpool) | ||
2340 | 203 | { | ||
2341 | 204 | if (thread.get_id() == std::this_thread::get_id()) | ||
2342 | 205 | { | ||
2343 | 206 | // We're being destroyed from within the dispatch callback | ||
2344 | 207 | // Attempting to join the eventloop will result in a trivial deadlock. | ||
2345 | 208 | // | ||
2346 | 209 | // The std::thread destructor will call std::terminate() for us, let's | ||
2347 | 210 | // leave a useful message. | ||
2348 | 211 | mir::logging::log(mir::logging::Severity::critical, | ||
2349 | 212 | "Destroying ThreadedDispatcher from within a dispatch callback. This is a programming error.", | ||
2350 | 213 | "Dispatch"); | ||
2351 | 214 | } | ||
2352 | 215 | else | ||
2353 | 216 | { | ||
2354 | 217 | thread.join(); | ||
2355 | 218 | } | ||
2356 | 219 | } | ||
2357 | 220 | } | ||
2358 | 221 | |||
2359 | 222 | void md::ThreadedDispatcher::add_thread() | ||
2360 | 223 | { | ||
2361 | 224 | std::lock_guard<decltype(thread_pool_mutex)> lock{thread_pool_mutex}; | ||
2362 | 225 | threadpool.emplace_back(&dispatch_loop, name_base, thread_exiter, dispatcher, exception_handler); | ||
2363 | 226 | } | ||
2364 | 227 | |||
2365 | 228 | void md::ThreadedDispatcher::remove_thread() | ||
2366 | 229 | { | ||
2367 | 230 | auto terminated_thread_id = thread_exiter->terminate_one_thread(); | ||
2368 | 231 | |||
2369 | 232 | // Find that thread in our vector, join() it, then remove it. | ||
2370 | 233 | std::lock_guard<decltype(thread_pool_mutex)> threadpool_lock{thread_pool_mutex}; | ||
2371 | 234 | |||
2372 | 235 | auto dying_thread = std::find_if(threadpool.begin(), | ||
2373 | 236 | threadpool.end(), | ||
2374 | 237 | [this, &terminated_thread_id](std::thread const& candidate) | ||
2375 | 238 | { | ||
2376 | 239 | return candidate.get_id() == terminated_thread_id; | ||
2377 | 240 | }); | ||
2378 | 241 | dying_thread->join(); | ||
2379 | 242 | threadpool.erase(dying_thread); | ||
2380 | 243 | } | ||
2381 | 244 | |||
2382 | 245 | void md::ThreadedDispatcher::dispatch_loop(std::string const& name, | ||
2383 | 246 | std::shared_ptr<ThreadShutdownRequestHandler> thread_register, | ||
2384 | 247 | std::shared_ptr<Dispatchable> dispatcher, | ||
2385 | 248 | std::function<void()> const& exception_handler) | ||
2386 | 249 | { | ||
2387 | 250 | sigset_t all_signals; | ||
2388 | 251 | sigfillset(&all_signals); | ||
2389 | 252 | |||
2390 | 253 | if (auto error = pthread_sigmask(SIG_BLOCK, &all_signals, NULL)) | ||
2391 | 254 | BOOST_THROW_EXCEPTION((std::system_error{error, | ||
2392 | 255 | std::system_category(), | ||
2393 | 256 | "Failed to block signals on IO thread"})); | ||
2394 | 257 | |||
2395 | 258 | mir::set_thread_name(name); | ||
2396 | 259 | |||
2397 | 260 | // This does not have to be std::atomic<bool> because thread_register is guaranteed to | ||
2398 | 261 | // only ever be dispatch()ed from one thread at a time. | ||
2399 | 262 | bool running{true}; | ||
2400 | 263 | |||
2401 | 264 | auto thread_registrar = mir::raii::paired_calls( | ||
2402 | 265 | [&running, thread_register]() | ||
2403 | 266 | { | ||
2404 | 267 | thread_register->register_thread(running); | ||
2405 | 268 | }, | ||
2406 | 269 | [thread_register]() | ||
2407 | 270 | { | ||
2408 | 271 | thread_register->unregister_thread(); | ||
2409 | 272 | }); | ||
2410 | 273 | |||
2411 | 274 | try | ||
2412 | 275 | { | ||
2413 | 276 | struct pollfd waiter; | ||
2414 | 277 | waiter.fd = dispatcher->watch_fd(); | ||
2415 | 278 | waiter.events = POLL_IN; | ||
2416 | 279 | while (running) | ||
2417 | 280 | { | ||
2418 | 281 | if (poll(&waiter, 1, -1) < 0) | ||
2419 | 282 | { | ||
2420 | 283 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
2421 | 284 | std::system_category(), | ||
2422 | 285 | "Failed to wait for event"})); | ||
2423 | 286 | } | ||
2424 | 287 | dispatcher->dispatch(md::FdEvent::readable); | ||
2425 | 288 | } | ||
2426 | 289 | } | ||
2427 | 290 | catch(...) | ||
2428 | 291 | { | ||
2429 | 292 | exception_handler(); | ||
2430 | 293 | } | ||
2431 | 294 | } | ||
2432 | 0 | 295 | ||
2433 | === modified file 'src/common/symbols.map' | |||
2434 | --- src/common/symbols.map 2015-04-15 05:07:08 +0000 | |||
2435 | +++ src/common/symbols.map 2015-05-14 07:50:26 +0000 | |||
2436 | @@ -24,8 +24,10 @@ | |||
2437 | 24 | mir::dispatch::MultiplexingDispatchable::relevant_events*; | 24 | mir::dispatch::MultiplexingDispatchable::relevant_events*; |
2438 | 25 | mir::dispatch::MultiplexingDispatchable::remove_watch*; | 25 | mir::dispatch::MultiplexingDispatchable::remove_watch*; |
2439 | 26 | mir::dispatch::MultiplexingDispatchable::watch_fd*; | 26 | mir::dispatch::MultiplexingDispatchable::watch_fd*; |
2442 | 27 | mir::dispatch::SimpleDispatchThread::?SimpleDispatchThread*; | 27 | mir::dispatch::ThreadedDispatcher::?ThreadedDispatcher*; |
2443 | 28 | mir::dispatch::SimpleDispatchThread::SimpleDispatchThread*; | 28 | mir::dispatch::ThreadedDispatcher::ThreadedDispatcher*; |
2444 | 29 | mir::dispatch::ThreadedDispatcher::add_thread*; | ||
2445 | 30 | mir::dispatch::ThreadedDispatcher::remove_thread*; | ||
2446 | 29 | mir::Fd::Fd*; | 31 | mir::Fd::Fd*; |
2447 | 30 | mir::Fd::invalid*; | 32 | mir::Fd::invalid*; |
2448 | 31 | mir::Fd::operator*; | 33 | mir::Fd::operator*; |
2449 | @@ -73,7 +75,7 @@ | |||
2450 | 73 | typeinfo?for?mir::dispatch::ActionQueue; | 75 | typeinfo?for?mir::dispatch::ActionQueue; |
2451 | 74 | typeinfo?for?mir::dispatch::Dispatchable; | 76 | typeinfo?for?mir::dispatch::Dispatchable; |
2452 | 75 | typeinfo?for?mir::dispatch::MultiplexingDispatchable; | 77 | typeinfo?for?mir::dispatch::MultiplexingDispatchable; |
2454 | 76 | typeinfo?for?mir::dispatch::SimpleDispatchThread; | 78 | typeinfo?for?mir::dispatch::ThreadedDispatcher; |
2455 | 77 | typeinfo?for?mir::Fd; | 79 | typeinfo?for?mir::Fd; |
2456 | 78 | typeinfo?for?mir::geometry::Displacement; | 80 | typeinfo?for?mir::geometry::Displacement; |
2457 | 79 | typeinfo?for?mir::geometry::Length; | 81 | typeinfo?for?mir::geometry::Length; |
2458 | @@ -88,7 +90,7 @@ | |||
2459 | 88 | vtable?for?mir::dispatch::ActionQueue; | 90 | vtable?for?mir::dispatch::ActionQueue; |
2460 | 89 | vtable?for?mir::dispatch::Dispatchable; | 91 | vtable?for?mir::dispatch::Dispatchable; |
2461 | 90 | vtable?for?mir::dispatch::MultiplexingDispatchable; | 92 | vtable?for?mir::dispatch::MultiplexingDispatchable; |
2463 | 91 | vtable?for?mir::dispatch::SimpleDispatchThread; | 93 | vtable?for?mir::dispatch::ThreadedDispatcher; |
2464 | 92 | vtable?for?mir::Fd; | 94 | vtable?for?mir::Fd; |
2465 | 93 | vtable?for?mir::geometry::Displacement; | 95 | vtable?for?mir::geometry::Displacement; |
2466 | 94 | vtable?for?mir::geometry::Length; | 96 | vtable?for?mir::geometry::Length; |
2467 | 95 | 97 | ||
2468 | === modified file 'src/server/input/default_input_manager.cpp' | |||
2469 | --- src/server/input/default_input_manager.cpp 2015-05-05 13:46:29 +0000 | |||
2470 | +++ src/server/input/default_input_manager.cpp 2015-05-14 07:50:26 +0000 | |||
2471 | @@ -22,7 +22,7 @@ | |||
2472 | 22 | #include "mir/input/platform.h" | 22 | #include "mir/input/platform.h" |
2473 | 23 | #include "mir/dispatch/action_queue.h" | 23 | #include "mir/dispatch/action_queue.h" |
2474 | 24 | #include "mir/dispatch/multiplexing_dispatchable.h" | 24 | #include "mir/dispatch/multiplexing_dispatchable.h" |
2476 | 25 | #include "mir/dispatch/simple_dispatch_thread.h" | 25 | #include "mir/dispatch/threaded_dispatcher.h" |
2477 | 26 | 26 | ||
2478 | 27 | #include "mir/main_loop.h" | 27 | #include "mir/main_loop.h" |
2479 | 28 | #include "mir/thread_name.h" | 28 | #include "mir/thread_name.h" |
2480 | @@ -86,7 +86,6 @@ | |||
2481 | 86 | 86 | ||
2482 | 87 | queue->enqueue([this,weak_started_promise]() | 87 | queue->enqueue([this,weak_started_promise]() |
2483 | 88 | { | 88 | { |
2484 | 89 | mir::set_thread_name("Mir/InputReader"); | ||
2485 | 90 | for (auto const& platform : platforms) | 89 | for (auto const& platform : platforms) |
2486 | 91 | { | 90 | { |
2487 | 92 | platform->start(); | 91 | platform->start(); |
2488 | @@ -100,7 +99,8 @@ | |||
2489 | 100 | started_promise->set_value(); | 99 | started_promise->set_value(); |
2490 | 101 | }); | 100 | }); |
2491 | 102 | 101 | ||
2493 | 103 | input_thread = std::make_unique<dispatch::SimpleDispatchThread>( | 102 | input_thread = std::make_unique<dispatch::ThreadedDispatcher>( |
2494 | 103 | "Mir/InputReader", | ||
2495 | 104 | multiplexer, | 104 | multiplexer, |
2496 | 105 | [this,weak_started_promise]() | 105 | [this,weak_started_promise]() |
2497 | 106 | { | 106 | { |
2498 | 107 | 107 | ||
2499 | === modified file 'src/server/input/default_input_manager.h' | |||
2500 | --- src/server/input/default_input_manager.h 2015-05-01 14:47:55 +0000 | |||
2501 | +++ src/server/input/default_input_manager.h 2015-05-14 07:50:26 +0000 | |||
2502 | @@ -37,7 +37,7 @@ | |||
2503 | 37 | namespace dispatch | 37 | namespace dispatch |
2504 | 38 | { | 38 | { |
2505 | 39 | class MultiplexingDispatchable; | 39 | class MultiplexingDispatchable; |
2507 | 40 | class SimpleDispatchThread; | 40 | class ThreadedDispatcher; |
2508 | 41 | class ActionQueue; | 41 | class ActionQueue; |
2509 | 42 | } | 42 | } |
2510 | 43 | namespace input | 43 | namespace input |
2511 | @@ -65,7 +65,7 @@ | |||
2512 | 65 | std::shared_ptr<dispatch::MultiplexingDispatchable> const multiplexer; | 65 | std::shared_ptr<dispatch::MultiplexingDispatchable> const multiplexer; |
2513 | 66 | std::shared_ptr<input::android::InputReaderDispatchable> const legacy_dispatchable; | 66 | std::shared_ptr<input::android::InputReaderDispatchable> const legacy_dispatchable; |
2514 | 67 | std::shared_ptr<dispatch::ActionQueue> const queue; | 67 | std::shared_ptr<dispatch::ActionQueue> const queue; |
2516 | 68 | std::unique_ptr<dispatch::SimpleDispatchThread> input_thread; | 68 | std::unique_ptr<dispatch::ThreadedDispatcher> input_thread; |
2517 | 69 | 69 | ||
2518 | 70 | enum class State | 70 | enum class State |
2519 | 71 | { | 71 | { |
2520 | 72 | 72 | ||
2521 | === modified file 'tests/acceptance-tests/CMakeLists.txt' | |||
2522 | --- tests/acceptance-tests/CMakeLists.txt 2015-05-05 06:46:30 +0000 | |||
2523 | +++ tests/acceptance-tests/CMakeLists.txt 2015-05-14 07:50:26 +0000 | |||
2524 | @@ -2,6 +2,7 @@ | |||
2525 | 2 | 2 | ||
2526 | 3 | include_directories( | 3 | include_directories( |
2527 | 4 | ${CMAKE_SOURCE_DIR} | 4 | ${CMAKE_SOURCE_DIR} |
2528 | 5 | ${UMOCKDEV_INCLUDE_DIRS} | ||
2529 | 5 | ) | 6 | ) |
2530 | 6 | 7 | ||
2531 | 7 | set( | 8 | set( |
2532 | @@ -84,5 +85,5 @@ | |||
2533 | 84 | OFF) | 85 | OFF) |
2534 | 85 | 86 | ||
2535 | 86 | if (MIR_RUN_ACCEPTANCE_TESTS) | 87 | if (MIR_RUN_ACCEPTANCE_TESTS) |
2537 | 87 | mir_discover_tests(mir_acceptance_tests) | 88 | mir_discover_tests(mir_acceptance_tests LD_PRELOAD=libumockdev-preload.so.0 G_SLICE=always-malloc G_DEBUG=gc-friendly) |
2538 | 88 | endif (MIR_RUN_ACCEPTANCE_TESTS) | 89 | endif (MIR_RUN_ACCEPTANCE_TESTS) |
2539 | 89 | 90 | ||
2540 | === modified file 'tests/acceptance-tests/test_client_library.cpp' | |||
2541 | --- tests/acceptance-tests/test_client_library.cpp 2015-04-30 12:27:33 +0000 | |||
2542 | +++ tests/acceptance-tests/test_client_library.cpp 2015-05-14 07:50:26 +0000 | |||
2543 | @@ -24,6 +24,10 @@ | |||
2544 | 24 | #include "mir_test_framework/using_stub_client_platform.h" | 24 | #include "mir_test_framework/using_stub_client_platform.h" |
2545 | 25 | #include "mir_test_framework/any_surface.h" | 25 | #include "mir_test_framework/any_surface.h" |
2546 | 26 | #include "mir_test/validity_matchers.h" | 26 | #include "mir_test/validity_matchers.h" |
2547 | 27 | #include "mir_test/fd_utils.h" | ||
2548 | 28 | #include "mir_test_framework/udev_environment.h" | ||
2549 | 29 | #include "mir_test/signal.h" | ||
2550 | 30 | #include "mir_test/auto_unblock_thread.h" | ||
2551 | 27 | 31 | ||
2552 | 28 | #include "src/include/client/mir/client_buffer.h" | 32 | #include "src/include/client/mir/client_buffer.h" |
2553 | 29 | 33 | ||
2554 | @@ -37,6 +41,8 @@ | |||
2555 | 37 | #include <system/window.h> // for ANativeWindowBuffer AKA MirNativeBuffer | 41 | #include <system/window.h> // for ANativeWindowBuffer AKA MirNativeBuffer |
2556 | 38 | #endif | 42 | #endif |
2557 | 39 | 43 | ||
2558 | 44 | #include <boost/throw_exception.hpp> | ||
2559 | 45 | |||
2560 | 40 | #include <gtest/gtest.h> | 46 | #include <gtest/gtest.h> |
2561 | 41 | #include <gmock/gmock.h> | 47 | #include <gmock/gmock.h> |
2562 | 42 | #include <chrono> | 48 | #include <chrono> |
2563 | @@ -53,6 +59,8 @@ | |||
2564 | 53 | namespace mc = mir::compositor; | 59 | namespace mc = mir::compositor; |
2565 | 54 | namespace mcl = mir::client; | 60 | namespace mcl = mir::client; |
2566 | 55 | namespace mtf = mir_test_framework; | 61 | namespace mtf = mir_test_framework; |
2567 | 62 | namespace mt = mir::test; | ||
2568 | 63 | |||
2569 | 56 | namespace | 64 | namespace |
2570 | 57 | { | 65 | { |
2571 | 58 | struct ClientLibrary : mtf::HeadlessInProcessServer | 66 | struct ClientLibrary : mtf::HeadlessInProcessServer |
2572 | @@ -61,6 +69,12 @@ | |||
2573 | 61 | MirConnection* connection = nullptr; | 69 | MirConnection* connection = nullptr; |
2574 | 62 | MirSurface* surface = nullptr; | 70 | MirSurface* surface = nullptr; |
2575 | 63 | int buffers = 0; | 71 | int buffers = 0; |
2576 | 72 | mtf::UdevEnvironment mock_devices; | ||
2577 | 73 | |||
2578 | 74 | ClientLibrary() | ||
2579 | 75 | { | ||
2580 | 76 | mock_devices.add_standard_device("laptop-keyboard"); | ||
2581 | 77 | } | ||
2582 | 64 | 78 | ||
2583 | 65 | static void connection_callback(MirConnection* connection, void* context) | 79 | static void connection_callback(MirConnection* connection, void* context) |
2584 | 66 | { | 80 | { |
2585 | @@ -275,111 +289,6 @@ | |||
2586 | 275 | mir_connection_release(connection); | 289 | mir_connection_release(connection); |
2587 | 276 | } | 290 | } |
2588 | 277 | 291 | ||
2589 | 278 | TEST_F(ClientLibrary, can_set_surface_min_width) | ||
2590 | 279 | { | ||
2591 | 280 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2592 | 281 | |||
2593 | 282 | int const width = 640; | ||
2594 | 283 | int const height = 480; | ||
2595 | 284 | auto const format = mir_pixel_format_abgr_8888; | ||
2596 | 285 | auto const spec = | ||
2597 | 286 | mir_connection_create_spec_for_normal_surface(connection, width, height, format); | ||
2598 | 287 | |||
2599 | 288 | int const min_width = 480; | ||
2600 | 289 | EXPECT_TRUE(mir_surface_spec_set_min_width(spec, min_width)); | ||
2601 | 290 | |||
2602 | 291 | surface = mir_surface_create_sync(spec); | ||
2603 | 292 | mir_surface_spec_release(spec); | ||
2604 | 293 | mir_surface_release_sync(surface); | ||
2605 | 294 | mir_connection_release(connection); | ||
2606 | 295 | } | ||
2607 | 296 | |||
2608 | 297 | TEST_F(ClientLibrary, can_set_surface_min_height) | ||
2609 | 298 | { | ||
2610 | 299 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2611 | 300 | |||
2612 | 301 | int const width = 640; | ||
2613 | 302 | int const height = 480; | ||
2614 | 303 | auto const format = mir_pixel_format_abgr_8888; | ||
2615 | 304 | auto const spec = | ||
2616 | 305 | mir_connection_create_spec_for_normal_surface(connection, width, height, format); | ||
2617 | 306 | |||
2618 | 307 | int const min_height = 480; | ||
2619 | 308 | EXPECT_TRUE(mir_surface_spec_set_min_height(spec, min_height)); | ||
2620 | 309 | |||
2621 | 310 | surface = mir_surface_create_sync(spec); | ||
2622 | 311 | mir_surface_spec_release(spec); | ||
2623 | 312 | mir_surface_release_sync(surface); | ||
2624 | 313 | mir_connection_release(connection); | ||
2625 | 314 | } | ||
2626 | 315 | |||
2627 | 316 | TEST_F(ClientLibrary, can_set_surface_max_width) | ||
2628 | 317 | { | ||
2629 | 318 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2630 | 319 | |||
2631 | 320 | int const width = 640; | ||
2632 | 321 | int const height = 480; | ||
2633 | 322 | auto const format = mir_pixel_format_abgr_8888; | ||
2634 | 323 | auto const spec = | ||
2635 | 324 | mir_connection_create_spec_for_normal_surface(connection, width, height, format); | ||
2636 | 325 | |||
2637 | 326 | int const max_width = 1024; | ||
2638 | 327 | EXPECT_TRUE(mir_surface_spec_set_max_width(spec, max_width)); | ||
2639 | 328 | |||
2640 | 329 | surface = mir_surface_create_sync(spec); | ||
2641 | 330 | mir_surface_spec_release(spec); | ||
2642 | 331 | mir_surface_release_sync(surface); | ||
2643 | 332 | mir_connection_release(connection); | ||
2644 | 333 | } | ||
2645 | 334 | |||
2646 | 335 | TEST_F(ClientLibrary, can_set_surface_max_height) | ||
2647 | 336 | { | ||
2648 | 337 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2649 | 338 | |||
2650 | 339 | int const width = 640; | ||
2651 | 340 | int const height = 480; | ||
2652 | 341 | auto const format = mir_pixel_format_abgr_8888; | ||
2653 | 342 | auto const spec = | ||
2654 | 343 | mir_connection_create_spec_for_normal_surface(connection, width, height, format); | ||
2655 | 344 | |||
2656 | 345 | int const max_height = 1024; | ||
2657 | 346 | EXPECT_TRUE(mir_surface_spec_set_max_height(spec, max_height)); | ||
2658 | 347 | |||
2659 | 348 | surface = mir_surface_create_sync(spec); | ||
2660 | 349 | mir_surface_spec_release(spec); | ||
2661 | 350 | mir_surface_release_sync(surface); | ||
2662 | 351 | mir_connection_release(connection); | ||
2663 | 352 | } | ||
2664 | 353 | |||
2665 | 354 | TEST_F(ClientLibrary, min_size_respected_when_placing_surface) | ||
2666 | 355 | { | ||
2667 | 356 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2668 | 357 | |||
2669 | 358 | int const width = 6400; | ||
2670 | 359 | int const height = 4800; | ||
2671 | 360 | auto const format = mir_pixel_format_abgr_8888; | ||
2672 | 361 | auto const spec = | ||
2673 | 362 | mir_connection_create_spec_for_normal_surface(connection, width, height, format); | ||
2674 | 363 | |||
2675 | 364 | int const min_width = 4800; | ||
2676 | 365 | int const min_height = 3200; | ||
2677 | 366 | |||
2678 | 367 | mir_surface_spec_set_min_width(spec, min_width); | ||
2679 | 368 | mir_surface_spec_set_min_height(spec, min_height); | ||
2680 | 369 | surface = mir_surface_create_sync(spec); | ||
2681 | 370 | mir_surface_spec_release(spec); | ||
2682 | 371 | |||
2683 | 372 | auto const buffer_stream = mir_surface_get_buffer_stream(surface); | ||
2684 | 373 | |||
2685 | 374 | MirGraphicsRegion graphics_region; | ||
2686 | 375 | mir_buffer_stream_get_graphics_region(buffer_stream, &graphics_region); | ||
2687 | 376 | EXPECT_THAT(graphics_region.width, Ge(min_width)); | ||
2688 | 377 | EXPECT_THAT(graphics_region.height, Ge(min_height)); | ||
2689 | 378 | |||
2690 | 379 | mir_surface_release_sync(surface); | ||
2691 | 380 | mir_connection_release(connection); | ||
2692 | 381 | } | ||
2693 | 382 | |||
2694 | 383 | TEST_F(ClientLibrary, receives_surface_dpi_value) | 292 | TEST_F(ClientLibrary, receives_surface_dpi_value) |
2695 | 384 | { | 293 | { |
2696 | 385 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | 294 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
2697 | @@ -930,3 +839,320 @@ | |||
2698 | 930 | mir_surface_release_sync(surface); | 839 | mir_surface_release_sync(surface); |
2699 | 931 | mir_connection_release(connection); | 840 | mir_connection_release(connection); |
2700 | 932 | } | 841 | } |
2701 | 842 | |||
2702 | 843 | namespace | ||
2703 | 844 | { | ||
2704 | 845 | struct ThreadTrackingCallbacks | ||
2705 | 846 | { | ||
2706 | 847 | ThreadTrackingCallbacks() | ||
2707 | 848 | : client_thread{pthread_self()} | ||
2708 | 849 | { | ||
2709 | 850 | } | ||
2710 | 851 | |||
2711 | 852 | static void connection_ready(MirConnection* /*connection*/, void* ctx) | ||
2712 | 853 | { | ||
2713 | 854 | auto data = reinterpret_cast<ThreadTrackingCallbacks*>(ctx); | ||
2714 | 855 | EXPECT_EQ(pthread_self(), data->client_thread); | ||
2715 | 856 | data->connection_ready_called.raise(); | ||
2716 | 857 | } | ||
2717 | 858 | |||
2718 | 859 | static void event_delegate(MirSurface* /*surf*/, MirEvent const* event, void* ctx) | ||
2719 | 860 | { | ||
2720 | 861 | auto data = reinterpret_cast<ThreadTrackingCallbacks*>(ctx); | ||
2721 | 862 | |||
2722 | 863 | EXPECT_THAT(pthread_self(), Eq(data->client_thread)); | ||
2723 | 864 | data->event_received.raise(); | ||
2724 | 865 | if (mir_event_get_type(event) == mir_event_type_input) | ||
2725 | 866 | { | ||
2726 | 867 | data->input_event_received.raise(); | ||
2727 | 868 | } | ||
2728 | 869 | } | ||
2729 | 870 | |||
2730 | 871 | static void surface_created(MirSurface* surf, void* ctx) | ||
2731 | 872 | { | ||
2732 | 873 | auto data = reinterpret_cast<ThreadTrackingCallbacks*>(ctx); | ||
2733 | 874 | EXPECT_THAT(pthread_self(), Eq(data->client_thread)); | ||
2734 | 875 | data->surf = surf; | ||
2735 | 876 | |||
2736 | 877 | mir_surface_set_event_handler(data->surf, &ThreadTrackingCallbacks::event_delegate, data); | ||
2737 | 878 | } | ||
2738 | 879 | |||
2739 | 880 | static void swap_buffers_complete(MirBufferStream* /*stream*/, void* ctx) | ||
2740 | 881 | { | ||
2741 | 882 | auto data = reinterpret_cast<ThreadTrackingCallbacks*>(ctx); | ||
2742 | 883 | EXPECT_EQ(pthread_self(), data->client_thread); | ||
2743 | 884 | data->buffers_swapped.raise(); | ||
2744 | 885 | } | ||
2745 | 886 | |||
2746 | 887 | pthread_t const client_thread; | ||
2747 | 888 | MirSurface* surf{nullptr}; | ||
2748 | 889 | mt::Signal buffers_swapped; | ||
2749 | 890 | mt::Signal connection_ready_called; | ||
2750 | 891 | mt::Signal event_received; | ||
2751 | 892 | mt::Signal input_event_received; | ||
2752 | 893 | }; | ||
2753 | 894 | |||
2754 | 895 | void pump_eventloop_until(MirConnection* connection, std::function<bool()> predicate, std::chrono::steady_clock::time_point timeout) | ||
2755 | 896 | { | ||
2756 | 897 | using namespace std::literals::chrono_literals; | ||
2757 | 898 | |||
2758 | 899 | auto fd = mir::Fd{mir::IntOwnedFd{mir_connection_get_event_fd(connection)}}; | ||
2759 | 900 | |||
2760 | 901 | while (!predicate() && (std::chrono::steady_clock::now() < timeout)) | ||
2761 | 902 | { | ||
2762 | 903 | if (mt::fd_becomes_readable(fd, 10ms)) | ||
2763 | 904 | { | ||
2764 | 905 | mir_connection_dispatch(connection); | ||
2765 | 906 | } | ||
2766 | 907 | } | ||
2767 | 908 | if (!predicate()) | ||
2768 | 909 | { | ||
2769 | 910 | BOOST_THROW_EXCEPTION((std::runtime_error{"Timeout waiting for state change"})); | ||
2770 | 911 | } | ||
2771 | 912 | } | ||
2772 | 913 | } | ||
2773 | 914 | |||
2774 | 915 | TEST_F(ClientLibrary, manual_dispatch_handles_callbacks_in_parent_thread) | ||
2775 | 916 | { | ||
2776 | 917 | using namespace std::literals::chrono_literals; | ||
2777 | 918 | |||
2778 | 919 | auto const test_timeout = std::chrono::steady_clock::now() + 10min; | ||
2779 | 920 | |||
2780 | 921 | ThreadTrackingCallbacks data; | ||
2781 | 922 | |||
2782 | 923 | auto connection = mir_connect_with_manual_dispatch(new_connection().c_str(), __PRETTY_FUNCTION__, &ThreadTrackingCallbacks::connection_ready, &data); | ||
2783 | 924 | |||
2784 | 925 | ASSERT_THAT(connection, Ne(nullptr)); | ||
2785 | 926 | |||
2786 | 927 | pump_eventloop_until( | ||
2787 | 928 | connection, | ||
2788 | 929 | [&data]() | ||
2789 | 930 | { | ||
2790 | 931 | return data.connection_ready_called.raised(); | ||
2791 | 932 | }, | ||
2792 | 933 | test_timeout); | ||
2793 | 934 | |||
2794 | 935 | ASSERT_THAT(connection, IsValid()); | ||
2795 | 936 | |||
2796 | 937 | auto surface_spec = mir_connection_create_spec_for_normal_surface(connection, | ||
2797 | 938 | 233, 355, | ||
2798 | 939 | mir_pixel_format_argb_8888); | ||
2799 | 940 | auto surf_wh = mir_surface_create(surface_spec, | ||
2800 | 941 | &ThreadTrackingCallbacks::surface_created, | ||
2801 | 942 | &data); | ||
2802 | 943 | mir_surface_spec_release(surface_spec); | ||
2803 | 944 | |||
2804 | 945 | pump_eventloop_until( | ||
2805 | 946 | connection, | ||
2806 | 947 | [surf_wh]() | ||
2807 | 948 | { | ||
2808 | 949 | return mir_wait_handle_ready(surf_wh); | ||
2809 | 950 | }, | ||
2810 | 951 | test_timeout); | ||
2811 | 952 | |||
2812 | 953 | EXPECT_THAT(data.surf, IsValid()); | ||
2813 | 954 | |||
2814 | 955 | auto buffer_stream = mir_surface_get_buffer_stream(data.surf); | ||
2815 | 956 | auto swap_wh = mir_buffer_stream_swap_buffers(buffer_stream, ThreadTrackingCallbacks::swap_buffers_complete, &data); | ||
2816 | 957 | |||
2817 | 958 | pump_eventloop_until( | ||
2818 | 959 | connection, | ||
2819 | 960 | [swap_wh]() | ||
2820 | 961 | { | ||
2821 | 962 | return mir_wait_handle_ready(swap_wh); | ||
2822 | 963 | }, | ||
2823 | 964 | test_timeout); | ||
2824 | 965 | EXPECT_TRUE(data.buffers_swapped.raised()); | ||
2825 | 966 | |||
2826 | 967 | mir_surface_release_sync(data.surf); | ||
2827 | 968 | mir_connection_release(connection); | ||
2828 | 969 | } | ||
2829 | 970 | |||
2830 | 971 | TEST_F(ClientLibrary, manual_dispatch_handles_events_in_parent_thread) | ||
2831 | 972 | { | ||
2832 | 973 | using namespace testing; | ||
2833 | 974 | using namespace std::literals::chrono_literals; | ||
2834 | 975 | |||
2835 | 976 | auto const test_timeout = std::chrono::steady_clock::now() + 10min; | ||
2836 | 977 | |||
2837 | 978 | ThreadTrackingCallbacks data; | ||
2838 | 979 | |||
2839 | 980 | connection = mir_connect_with_manual_dispatch(new_connection().c_str(), __PRETTY_FUNCTION__, &ThreadTrackingCallbacks::connection_ready, &data); | ||
2840 | 981 | |||
2841 | 982 | ASSERT_THAT(connection, Ne(nullptr)); | ||
2842 | 983 | |||
2843 | 984 | pump_eventloop_until( | ||
2844 | 985 | connection, | ||
2845 | 986 | [&data]() | ||
2846 | 987 | { | ||
2847 | 988 | return data.connection_ready_called.raised(); | ||
2848 | 989 | }, | ||
2849 | 990 | test_timeout); | ||
2850 | 991 | |||
2851 | 992 | ASSERT_THAT(connection, IsValid()); | ||
2852 | 993 | |||
2853 | 994 | auto surface_spec = mir_connection_create_spec_for_normal_surface(connection, | ||
2854 | 995 | 233, 355, | ||
2855 | 996 | mir_pixel_format_argb_8888); | ||
2856 | 997 | auto surf_wh = mir_surface_create(surface_spec, | ||
2857 | 998 | &ThreadTrackingCallbacks::surface_created, | ||
2858 | 999 | &data); | ||
2859 | 1000 | mir_surface_spec_release(surface_spec); | ||
2860 | 1001 | |||
2861 | 1002 | |||
2862 | 1003 | pump_eventloop_until( | ||
2863 | 1004 | connection, | ||
2864 | 1005 | [surf_wh]() | ||
2865 | 1006 | { | ||
2866 | 1007 | return mir_wait_handle_ready(surf_wh); | ||
2867 | 1008 | }, | ||
2868 | 1009 | test_timeout); | ||
2869 | 1010 | |||
2870 | 1011 | EXPECT_THAT(data.surf, IsValid()); | ||
2871 | 1012 | |||
2872 | 1013 | // We need to swap buffers so that the surface is fully realised and | ||
2873 | 1014 | // will be a valid focus target. | ||
2874 | 1015 | // | ||
2875 | 1016 | // The shell will not focus a surface with no content. | ||
2876 | 1017 | auto buffer_stream = mir_surface_get_buffer_stream(data.surf); | ||
2877 | 1018 | mir_buffer_stream_swap_buffers_sync(buffer_stream); | ||
2878 | 1019 | |||
2879 | 1020 | mir_surface_set_state(data.surf, mir_surface_state_fullscreen); | ||
2880 | 1021 | |||
2881 | 1022 | pump_eventloop_until( | ||
2882 | 1023 | connection, | ||
2883 | 1024 | [&data]() | ||
2884 | 1025 | { | ||
2885 | 1026 | return data.event_received.raised(); | ||
2886 | 1027 | }, | ||
2887 | 1028 | test_timeout); | ||
2888 | 1029 | |||
2889 | 1030 | ASSERT_THAT(mir_surface_get_focus(data.surf), Eq(mir_surface_focused)); | ||
2890 | 1031 | |||
2891 | 1032 | mock_devices.load_device_evemu("laptop-keyboard-hello"); | ||
2892 | 1033 | |||
2893 | 1034 | pump_eventloop_until( | ||
2894 | 1035 | connection, | ||
2895 | 1036 | [&data]() | ||
2896 | 1037 | { | ||
2897 | 1038 | return data.input_event_received.raised(); | ||
2898 | 1039 | }, | ||
2899 | 1040 | test_timeout); | ||
2900 | 1041 | |||
2901 | 1042 | mir_surface_release_sync(data.surf); | ||
2902 | 1043 | mir_connection_release(connection); | ||
2903 | 1044 | } | ||
2904 | 1045 | |||
2905 | 1046 | namespace | ||
2906 | 1047 | { | ||
2907 | 1048 | struct SignalPair | ||
2908 | 1049 | { | ||
2909 | 1050 | mir::test::Signal now_blocking; | ||
2910 | 1051 | mir::test::Signal event_received; | ||
2911 | 1052 | }; | ||
2912 | 1053 | |||
2913 | 1054 | void notifying_event_handler(MirSurface*, MirEvent const* ev, void* ctx) | ||
2914 | 1055 | { | ||
2915 | 1056 | auto signal_pair = *reinterpret_cast<std::shared_ptr<SignalPair>*>(ctx); | ||
2916 | 1057 | // We trigger an input event once we've noticed the surface callback is blocking | ||
2917 | 1058 | // so we need to only raise the flag on an input event; otherwise we may spuriously | ||
2918 | 1059 | // fail if we receive a surface event (like the focus event) before we hit | ||
2919 | 1060 | // the wait in blocking_surface_callback() | ||
2920 | 1061 | if (mir_event_get_type(ev) == mir_event_type_input) | ||
2921 | 1062 | { | ||
2922 | 1063 | signal_pair->event_received.raise(); | ||
2923 | 1064 | } | ||
2924 | 1065 | } | ||
2925 | 1066 | |||
2926 | 1067 | void blocking_buffer_stream_callback(MirBufferStream*, void* ctx) | ||
2927 | 1068 | { | ||
2928 | 1069 | auto signal_pair = *reinterpret_cast<std::shared_ptr<SignalPair>*>(ctx); | ||
2929 | 1070 | signal_pair->now_blocking.raise(); | ||
2930 | 1071 | EXPECT_TRUE(signal_pair->event_received.wait_for(std::chrono::seconds{5})); | ||
2931 | 1072 | } | ||
2932 | 1073 | } | ||
2933 | 1074 | |||
2934 | 1075 | TEST_F(ClientLibrary, rpc_blocking_doesnt_block_event_delivery_with_auto_dispatch) | ||
2935 | 1076 | { | ||
2936 | 1077 | using namespace testing; | ||
2937 | 1078 | |||
2938 | 1079 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
2939 | 1080 | |||
2940 | 1081 | ASSERT_THAT(connection, IsValid()); | ||
2941 | 1082 | |||
2942 | 1083 | auto surface_spec = mir_connection_create_spec_for_normal_surface(connection, | ||
2943 | 1084 | 233, 355, | ||
2944 | 1085 | mir_pixel_format_argb_8888); | ||
2945 | 1086 | |||
2946 | 1087 | auto surf = mir_surface_create_sync(surface_spec); | ||
2947 | 1088 | mir_surface_spec_release(surface_spec); | ||
2948 | 1089 | |||
2949 | 1090 | EXPECT_THAT(surf, IsValid()); | ||
2950 | 1091 | |||
2951 | 1092 | auto signal_pair = std::make_shared<SignalPair>(); | ||
2952 | 1093 | mir_surface_set_event_handler(surf, ¬ifying_event_handler, &signal_pair); | ||
2953 | 1094 | |||
2954 | 1095 | auto buffer_stream = mir_surface_get_buffer_stream(surf); | ||
2955 | 1096 | auto wh = mir_buffer_stream_swap_buffers(buffer_stream, &blocking_buffer_stream_callback, &signal_pair); | ||
2956 | 1097 | |||
2957 | 1098 | EXPECT_TRUE(signal_pair->now_blocking.wait_for(std::chrono::seconds{5})); | ||
2958 | 1099 | EXPECT_FALSE(signal_pair->event_received.raised()); | ||
2959 | 1100 | |||
2960 | 1101 | mock_devices.load_device_evemu("laptop-keyboard-hello"); | ||
2961 | 1102 | |||
2962 | 1103 | EXPECT_TRUE(signal_pair->event_received.wait_for(std::chrono::seconds{5})); | ||
2963 | 1104 | |||
2964 | 1105 | mir_wait_for(wh); | ||
2965 | 1106 | mir_surface_release_sync(surf); | ||
2966 | 1107 | mir_connection_release(connection); | ||
2967 | 1108 | } | ||
2968 | 1109 | |||
2969 | 1110 | namespace | ||
2970 | 1111 | { | ||
2971 | 1112 | void async_release_completed(MirSurface*, void* ctx) | ||
2972 | 1113 | { | ||
2973 | 1114 | auto called = reinterpret_cast<bool*>(ctx); | ||
2974 | 1115 | *called = true; | ||
2975 | 1116 | } | ||
2976 | 1117 | |||
2977 | 1118 | void async_creation_completed(MirSurface* surf, void* ctx) | ||
2978 | 1119 | { | ||
2979 | 1120 | mir_surface_release(surf, &async_release_completed, ctx); | ||
2980 | 1121 | } | ||
2981 | 1122 | } | ||
2982 | 1123 | |||
2983 | 1124 | TEST_F(ClientLibrary, sync_call_completes_before_previous_undispatched_call) | ||
2984 | 1125 | { | ||
2985 | 1126 | using namespace std::literals::chrono_literals; | ||
2986 | 1127 | using namespace testing; | ||
2987 | 1128 | |||
2988 | 1129 | auto timeout = std::chrono::steady_clock::now() + 60s; | ||
2989 | 1130 | |||
2990 | 1131 | ThreadTrackingCallbacks data; | ||
2991 | 1132 | |||
2992 | 1133 | auto connection = mir_connect_with_manual_dispatch(new_connection().c_str(), __PRETTY_FUNCTION__, &ThreadTrackingCallbacks::connection_ready, &data); | ||
2993 | 1134 | ASSERT_THAT(connection, Ne(nullptr)); | ||
2994 | 1135 | |||
2995 | 1136 | pump_eventloop_until(connection, [connection]() { return mir_connection_is_valid(connection); }, timeout); | ||
2996 | 1137 | |||
2997 | 1138 | bool async_call_completed{false}; | ||
2998 | 1139 | |||
2999 | 1140 | auto surface_spec = mir_connection_create_spec_for_normal_surface(connection, | ||
3000 | 1141 | 233, 355, | ||
3001 | 1142 | mir_pixel_format_argb_8888); | ||
3002 | 1143 | mir_surface_create(surface_spec, &async_creation_completed, &async_call_completed); | ||
3003 | 1144 | |||
3004 | 1145 | EXPECT_FALSE(async_call_completed); | ||
3005 | 1146 | auto surf = mir_surface_create_sync(surface_spec); | ||
3006 | 1147 | mir_surface_spec_release(surface_spec); | ||
3007 | 1148 | |||
3008 | 1149 | EXPECT_THAT(surf, IsValid()); | ||
3009 | 1150 | EXPECT_FALSE(async_call_completed); | ||
3010 | 1151 | |||
3011 | 1152 | mir_surface_release_sync(surf); | ||
3012 | 1153 | EXPECT_FALSE(async_call_completed); | ||
3013 | 1154 | |||
3014 | 1155 | pump_eventloop_until(connection, [&async_call_completed]() { return async_call_completed;}, timeout); | ||
3015 | 1156 | |||
3016 | 1157 | mir_connection_release(connection); | ||
3017 | 1158 | } | ||
3018 | 933 | 1159 | ||
3019 | === modified file 'tests/include/mir_test/test_protobuf_client.h' | |||
3020 | --- tests/include/mir_test/test_protobuf_client.h 2015-03-31 02:35:42 +0000 | |||
3021 | +++ tests/include/mir_test/test_protobuf_client.h 2015-05-14 07:50:26 +0000 | |||
3022 | @@ -32,7 +32,7 @@ | |||
3023 | 32 | { | 32 | { |
3024 | 33 | namespace dispatch | 33 | namespace dispatch |
3025 | 34 | { | 34 | { |
3027 | 35 | class SimpleDispatchThread; | 35 | class ThreadedDispatcher; |
3028 | 36 | } | 36 | } |
3029 | 37 | namespace test | 37 | namespace test |
3030 | 38 | { | 38 | { |
3031 | @@ -46,7 +46,7 @@ | |||
3032 | 46 | 46 | ||
3033 | 47 | std::shared_ptr<doubles::MockRpcReport> rpc_report; | 47 | std::shared_ptr<doubles::MockRpcReport> rpc_report; |
3034 | 48 | std::shared_ptr<google::protobuf::RpcChannel> channel; | 48 | std::shared_ptr<google::protobuf::RpcChannel> channel; |
3036 | 49 | std::shared_ptr<dispatch::SimpleDispatchThread> eventloop; | 49 | std::shared_ptr<dispatch::ThreadedDispatcher> eventloop; |
3037 | 50 | mir::protobuf::DisplayServer::Stub display_server; | 50 | mir::protobuf::DisplayServer::Stub display_server; |
3038 | 51 | mir::protobuf::ConnectParameters connect_parameters; | 51 | mir::protobuf::ConnectParameters connect_parameters; |
3039 | 52 | mir::protobuf::SurfaceParameters surface_parameters; | 52 | mir::protobuf::SurfaceParameters surface_parameters; |
3040 | 53 | 53 | ||
3041 | === modified file 'tests/include/mir_test_doubles/mock_client_buffer_stream.h' | |||
3042 | --- tests/include/mir_test_doubles/mock_client_buffer_stream.h 2015-04-01 20:00:19 +0000 | |||
3043 | +++ tests/include/mir_test_doubles/mock_client_buffer_stream.h 2015-05-14 07:50:26 +0000 | |||
3044 | @@ -45,6 +45,7 @@ | |||
3045 | 45 | MOCK_METHOD0(get_create_wait_handle, MirWaitHandle*(void)); | 45 | MOCK_METHOD0(get_create_wait_handle, MirWaitHandle*(void)); |
3046 | 46 | MOCK_CONST_METHOD0(rpc_id, frontend::BufferStreamId(void)); | 46 | MOCK_CONST_METHOD0(rpc_id, frontend::BufferStreamId(void)); |
3047 | 47 | MOCK_CONST_METHOD0(valid, bool(void)); | 47 | MOCK_CONST_METHOD0(valid, bool(void)); |
3048 | 48 | MOCK_CONST_METHOD0(get_connection, MirConnection*()); | ||
3049 | 48 | }; | 49 | }; |
3050 | 49 | 50 | ||
3051 | 50 | } | 51 | } |
3052 | 51 | 52 | ||
3053 | === modified file 'tests/include/mir_test_doubles/mock_client_buffer_stream_factory.h' | |||
3054 | --- tests/include/mir_test_doubles/mock_client_buffer_stream_factory.h 2015-04-21 17:22:09 +0000 | |||
3055 | +++ tests/include/mir_test_doubles/mock_client_buffer_stream_factory.h 2015-05-14 07:50:26 +0000 | |||
3056 | @@ -34,12 +34,22 @@ | |||
3057 | 34 | 34 | ||
3058 | 35 | struct MockClientBufferStreamFactory : public client::ClientBufferStreamFactory | 35 | struct MockClientBufferStreamFactory : public client::ClientBufferStreamFactory |
3059 | 36 | { | 36 | { |
3066 | 37 | MOCK_METHOD3(make_consumer_stream, std::shared_ptr<client::ClientBufferStream>(protobuf::DisplayServer&, | 37 | MOCK_METHOD4(make_consumer_stream, std::shared_ptr<client::ClientBufferStream>( |
3067 | 38 | protobuf::BufferStream const&, std::string const&)); | 38 | MirConnection*, |
3068 | 39 | MOCK_METHOD3(make_producer_stream, std::shared_ptr<client::ClientBufferStream>(protobuf::DisplayServer&, | 39 | protobuf::DisplayServer&, |
3069 | 40 | protobuf::BufferStream const&, std::string const&)); | 40 | protobuf::BufferStream const&, |
3070 | 41 | MOCK_METHOD4(make_producer_stream, client::ClientBufferStream*(protobuf::DisplayServer&, | 41 | std::string const&)); |
3071 | 42 | protobuf::BufferStreamParameters const&, mir_buffer_stream_callback callback, void* context)); | 42 | MOCK_METHOD4(make_producer_stream, std::shared_ptr<client::ClientBufferStream>( |
3072 | 43 | MirConnection*, | ||
3073 | 44 | protobuf::DisplayServer&, | ||
3074 | 45 | protobuf::BufferStream const&, | ||
3075 | 46 | std::string const&)); | ||
3076 | 47 | MOCK_METHOD5(make_producer_stream, client::ClientBufferStream*( | ||
3077 | 48 | MirConnection*, | ||
3078 | 49 | protobuf::DisplayServer&, | ||
3079 | 50 | protobuf::BufferStreamParameters const&, | ||
3080 | 51 | mir_buffer_stream_callback callback, | ||
3081 | 52 | void* context)); | ||
3082 | 43 | }; | 53 | }; |
3083 | 44 | 54 | ||
3084 | 45 | } | 55 | } |
3085 | 46 | 56 | ||
3086 | === modified file 'tests/include/mir_test_doubles/stub_client_buffer_stream_factory.h' | |||
3087 | --- tests/include/mir_test_doubles/stub_client_buffer_stream_factory.h 2015-04-01 20:00:19 +0000 | |||
3088 | +++ tests/include/mir_test_doubles/stub_client_buffer_stream_factory.h 2015-05-14 07:50:26 +0000 | |||
3089 | @@ -32,6 +32,7 @@ | |||
3090 | 32 | struct StubClientBufferStreamFactory : public client::ClientBufferStreamFactory | 32 | struct StubClientBufferStreamFactory : public client::ClientBufferStreamFactory |
3091 | 33 | { | 33 | { |
3092 | 34 | std::shared_ptr<client::ClientBufferStream> make_consumer_stream( | 34 | std::shared_ptr<client::ClientBufferStream> make_consumer_stream( |
3093 | 35 | MirConnection* /* allocating_connection */, | ||
3094 | 35 | protobuf::DisplayServer& /* server */, | 36 | protobuf::DisplayServer& /* server */, |
3095 | 36 | protobuf::BufferStream const& /* protobuf_bs */, | 37 | protobuf::BufferStream const& /* protobuf_bs */, |
3096 | 37 | std::string const& /* surface_name */) override | 38 | std::string const& /* surface_name */) override |
3097 | @@ -40,6 +41,7 @@ | |||
3098 | 40 | } | 41 | } |
3099 | 41 | 42 | ||
3100 | 42 | std::shared_ptr<client::ClientBufferStream> make_producer_stream( | 43 | std::shared_ptr<client::ClientBufferStream> make_producer_stream( |
3101 | 44 | MirConnection* /* allocating_connection */, | ||
3102 | 43 | protobuf::DisplayServer& /* server */, | 45 | protobuf::DisplayServer& /* server */, |
3103 | 44 | protobuf::BufferStream const& /* protobuf_bs */, | 46 | protobuf::BufferStream const& /* protobuf_bs */, |
3104 | 45 | std::string const& /* surface_name */) override | 47 | std::string const& /* surface_name */) override |
3105 | @@ -47,7 +49,9 @@ | |||
3106 | 47 | return nullptr; | 49 | return nullptr; |
3107 | 48 | } | 50 | } |
3108 | 49 | 51 | ||
3110 | 50 | client::ClientBufferStream* make_producer_stream(protobuf::DisplayServer& /* server */, | 52 | client::ClientBufferStream* make_producer_stream( |
3111 | 53 | MirConnection* /* allocating_connection */, | ||
3112 | 54 | protobuf::DisplayServer& /* server */, | ||
3113 | 51 | protobuf::BufferStreamParameters const& /* params */, | 55 | protobuf::BufferStreamParameters const& /* params */, |
3114 | 52 | mir_buffer_stream_callback /* callback */, void* /* context */) override | 56 | mir_buffer_stream_callback /* callback */, void* /* context */) override |
3115 | 53 | { | 57 | { |
3116 | 54 | 58 | ||
3117 | === modified file 'tests/include/mir_test_framework/udev_environment.h' | |||
3118 | --- tests/include/mir_test_framework/udev_environment.h 2015-01-21 07:34:50 +0000 | |||
3119 | +++ tests/include/mir_test_framework/udev_environment.h 2015-05-14 07:50:26 +0000 | |||
3120 | @@ -53,6 +53,32 @@ | |||
3121 | 53 | */ | 53 | */ |
3122 | 54 | void add_standard_device(std::string const& name); | 54 | void add_standard_device(std::string const& name); |
3123 | 55 | 55 | ||
3124 | 56 | /** | ||
3125 | 57 | * Load an ioctl recording for a UMockdev device | ||
3126 | 58 | * | ||
3127 | 59 | * Looks for a <tt>name</tt>.ioctl file recorded with umockdev-record --ioctl | ||
3128 | 60 | * and adds it to the associated device in the testbed. | ||
3129 | 61 | * | ||
3130 | 62 | * The udev records for the device these ioctl records will be associated with | ||
3131 | 63 | * must already exist in the testbed | ||
3132 | 64 | * | ||
3133 | 65 | * @param name The unadorned filename for the ioctl records to add | ||
3134 | 66 | */ | ||
3135 | 67 | void load_device_ioctls(std::string const& name); | ||
3136 | 68 | |||
3137 | 69 | /** | ||
3138 | 70 | * Load an evemu evdev recording for a UMockdev device | ||
3139 | 71 | * | ||
3140 | 72 | * Looks for a <tt>name</tt>.evemu file recorded with umockdev-record --evemu | ||
3141 | 73 | * (or evemu-record) and associates it with the udev device it was recorded from. | ||
3142 | 74 | * | ||
3143 | 75 | * The udev records for the device this recording is associated with | ||
3144 | 76 | * must already exist in the testbed | ||
3145 | 77 | * | ||
3146 | 78 | * @param name The unadorned filename for the ioctl records to add | ||
3147 | 79 | */ | ||
3148 | 80 | void load_device_evemu(std::string const& name); | ||
3149 | 81 | |||
3150 | 56 | UMockdevTestbed *testbed; | 82 | UMockdevTestbed *testbed; |
3151 | 57 | std::string const recordings_path; | 83 | std::string const recordings_path; |
3152 | 58 | }; | 84 | }; |
3153 | 59 | 85 | ||
3154 | === modified file 'tests/integration-tests/client/test_screencast.cpp' | |||
3155 | --- tests/integration-tests/client/test_screencast.cpp 2015-03-31 02:35:42 +0000 | |||
3156 | +++ tests/integration-tests/client/test_screencast.cpp 2015-05-14 07:50:26 +0000 | |||
3157 | @@ -18,7 +18,8 @@ | |||
3158 | 18 | 18 | ||
3159 | 19 | #include "mir_protobuf.pb.h" | 19 | #include "mir_protobuf.pb.h" |
3160 | 20 | #include "src/client/default_connection_configuration.h" | 20 | #include "src/client/default_connection_configuration.h" |
3162 | 21 | #include "mir/dispatch/simple_dispatch_thread.h" | 21 | #include "src/client/rpc/mir_basic_rpc_channel.h" |
3163 | 22 | #include "mir/dispatch/threaded_dispatcher.h" | ||
3164 | 22 | #include "mir/dispatch/dispatchable.h" | 23 | #include "mir/dispatch/dispatchable.h" |
3165 | 23 | 24 | ||
3166 | 24 | #include "mir/frontend/connector.h" | 25 | #include "mir/frontend/connector.h" |
3167 | @@ -78,16 +79,15 @@ | |||
3168 | 78 | protobuf_server = | 79 | protobuf_server = |
3169 | 79 | std::make_shared<mir::protobuf::DisplayServer::Stub>(rpc_channel.get()); | 80 | std::make_shared<mir::protobuf::DisplayServer::Stub>(rpc_channel.get()); |
3170 | 80 | eventloop = | 81 | eventloop = |
3173 | 81 | std::make_shared<md::SimpleDispatchThread>( | 82 | std::make_shared<md::ThreadedDispatcher>("I/O loop", rpc_channel); |
3172 | 82 | std::dynamic_pointer_cast<md::Dispatchable>(rpc_channel)); | ||
3174 | 83 | } | 83 | } |
3175 | 84 | 84 | ||
3176 | 85 | char const* const test_socket = "./test_socket_screencast"; | 85 | char const* const test_socket = "./test_socket_screencast"; |
3177 | 86 | std::shared_ptr<StubScreencastServerTool> const server_tool; | 86 | std::shared_ptr<StubScreencastServerTool> const server_tool; |
3178 | 87 | std::shared_ptr<mt::TestProtobufServer> test_server; | 87 | std::shared_ptr<mt::TestProtobufServer> test_server; |
3180 | 88 | std::shared_ptr<google::protobuf::RpcChannel> rpc_channel; | 88 | std::shared_ptr<mir::client::rpc::MirBasicRpcChannel> rpc_channel; |
3181 | 89 | std::shared_ptr<mir::protobuf::DisplayServer> protobuf_server; | 89 | std::shared_ptr<mir::protobuf::DisplayServer> protobuf_server; |
3183 | 90 | std::shared_ptr<mir::dispatch::SimpleDispatchThread> eventloop; | 90 | std::shared_ptr<mir::dispatch::ThreadedDispatcher> eventloop; |
3184 | 91 | }; | 91 | }; |
3185 | 92 | 92 | ||
3186 | 93 | } | 93 | } |
3187 | 94 | 94 | ||
3188 | === modified file 'tests/mir_test_doubles/test_protobuf_client.cpp' | |||
3189 | --- tests/mir_test_doubles/test_protobuf_client.cpp 2015-04-01 19:39:19 +0000 | |||
3190 | +++ tests/mir_test_doubles/test_protobuf_client.cpp 2015-05-14 07:50:26 +0000 | |||
3191 | @@ -26,7 +26,7 @@ | |||
3192 | 26 | #include "src/client/rpc/make_rpc_channel.h" | 26 | #include "src/client/rpc/make_rpc_channel.h" |
3193 | 27 | #include "src/client/rpc/mir_basic_rpc_channel.h" | 27 | #include "src/client/rpc/mir_basic_rpc_channel.h" |
3194 | 28 | #include "mir/dispatch/dispatchable.h" | 28 | #include "mir/dispatch/dispatchable.h" |
3196 | 29 | #include "mir/dispatch/simple_dispatch_thread.h" | 29 | #include "mir/dispatch/threaded_dispatcher.h" |
3197 | 30 | #include "mir/events/event_private.h" | 30 | #include "mir/events/event_private.h" |
3198 | 31 | 31 | ||
3199 | 32 | #include <thread> | 32 | #include <thread> |
3200 | @@ -46,7 +46,7 @@ | |||
3201 | 46 | rpc_report, | 46 | rpc_report, |
3202 | 47 | std::make_shared<mir::client::LifecycleControl>(), | 47 | std::make_shared<mir::client::LifecycleControl>(), |
3203 | 48 | std::make_shared<mtd::NullClientEventSink>())), | 48 | std::make_shared<mtd::NullClientEventSink>())), |
3205 | 49 | eventloop{std::make_shared<md::SimpleDispatchThread>(std::dynamic_pointer_cast<md::Dispatchable>(channel))}, | 49 | eventloop{std::make_shared<md::ThreadedDispatcher>("I/O loop", std::dynamic_pointer_cast<md::Dispatchable>(channel))}, |
3206 | 50 | display_server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), | 50 | display_server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL), |
3207 | 51 | maxwait(timeout_ms), | 51 | maxwait(timeout_ms), |
3208 | 52 | connect_done_called(false), | 52 | connect_done_called(false), |
3209 | 53 | 53 | ||
3210 | === modified file 'tests/mir_test_framework/CMakeLists.txt' | |||
3211 | --- tests/mir_test_framework/CMakeLists.txt 2015-04-30 11:36:36 +0000 | |||
3212 | +++ tests/mir_test_framework/CMakeLists.txt 2015-05-14 07:50:26 +0000 | |||
3213 | @@ -14,6 +14,7 @@ | |||
3214 | 14 | add_definitions( | 14 | add_definitions( |
3215 | 15 | -DMIR_CLIENT_PLATFORM_PATH="${MIR_CLIENT_PLATFORM_PATH}" | 15 | -DMIR_CLIENT_PLATFORM_PATH="${MIR_CLIENT_PLATFORM_PATH}" |
3216 | 16 | -DMIR_SERVER_PLATFORM_PATH="${MIR_SERVER_PLATFORM_PATH}" | 16 | -DMIR_SERVER_PLATFORM_PATH="${MIR_SERVER_PLATFORM_PATH}" |
3217 | 17 | -DTEST_RECORDING_PATH="${CMAKE_INSTALL_PREFIX}/share/mir/udev_recordings" | ||
3218 | 17 | -DMIR_CLIENT_PLATFORM_ABI_STRING="${MIR_CLIENT_PLATFORM_ABI}" | 18 | -DMIR_CLIENT_PLATFORM_ABI_STRING="${MIR_CLIENT_PLATFORM_ABI}" |
3219 | 18 | -DMIR_SERVER_GRAPHICS_PLATFORM_ABI_STRING="${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" | 19 | -DMIR_SERVER_GRAPHICS_PLATFORM_ABI_STRING="${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" |
3220 | 19 | ) | 20 | ) |
3221 | @@ -158,3 +159,5 @@ | |||
3222 | 158 | install(TARGETS mirplatformgraphicsstub LIBRARY DESTINATION ${MIR_SERVER_PLATFORM_PATH}) | 159 | install(TARGETS mirplatformgraphicsstub LIBRARY DESTINATION ${MIR_SERVER_PLATFORM_PATH}) |
3223 | 159 | 160 | ||
3224 | 160 | install(TARGETS mirclientplatformstub LIBRARY DESTINATION ${MIR_CLIENT_PLATFORM_PATH}) | 161 | install(TARGETS mirclientplatformstub LIBRARY DESTINATION ${MIR_CLIENT_PLATFORM_PATH}) |
3225 | 162 | |||
3226 | 163 | install(DIRECTORY udev_recordings DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mir) | ||
3227 | 161 | 164 | ||
3228 | === modified file 'tests/mir_test_framework/udev_environment.cpp' | |||
3229 | --- tests/mir_test_framework/udev_environment.cpp 2015-01-21 07:34:50 +0000 | |||
3230 | +++ tests/mir_test_framework/udev_environment.cpp 2015-05-14 07:50:26 +0000 | |||
3231 | @@ -37,9 +37,33 @@ | |||
3232 | 37 | 37 | ||
3233 | 38 | namespace mtf = mir_test_framework; | 38 | namespace mtf = mir_test_framework; |
3234 | 39 | 39 | ||
3235 | 40 | namespace | ||
3236 | 41 | { | ||
3237 | 42 | std::string find_recording_path() | ||
3238 | 43 | { | ||
3239 | 44 | std::initializer_list<std::string> candidates{mtf::executable_path() + "/udev_recordings", TEST_RECORDING_PATH}; | ||
3240 | 45 | for (auto candidate : candidates) | ||
3241 | 46 | { | ||
3242 | 47 | struct stat sb; | ||
3243 | 48 | if (stat(candidate.c_str(), &sb) == 0) | ||
3244 | 49 | { | ||
3245 | 50 | if (S_ISDIR(sb.st_mode)) | ||
3246 | 51 | { | ||
3247 | 52 | return candidate; | ||
3248 | 53 | } | ||
3249 | 54 | } | ||
3250 | 55 | } | ||
3251 | 56 | BOOST_THROW_EXCEPTION((std::runtime_error{"Failed to find udev recordings directory"})); | ||
3252 | 57 | } | ||
3253 | 58 | } | ||
3254 | 59 | |||
3255 | 40 | mtf::UdevEnvironment::UdevEnvironment() | 60 | mtf::UdevEnvironment::UdevEnvironment() |
3257 | 41 | : recordings_path(mtf::executable_path() + "/udev_recordings") | 61 | : recordings_path{find_recording_path()} |
3258 | 42 | { | 62 | { |
3259 | 63 | if (!umockdev_in_mock_environment()) | ||
3260 | 64 | { | ||
3261 | 65 | BOOST_THROW_EXCEPTION((std::runtime_error{"Test not running under umockdev!"})); | ||
3262 | 66 | } | ||
3263 | 43 | testbed = umockdev_testbed_new(); | 67 | testbed = umockdev_testbed_new(); |
3264 | 44 | } | 68 | } |
3265 | 45 | 69 | ||
3266 | @@ -109,4 +133,45 @@ | |||
3267 | 109 | } | 133 | } |
3268 | 110 | } | 134 | } |
3269 | 111 | } | 135 | } |
3270 | 136 | |||
3271 | 137 | auto script_filename = recordings_path + "/" + name + ".script"; | ||
3272 | 138 | if (stat(script_filename.c_str(), &sb) == 0) | ||
3273 | 139 | { | ||
3274 | 140 | if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode)) | ||
3275 | 141 | { | ||
3276 | 142 | if (!umockdev_testbed_load_script(testbed, NULL, script_filename.c_str(), &err)) | ||
3277 | 143 | { | ||
3278 | 144 | BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Failed to load device recording: ") + | ||
3279 | 145 | err->message)); | ||
3280 | 146 | } | ||
3281 | 147 | } | ||
3282 | 148 | } | ||
3283 | 149 | } | ||
3284 | 150 | |||
3285 | 151 | void mtf::UdevEnvironment::load_device_ioctls(std::string const& name) | ||
3286 | 152 | { | ||
3287 | 153 | auto ioctls_filename = recordings_path + "/" + name + ".ioctl"; | ||
3288 | 154 | |||
3289 | 155 | GError* err = nullptr; | ||
3290 | 156 | if (!umockdev_testbed_load_ioctl(testbed, NULL, ioctls_filename.c_str(), &err)) | ||
3291 | 157 | { | ||
3292 | 158 | std::runtime_error exception{std::string("Failed to load ioctl recording: ") + | ||
3293 | 159 | err->message}; | ||
3294 | 160 | g_error_free(err); | ||
3295 | 161 | BOOST_THROW_EXCEPTION(exception); | ||
3296 | 162 | } | ||
3297 | 163 | } | ||
3298 | 164 | |||
3299 | 165 | void mtf::UdevEnvironment::load_device_evemu(std::string const& name) | ||
3300 | 166 | { | ||
3301 | 167 | auto evemu_filename = recordings_path + "/" + name + ".evemu"; | ||
3302 | 168 | |||
3303 | 169 | GError* err = nullptr; | ||
3304 | 170 | if (!umockdev_testbed_load_evemu_events(testbed, NULL, evemu_filename.c_str(), &err)) | ||
3305 | 171 | { | ||
3306 | 172 | std::runtime_error exception{std::string{"Failed to load evemu recording: "} + | ||
3307 | 173 | err->message}; | ||
3308 | 174 | g_error_free(err); | ||
3309 | 175 | BOOST_THROW_EXCEPTION(exception); | ||
3310 | 176 | } | ||
3311 | 112 | } | 177 | } |
3312 | 113 | 178 | ||
3313 | === added file 'tests/mir_test_framework/udev_recordings/laptop-keyboard-hello.evemu' | |||
3314 | --- tests/mir_test_framework/udev_recordings/laptop-keyboard-hello.evemu 1970-01-01 00:00:00 +0000 | |||
3315 | +++ tests/mir_test_framework/udev_recordings/laptop-keyboard-hello.evemu 2015-05-14 07:50:26 +0000 | |||
3316 | @@ -0,0 +1,272 @@ | |||
3317 | 1 | # device /dev/input/event4 | ||
3318 | 2 | # EVEMU 1.2 | ||
3319 | 3 | # Input device name: "AT Translated Set 2 keyboard" | ||
3320 | 4 | # Input device ID: bus 0x11 vendor 0x01 product 0x01 version 0xab83 | ||
3321 | 5 | # Supported events: | ||
3322 | 6 | # Event type 0 (EV_SYN) | ||
3323 | 7 | # Event code 0 (SYN_REPORT) | ||
3324 | 8 | # Event code 1 (SYN_CONFIG) | ||
3325 | 9 | # Event code 4 (FF_STATUS_STOPPED) | ||
3326 | 10 | # Event code 17 ((null)) | ||
3327 | 11 | # Event code 20 ((null)) | ||
3328 | 12 | # Event type 1 (EV_KEY) | ||
3329 | 13 | # Event code 1 (KEY_ESC) | ||
3330 | 14 | # Event code 2 (KEY_1) | ||
3331 | 15 | # Event code 3 (KEY_2) | ||
3332 | 16 | # Event code 4 (KEY_3) | ||
3333 | 17 | # Event code 5 (KEY_4) | ||
3334 | 18 | # Event code 6 (KEY_5) | ||
3335 | 19 | # Event code 7 (KEY_6) | ||
3336 | 20 | # Event code 8 (KEY_7) | ||
3337 | 21 | # Event code 9 (KEY_8) | ||
3338 | 22 | # Event code 10 (KEY_9) | ||
3339 | 23 | # Event code 11 (KEY_0) | ||
3340 | 24 | # Event code 12 (KEY_MINUS) | ||
3341 | 25 | # Event code 13 (KEY_EQUAL) | ||
3342 | 26 | # Event code 14 (KEY_BACKSPACE) | ||
3343 | 27 | # Event code 15 (KEY_TAB) | ||
3344 | 28 | # Event code 16 (KEY_Q) | ||
3345 | 29 | # Event code 17 (KEY_W) | ||
3346 | 30 | # Event code 18 (KEY_E) | ||
3347 | 31 | # Event code 19 (KEY_R) | ||
3348 | 32 | # Event code 20 (KEY_T) | ||
3349 | 33 | # Event code 21 (KEY_Y) | ||
3350 | 34 | # Event code 22 (KEY_U) | ||
3351 | 35 | # Event code 23 (KEY_I) | ||
3352 | 36 | # Event code 24 (KEY_O) | ||
3353 | 37 | # Event code 25 (KEY_P) | ||
3354 | 38 | # Event code 26 (KEY_LEFTBRACE) | ||
3355 | 39 | # Event code 27 (KEY_RIGHTBRACE) | ||
3356 | 40 | # Event code 28 (KEY_ENTER) | ||
3357 | 41 | # Event code 29 (KEY_LEFTCTRL) | ||
3358 | 42 | # Event code 30 (KEY_A) | ||
3359 | 43 | # Event code 31 (KEY_S) | ||
3360 | 44 | # Event code 32 (KEY_D) | ||
3361 | 45 | # Event code 33 (KEY_F) | ||
3362 | 46 | # Event code 34 (KEY_G) | ||
3363 | 47 | # Event code 35 (KEY_H) | ||
3364 | 48 | # Event code 36 (KEY_J) | ||
3365 | 49 | # Event code 37 (KEY_K) | ||
3366 | 50 | # Event code 38 (KEY_L) | ||
3367 | 51 | # Event code 39 (KEY_SEMICOLON) | ||
3368 | 52 | # Event code 40 (KEY_APOSTROPHE) | ||
3369 | 53 | # Event code 41 (KEY_GRAVE) | ||
3370 | 54 | # Event code 42 (KEY_LEFTSHIFT) | ||
3371 | 55 | # Event code 43 (KEY_BACKSLASH) | ||
3372 | 56 | # Event code 44 (KEY_Z) | ||
3373 | 57 | # Event code 45 (KEY_X) | ||
3374 | 58 | # Event code 46 (KEY_C) | ||
3375 | 59 | # Event code 47 (KEY_V) | ||
3376 | 60 | # Event code 48 (KEY_B) | ||
3377 | 61 | # Event code 49 (KEY_N) | ||
3378 | 62 | # Event code 50 (KEY_M) | ||
3379 | 63 | # Event code 51 (KEY_COMMA) | ||
3380 | 64 | # Event code 52 (KEY_DOT) | ||
3381 | 65 | # Event code 53 (KEY_SLASH) | ||
3382 | 66 | # Event code 54 (KEY_RIGHTSHIFT) | ||
3383 | 67 | # Event code 55 (KEY_KPASTERISK) | ||
3384 | 68 | # Event code 56 (KEY_LEFTALT) | ||
3385 | 69 | # Event code 57 (KEY_SPACE) | ||
3386 | 70 | # Event code 58 (KEY_CAPSLOCK) | ||
3387 | 71 | # Event code 59 (KEY_F1) | ||
3388 | 72 | # Event code 60 (KEY_F2) | ||
3389 | 73 | # Event code 61 (KEY_F3) | ||
3390 | 74 | # Event code 62 (KEY_F4) | ||
3391 | 75 | # Event code 63 (KEY_F5) | ||
3392 | 76 | # Event code 64 (KEY_F6) | ||
3393 | 77 | # Event code 65 (KEY_F7) | ||
3394 | 78 | # Event code 66 (KEY_F8) | ||
3395 | 79 | # Event code 67 (KEY_F9) | ||
3396 | 80 | # Event code 68 (KEY_F10) | ||
3397 | 81 | # Event code 69 (KEY_NUMLOCK) | ||
3398 | 82 | # Event code 70 (KEY_SCROLLLOCK) | ||
3399 | 83 | # Event code 71 (KEY_KP7) | ||
3400 | 84 | # Event code 72 (KEY_KP8) | ||
3401 | 85 | # Event code 73 (KEY_KP9) | ||
3402 | 86 | # Event code 74 (KEY_KPMINUS) | ||
3403 | 87 | # Event code 75 (KEY_KP4) | ||
3404 | 88 | # Event code 76 (KEY_KP5) | ||
3405 | 89 | # Event code 77 (KEY_KP6) | ||
3406 | 90 | # Event code 78 (KEY_KPPLUS) | ||
3407 | 91 | # Event code 79 (KEY_KP1) | ||
3408 | 92 | # Event code 80 (KEY_KP2) | ||
3409 | 93 | # Event code 81 (KEY_KP3) | ||
3410 | 94 | # Event code 82 (KEY_KP0) | ||
3411 | 95 | # Event code 83 (KEY_KPDOT) | ||
3412 | 96 | # Event code 85 (KEY_ZENKAKUHANKAKU) | ||
3413 | 97 | # Event code 86 (KEY_102ND) | ||
3414 | 98 | # Event code 87 (KEY_F11) | ||
3415 | 99 | # Event code 88 (KEY_F12) | ||
3416 | 100 | # Event code 89 (KEY_RO) | ||
3417 | 101 | # Event code 90 (KEY_KATAKANA) | ||
3418 | 102 | # Event code 91 (KEY_HIRAGANA) | ||
3419 | 103 | # Event code 92 (KEY_HENKAN) | ||
3420 | 104 | # Event code 93 (KEY_KATAKANAHIRAGANA) | ||
3421 | 105 | # Event code 94 (KEY_MUHENKAN) | ||
3422 | 106 | # Event code 95 (KEY_KPJPCOMMA) | ||
3423 | 107 | # Event code 96 (KEY_KPENTER) | ||
3424 | 108 | # Event code 97 (KEY_RIGHTCTRL) | ||
3425 | 109 | # Event code 98 (KEY_KPSLASH) | ||
3426 | 110 | # Event code 99 (KEY_SYSRQ) | ||
3427 | 111 | # Event code 100 (KEY_RIGHTALT) | ||
3428 | 112 | # Event code 102 (KEY_HOME) | ||
3429 | 113 | # Event code 103 (KEY_UP) | ||
3430 | 114 | # Event code 104 (KEY_PAGEUP) | ||
3431 | 115 | # Event code 105 (KEY_LEFT) | ||
3432 | 116 | # Event code 106 (KEY_RIGHT) | ||
3433 | 117 | # Event code 107 (KEY_END) | ||
3434 | 118 | # Event code 108 (KEY_DOWN) | ||
3435 | 119 | # Event code 109 (KEY_PAGEDOWN) | ||
3436 | 120 | # Event code 110 (KEY_INSERT) | ||
3437 | 121 | # Event code 111 (KEY_DELETE) | ||
3438 | 122 | # Event code 112 (KEY_MACRO) | ||
3439 | 123 | # Event code 113 (KEY_MUTE) | ||
3440 | 124 | # Event code 114 (KEY_VOLUMEDOWN) | ||
3441 | 125 | # Event code 115 (KEY_VOLUMEUP) | ||
3442 | 126 | # Event code 116 (KEY_POWER) | ||
3443 | 127 | # Event code 117 (KEY_KPEQUAL) | ||
3444 | 128 | # Event code 118 (KEY_KPPLUSMINUS) | ||
3445 | 129 | # Event code 119 (KEY_PAUSE) | ||
3446 | 130 | # Event code 121 (KEY_KPCOMMA) | ||
3447 | 131 | # Event code 122 (KEY_HANGEUL) | ||
3448 | 132 | # Event code 123 (KEY_HANJA) | ||
3449 | 133 | # Event code 124 (KEY_YEN) | ||
3450 | 134 | # Event code 125 (KEY_LEFTMETA) | ||
3451 | 135 | # Event code 126 (KEY_RIGHTMETA) | ||
3452 | 136 | # Event code 127 (KEY_COMPOSE) | ||
3453 | 137 | # Event code 128 (KEY_STOP) | ||
3454 | 138 | # Event code 140 (KEY_CALC) | ||
3455 | 139 | # Event code 142 (KEY_SLEEP) | ||
3456 | 140 | # Event code 143 (KEY_WAKEUP) | ||
3457 | 141 | # Event code 155 (KEY_MAIL) | ||
3458 | 142 | # Event code 156 (KEY_BOOKMARKS) | ||
3459 | 143 | # Event code 157 (KEY_COMPUTER) | ||
3460 | 144 | # Event code 158 (KEY_BACK) | ||
3461 | 145 | # Event code 159 (KEY_FORWARD) | ||
3462 | 146 | # Event code 163 (KEY_NEXTSONG) | ||
3463 | 147 | # Event code 164 (KEY_PLAYPAUSE) | ||
3464 | 148 | # Event code 165 (KEY_PREVIOUSSONG) | ||
3465 | 149 | # Event code 166 (KEY_STOPCD) | ||
3466 | 150 | # Event code 172 (KEY_HOMEPAGE) | ||
3467 | 151 | # Event code 173 (KEY_REFRESH) | ||
3468 | 152 | # Event code 183 (KEY_F13) | ||
3469 | 153 | # Event code 184 (KEY_F14) | ||
3470 | 154 | # Event code 185 (KEY_F15) | ||
3471 | 155 | # Event code 217 (KEY_SEARCH) | ||
3472 | 156 | # Event code 226 (KEY_MEDIA) | ||
3473 | 157 | # Event type 4 (EV_MSC) | ||
3474 | 158 | # Event code 4 (MSC_SCAN) | ||
3475 | 159 | # Event type 17 (EV_LED) | ||
3476 | 160 | # Event code 0 (LED_NUML) | ||
3477 | 161 | # Event code 1 (LED_CAPSL) | ||
3478 | 162 | # Event code 2 (LED_SCROLLL) | ||
3479 | 163 | # Event type 20 (EV_REP) | ||
3480 | 164 | # Properties: | ||
3481 | 165 | # N: AT Translated Set 2 keyboard | ||
3482 | 166 | # I: 0011 0001 0001 ab83 | ||
3483 | 167 | # P: 00 00 00 00 00 00 00 00 | ||
3484 | 168 | # B: 00 13 00 12 00 00 00 00 00 | ||
3485 | 169 | # B: 01 fe ff ff ff ff ff ff ff | ||
3486 | 170 | # B: 01 ff ff ef ff df ff ff fe | ||
3487 | 171 | # B: 01 01 d0 00 f8 78 30 80 03 | ||
3488 | 172 | # B: 01 00 00 00 02 04 00 00 00 | ||
3489 | 173 | # B: 01 00 00 00 00 00 00 00 00 | ||
3490 | 174 | # B: 01 00 00 00 00 00 00 00 00 | ||
3491 | 175 | # B: 01 00 00 00 00 00 00 00 00 | ||
3492 | 176 | # B: 01 00 00 00 00 00 00 00 00 | ||
3493 | 177 | # B: 01 00 00 00 00 00 00 00 00 | ||
3494 | 178 | # B: 01 00 00 00 00 00 00 00 00 | ||
3495 | 179 | # B: 01 00 00 00 00 00 00 00 00 | ||
3496 | 180 | # B: 01 00 00 00 00 00 00 00 00 | ||
3497 | 181 | # B: 02 00 00 00 00 00 00 00 00 | ||
3498 | 182 | # B: 03 00 00 00 00 00 00 00 00 | ||
3499 | 183 | # B: 04 10 00 00 00 00 00 00 00 | ||
3500 | 184 | # B: 05 00 00 00 00 00 00 00 00 | ||
3501 | 185 | # B: 11 07 00 00 00 00 00 00 00 | ||
3502 | 186 | # B: 12 00 00 00 00 00 00 00 00 | ||
3503 | 187 | # B: 15 00 00 00 00 00 00 00 00 | ||
3504 | 188 | # B: 15 00 00 00 00 00 00 00 00 | ||
3505 | 189 | ################################ | ||
3506 | 190 | # Waiting for events # | ||
3507 | 191 | ################################ | ||
3508 | 192 | E: 0.000000 0004 0004 0028 # EV_MSC / MSC_SCAN 28 | ||
3509 | 193 | E: 0.000000 0001 001c 0000 # EV_KEY / KEY_ENTER 0 | ||
3510 | 194 | E: 0.000000 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3511 | 195 | E: 0.825945 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3512 | 196 | E: 0.825945 0001 0036 0001 # EV_KEY / KEY_RIGHTSHIFT 1 | ||
3513 | 197 | E: 0.825945 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3514 | 198 | E: 1.101404 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3515 | 199 | E: 1.101404 0001 0036 0002 # EV_KEY / KEY_RIGHTSHIFT 2 | ||
3516 | 200 | E: 1.101404 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3517 | 201 | E: 1.131449 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3518 | 202 | E: 1.131449 0001 0036 0002 # EV_KEY / KEY_RIGHTSHIFT 2 | ||
3519 | 203 | E: 1.131449 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3520 | 204 | E: 1.161472 0004 0004 0036 # EV_MSC / MSC_SCAN 36 | ||
3521 | 205 | E: 1.161472 0001 0024 0001 # EV_KEY / KEY_J 1 | ||
3522 | 206 | E: 1.161472 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3523 | 207 | E: 1.221981 0004 0004 0036 # EV_MSC / MSC_SCAN 36 | ||
3524 | 208 | E: 1.221981 0001 0024 0000 # EV_KEY / KEY_J 0 | ||
3525 | 209 | E: 1.221981 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3526 | 210 | E: 1.241906 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3527 | 211 | E: 1.241906 0001 0036 0000 # EV_KEY / KEY_RIGHTSHIFT 0 | ||
3528 | 212 | E: 1.241906 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3529 | 213 | E: 1.346773 0004 0004 0032 # EV_MSC / MSC_SCAN 32 | ||
3530 | 214 | E: 1.346773 0001 0020 0001 # EV_KEY / KEY_D 1 | ||
3531 | 215 | E: 1.346773 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3532 | 216 | E: 1.432213 0004 0004 0032 # EV_MSC / MSC_SCAN 32 | ||
3533 | 217 | E: 1.432213 0001 0020 0000 # EV_KEY / KEY_D 0 | ||
3534 | 218 | E: 1.432213 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3535 | 219 | E: 1.562060 0004 0004 0025 # EV_MSC / MSC_SCAN 25 | ||
3536 | 220 | E: 1.562060 0001 0019 0001 # EV_KEY / KEY_P 1 | ||
3537 | 221 | E: 1.562060 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3538 | 222 | E: 1.622477 0004 0004 0025 # EV_MSC / MSC_SCAN 25 | ||
3539 | 223 | E: 1.622477 0001 0019 0000 # EV_KEY / KEY_P 0 | ||
3540 | 224 | E: 1.622477 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3541 | 225 | E: 1.687305 0004 0004 0025 # EV_MSC / MSC_SCAN 25 | ||
3542 | 226 | E: 1.687305 0001 0019 0001 # EV_KEY / KEY_P 1 | ||
3543 | 227 | E: 1.687305 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3544 | 228 | E: 1.777807 0004 0004 0025 # EV_MSC / MSC_SCAN 25 | ||
3545 | 229 | E: 1.777807 0001 0019 0000 # EV_KEY / KEY_P 0 | ||
3546 | 230 | E: 1.777807 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3547 | 231 | E: 1.867577 0004 0004 0031 # EV_MSC / MSC_SCAN 31 | ||
3548 | 232 | E: 1.867577 0001 001f 0001 # EV_KEY / KEY_S 1 | ||
3549 | 233 | E: 1.867577 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3550 | 234 | E: 1.953019 0004 0004 0031 # EV_MSC / MSC_SCAN 31 | ||
3551 | 235 | E: 1.953019 0001 001f 0000 # EV_KEY / KEY_S 0 | ||
3552 | 236 | E: 1.953019 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3553 | 237 | E: 2.118004 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3554 | 238 | E: 2.118004 0001 0036 0001 # EV_KEY / KEY_RIGHTSHIFT 1 | ||
3555 | 239 | E: 2.118004 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3556 | 240 | E: 2.348316 0004 0004 0002 # EV_MSC / MSC_SCAN 2 | ||
3557 | 241 | E: 2.348316 0001 0002 0001 # EV_KEY / KEY_1 1 | ||
3558 | 242 | E: 2.348316 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3559 | 243 | E: 2.489561 0004 0004 0002 # EV_MSC / MSC_SCAN 2 | ||
3560 | 244 | E: 2.489561 0001 0002 0000 # EV_KEY / KEY_1 0 | ||
3561 | 245 | E: 2.489561 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3562 | 246 | E: 2.523740 0004 0004 0054 # EV_MSC / MSC_SCAN 54 | ||
3563 | 247 | E: 2.523740 0001 0036 0000 # EV_KEY / KEY_RIGHTSHIFT 0 | ||
3564 | 248 | E: 2.523740 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3565 | 249 | E: 6.714286 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3566 | 250 | E: 6.714286 0001 001d 0001 # EV_KEY / KEY_LEFTCTRL 1 | ||
3567 | 251 | E: 6.714286 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3568 | 252 | E: 6.989728 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3569 | 253 | E: 6.989728 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3570 | 254 | E: 6.989728 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3571 | 255 | E: 7.019767 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3572 | 256 | E: 7.019767 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3573 | 257 | E: 7.019767 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3574 | 258 | E: 7.049847 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3575 | 259 | E: 7.049847 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3576 | 260 | E: 7.049847 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3577 | 261 | E: 7.079889 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3578 | 262 | E: 7.079889 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3579 | 263 | E: 7.079889 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3580 | 264 | E: 7.109934 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3581 | 265 | E: 7.109934 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3582 | 266 | E: 7.109934 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3583 | 267 | E: 7.139943 0004 0004 0029 # EV_MSC / MSC_SCAN 29 | ||
3584 | 268 | E: 7.139943 0001 001d 0002 # EV_KEY / KEY_LEFTCTRL 2 | ||
3585 | 269 | E: 7.139943 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3586 | 270 | E: 7.170005 0004 0004 0023 # EV_MSC / MSC_SCAN 23 | ||
3587 | 271 | E: 7.170005 0001 0017 0001 # EV_KEY / KEY_I 1 | ||
3588 | 272 | E: 7.170005 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- | ||
3589 | 0 | 273 | ||
3590 | === modified file 'tests/unit-tests/client/test_client_buffer_stream.cpp' | |||
3591 | --- tests/unit-tests/client/test_client_buffer_stream.cpp 2015-04-16 19:56:08 +0000 | |||
3592 | +++ tests/unit-tests/client/test_client_buffer_stream.cpp 2015-05-14 07:50:26 +0000 | |||
3593 | @@ -132,7 +132,7 @@ | |||
3594 | 132 | mcl::ClientBufferFactory& buffer_factory, | 132 | mcl::ClientBufferFactory& buffer_factory, |
3595 | 133 | mcl::BufferStreamMode mode=mcl::BufferStreamMode::Producer) | 133 | mcl::BufferStreamMode mode=mcl::BufferStreamMode::Producer) |
3596 | 134 | { | 134 | { |
3598 | 135 | return std::make_shared<mcl::BufferStream>(mock_protobuf_server, mode, | 135 | return std::make_shared<mcl::BufferStream>(nullptr, mock_protobuf_server, mode, |
3599 | 136 | std::make_shared<StubClientPlatform>(mt::fake_shared(buffer_factory)), protobuf_bs, perf_report, ""); | 136 | std::make_shared<StubClientPlatform>(mt::fake_shared(buffer_factory)), protobuf_bs, perf_report, ""); |
3600 | 137 | } | 137 | } |
3601 | 138 | }; | 138 | }; |
3602 | @@ -448,7 +448,7 @@ | |||
3603 | 448 | 448 | ||
3604 | 449 | EXPECT_CALL(mock_perf_report, name_surface(StrEq(name))).Times(1); | 449 | EXPECT_CALL(mock_perf_report, name_surface(StrEq(name))).Times(1); |
3605 | 450 | 450 | ||
3607 | 451 | auto bs = std::make_shared<mcl::BufferStream>(mock_protobuf_server, mcl::BufferStreamMode::Producer, | 451 | auto bs = std::make_shared<mcl::BufferStream>(nullptr, mock_protobuf_server, mcl::BufferStreamMode::Producer, |
3608 | 452 | std::make_shared<StubClientPlatform>(mt::fake_shared(stub_client_buffer_factory)), | 452 | std::make_shared<StubClientPlatform>(mt::fake_shared(stub_client_buffer_factory)), |
3609 | 453 | protobuf_bs, mt::fake_shared(mock_perf_report), name); | 453 | protobuf_bs, mt::fake_shared(mock_perf_report), name); |
3610 | 454 | } | 454 | } |
3611 | 455 | 455 | ||
3612 | === modified file 'tests/unit-tests/client/test_client_mir_surface.cpp' | |||
3613 | --- tests/unit-tests/client/test_client_mir_surface.cpp 2015-04-16 20:03:39 +0000 | |||
3614 | +++ tests/unit-tests/client/test_client_mir_surface.cpp 2015-05-14 07:50:26 +0000 | |||
3615 | @@ -30,8 +30,8 @@ | |||
3616 | 30 | #include "src/client/mir_connection.h" | 30 | #include "src/client/mir_connection.h" |
3617 | 31 | #include "src/client/default_connection_configuration.h" | 31 | #include "src/client/default_connection_configuration.h" |
3618 | 32 | #include "src/client/rpc/null_rpc_report.h" | 32 | #include "src/client/rpc/null_rpc_report.h" |
3619 | 33 | #include "mir/dispatch/simple_dispatch_thread.h" | ||
3620 | 34 | #include "mir/dispatch/dispatchable.h" | 33 | #include "mir/dispatch/dispatchable.h" |
3621 | 34 | #include "mir/dispatch/threaded_dispatcher.h" | ||
3622 | 35 | 35 | ||
3623 | 36 | #include "mir/frontend/connector.h" | 36 | #include "mir/frontend/connector.h" |
3624 | 37 | #include "mir/input/input_platform.h" | 37 | #include "mir/input/input_platform.h" |
3625 | 38 | 38 | ||
3626 | === modified file 'tests/unit-tests/client/test_mir_connection.cpp' | |||
3627 | --- tests/unit-tests/client/test_mir_connection.cpp 2015-03-31 02:35:42 +0000 | |||
3628 | +++ tests/unit-tests/client/test_mir_connection.cpp 2015-05-14 07:50:26 +0000 | |||
3629 | @@ -34,6 +34,10 @@ | |||
3630 | 34 | #include "mir_test/test_protobuf_server.h" | 34 | #include "mir_test/test_protobuf_server.h" |
3631 | 35 | #include "mir_test/stub_server_tool.h" | 35 | #include "mir_test/stub_server_tool.h" |
3632 | 36 | #include "mir_test_doubles/stub_client_buffer_factory.h" | 36 | #include "mir_test_doubles/stub_client_buffer_factory.h" |
3633 | 37 | #include "mir_test/pipe.h" | ||
3634 | 38 | #include "mir_test/signal.h" | ||
3635 | 39 | #include "mir_test/fd_utils.h" | ||
3636 | 40 | #include "mir_test/test_dispatchable.h" | ||
3637 | 37 | 41 | ||
3638 | 38 | #include "mir_protobuf.pb.h" | 42 | #include "mir_protobuf.pb.h" |
3639 | 39 | 43 | ||
3640 | @@ -49,16 +53,19 @@ | |||
3641 | 49 | namespace md = mir::dispatch; | 53 | namespace md = mir::dispatch; |
3642 | 50 | namespace geom = mir::geometry; | 54 | namespace geom = mir::geometry; |
3643 | 51 | namespace mtd = mir::test::doubles; | 55 | namespace mtd = mir::test::doubles; |
3644 | 56 | namespace md = mir::dispatch; | ||
3645 | 57 | namespace mt = mir::test; | ||
3646 | 52 | 58 | ||
3647 | 53 | namespace | 59 | namespace |
3648 | 54 | { | 60 | { |
3649 | 55 | 61 | ||
3652 | 56 | struct MockRpcChannel : public mir::client::rpc::MirBasicRpcChannel, | 62 | struct MockRpcChannel : public mir::client::rpc::MirBasicRpcChannel |
3651 | 57 | public mir::dispatch::Dispatchable | ||
3653 | 58 | { | 63 | { |
3654 | 59 | MockRpcChannel() | 64 | MockRpcChannel() |
3655 | 60 | { | 65 | { |
3657 | 61 | ON_CALL(*this, watch_fd()).WillByDefault(testing::Return(mir::Fd{})); | 66 | using namespace testing; |
3658 | 67 | ON_CALL(*this, watch_fd()).WillByDefault(Return(fake_epoll.read_fd())); | ||
3659 | 68 | ON_CALL(*this, relevant_events()).WillByDefault(Return(md::FdEvent::readable)); | ||
3660 | 62 | } | 69 | } |
3661 | 63 | 70 | ||
3662 | 64 | void CallMethod(const google::protobuf::MethodDescriptor* method, | 71 | void CallMethod(const google::protobuf::MethodDescriptor* method, |
3663 | @@ -86,14 +93,35 @@ | |||
3664 | 86 | complete->Run(); | 93 | complete->Run(); |
3665 | 87 | } | 94 | } |
3666 | 88 | 95 | ||
3667 | 96 | // MirBasicRpcChannel | ||
3668 | 97 | MOCK_METHOD0(process_next_request_first,void()); | ||
3669 | 98 | |||
3670 | 99 | // Dispatchable | ||
3671 | 100 | MOCK_CONST_METHOD0(watch_fd, mir::Fd()); | ||
3672 | 101 | MOCK_METHOD1(dispatch, bool(md::FdEvents)); | ||
3673 | 102 | MOCK_CONST_METHOD0(relevant_events, md::FdEvents()); | ||
3674 | 103 | |||
3675 | 89 | MOCK_METHOD2(connect, void(mp::ConnectParameters const*,mp::Connection*)); | 104 | MOCK_METHOD2(connect, void(mp::ConnectParameters const*,mp::Connection*)); |
3676 | 90 | MOCK_METHOD1(configure_display_sent, void(mp::DisplayConfiguration const*)); | 105 | MOCK_METHOD1(configure_display_sent, void(mp::DisplayConfiguration const*)); |
3677 | 91 | MOCK_METHOD2(platform_operation, | 106 | MOCK_METHOD2(platform_operation, |
3678 | 92 | void(mp::PlatformOperationMessage const*, mp::PlatformOperationMessage*)); | 107 | void(mp::PlatformOperationMessage const*, mp::PlatformOperationMessage*)); |
3679 | 93 | 108 | ||
3683 | 94 | MOCK_CONST_METHOD0(watch_fd, mir::Fd()); | 109 | void trigger() |
3684 | 95 | MOCK_METHOD1(dispatch, bool(md::FdEvents)); | 110 | { |
3685 | 96 | MOCK_CONST_METHOD0(relevant_events, md::FdEvents()); | 111 | using namespace testing; |
3686 | 112 | int dummy{0}; | ||
3687 | 113 | EXPECT_THAT(write(fake_epoll.write_fd(), &dummy, sizeof(dummy)), Eq(sizeof(dummy))); | ||
3688 | 114 | } | ||
3689 | 115 | |||
3690 | 116 | void untrigger() | ||
3691 | 117 | { | ||
3692 | 118 | using namespace testing; | ||
3693 | 119 | int dummy{0}; | ||
3694 | 120 | EXPECT_THAT(read(fake_epoll.read_fd(), &dummy, sizeof(dummy)), Eq(sizeof(dummy))); | ||
3695 | 121 | } | ||
3696 | 122 | |||
3697 | 123 | private: | ||
3698 | 124 | mt::Pipe fake_epoll; | ||
3699 | 97 | }; | 125 | }; |
3700 | 98 | 126 | ||
3701 | 99 | struct MockClientPlatform : public mcl::ClientPlatform | 127 | struct MockClientPlatform : public mcl::ClientPlatform |
3702 | @@ -167,7 +195,7 @@ | |||
3703 | 167 | { | 195 | { |
3704 | 168 | } | 196 | } |
3705 | 169 | 197 | ||
3707 | 170 | std::shared_ptr<::google::protobuf::RpcChannel> the_rpc_channel() override | 198 | std::shared_ptr<mcl::rpc::MirBasicRpcChannel> the_rpc_channel() override |
3708 | 171 | { | 199 | { |
3709 | 172 | return channel; | 200 | return channel; |
3710 | 173 | } | 201 | } |
3711 | @@ -194,22 +222,21 @@ | |||
3712 | 194 | MirConnectionTest() | 222 | MirConnectionTest() |
3713 | 195 | : mock_platform{std::make_shared<testing::NiceMock<MockClientPlatform>>()}, | 223 | : mock_platform{std::make_shared<testing::NiceMock<MockClientPlatform>>()}, |
3714 | 196 | mock_channel{std::make_shared<testing::NiceMock<MockRpcChannel>>()}, | 224 | mock_channel{std::make_shared<testing::NiceMock<MockRpcChannel>>()}, |
3717 | 197 | conf{mock_platform, mock_channel}, | 225 | conf{mock_platform, mock_channel} |
3716 | 198 | connection{std::make_shared<MirConnection>(conf)} | ||
3718 | 199 | { | 226 | { |
3719 | 200 | mock_platform->set_client_context(connection.get()); | ||
3720 | 201 | } | 227 | } |
3721 | 202 | 228 | ||
3722 | 203 | std::shared_ptr<testing::NiceMock<MockClientPlatform>> const mock_platform; | 229 | std::shared_ptr<testing::NiceMock<MockClientPlatform>> const mock_platform; |
3723 | 204 | std::shared_ptr<testing::NiceMock<MockRpcChannel>> const mock_channel; | 230 | std::shared_ptr<testing::NiceMock<MockRpcChannel>> const mock_channel; |
3724 | 205 | TestConnectionConfiguration conf; | 231 | TestConnectionConfiguration conf; |
3725 | 206 | std::shared_ptr<MirConnection> const connection; | ||
3726 | 207 | }; | 232 | }; |
3727 | 208 | 233 | ||
3728 | 209 | TEST_F(MirConnectionTest, returns_correct_egl_native_display) | 234 | TEST_F(MirConnectionTest, returns_correct_egl_native_display) |
3729 | 210 | { | 235 | { |
3730 | 211 | using namespace testing; | 236 | using namespace testing; |
3731 | 212 | 237 | ||
3732 | 238 | auto connection = std::make_shared<MirConnection>(conf); | ||
3733 | 239 | |||
3734 | 213 | EGLNativeDisplayType native_display_raw = reinterpret_cast<EGLNativeDisplayType>(0xabcdef); | 240 | EGLNativeDisplayType native_display_raw = reinterpret_cast<EGLNativeDisplayType>(0xabcdef); |
3735 | 214 | auto native_display = std::make_shared<EGLNativeDisplayType>(); | 241 | auto native_display = std::make_shared<EGLNativeDisplayType>(); |
3736 | 215 | *native_display = native_display_raw; | 242 | *native_display = native_display_raw; |
3737 | @@ -278,6 +305,8 @@ | |||
3738 | 278 | { | 305 | { |
3739 | 279 | using namespace testing; | 306 | using namespace testing; |
3740 | 280 | 307 | ||
3741 | 308 | auto connection = std::make_shared<MirConnection>(conf); | ||
3742 | 309 | |||
3743 | 281 | EXPECT_CALL(*mock_channel, connect(_,_)) | 310 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3744 | 282 | .WillOnce(Invoke(fill_display_configuration)); | 311 | .WillOnce(Invoke(fill_display_configuration)); |
3745 | 283 | 312 | ||
3746 | @@ -317,6 +346,8 @@ | |||
3747 | 317 | { | 346 | { |
3748 | 318 | using namespace testing; | 347 | using namespace testing; |
3749 | 319 | 348 | ||
3750 | 349 | auto connection = std::make_shared<MirConnection>(conf); | ||
3751 | 350 | |||
3752 | 320 | EXPECT_CALL(*mock_channel, connect(_,_)) | 351 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3753 | 321 | .WillOnce(Invoke(fill_display_configuration)); | 352 | .WillOnce(Invoke(fill_display_configuration)); |
3754 | 322 | 353 | ||
3755 | @@ -362,6 +393,8 @@ | |||
3756 | 362 | { | 393 | { |
3757 | 363 | using namespace testing; | 394 | using namespace testing; |
3758 | 364 | 395 | ||
3759 | 396 | auto connection = std::make_shared<MirConnection>(conf); | ||
3760 | 397 | |||
3761 | 365 | EXPECT_CALL(*mock_channel, connect(_,_)) | 398 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3762 | 366 | .WillOnce(Invoke(fill_display_configuration)); | 399 | .WillOnce(Invoke(fill_display_configuration)); |
3763 | 367 | 400 | ||
3764 | @@ -383,6 +416,8 @@ | |||
3765 | 383 | { | 416 | { |
3766 | 384 | using namespace testing; | 417 | using namespace testing; |
3767 | 385 | 418 | ||
3768 | 419 | auto connection = std::make_shared<MirConnection>(conf); | ||
3769 | 420 | |||
3770 | 386 | EXPECT_CALL(*mock_channel, connect(_,_)) | 421 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3771 | 387 | .WillOnce(Invoke(fill_display_configuration)); | 422 | .WillOnce(Invoke(fill_display_configuration)); |
3772 | 388 | 423 | ||
3773 | @@ -420,6 +455,8 @@ | |||
3774 | 420 | { | 455 | { |
3775 | 421 | using namespace testing; | 456 | using namespace testing; |
3776 | 422 | 457 | ||
3777 | 458 | auto connection = std::make_shared<MirConnection>(conf); | ||
3778 | 459 | |||
3779 | 423 | EXPECT_CALL(*mock_channel, connect(_,_)) | 460 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3780 | 424 | .WillOnce(Invoke(fill_surface_pixel_formats)); | 461 | .WillOnce(Invoke(fill_surface_pixel_formats)); |
3781 | 425 | MirWaitHandle* wait_handle = connection->connect("MirClientSurfaceTest", | 462 | MirWaitHandle* wait_handle = connection->connect("MirClientSurfaceTest", |
3782 | @@ -443,6 +480,8 @@ | |||
3783 | 443 | { | 480 | { |
3784 | 444 | using namespace testing; | 481 | using namespace testing; |
3785 | 445 | 482 | ||
3786 | 483 | auto connection = std::make_shared<MirConnection>(conf); | ||
3787 | 484 | |||
3788 | 446 | EXPECT_CALL(*mock_channel, connect(_,_)) | 485 | EXPECT_CALL(*mock_channel, connect(_,_)) |
3789 | 447 | .WillOnce(Invoke(fill_display_configuration)); | 486 | .WillOnce(Invoke(fill_display_configuration)); |
3790 | 448 | 487 | ||
3791 | @@ -509,6 +548,8 @@ | |||
3792 | 509 | { | 548 | { |
3793 | 510 | using namespace testing; | 549 | using namespace testing; |
3794 | 511 | 550 | ||
3795 | 551 | auto connection = std::make_shared<MirConnection>(conf); | ||
3796 | 552 | |||
3797 | 512 | MirSurfaceSpec params{nullptr, 640, 480, mir_pixel_format_abgr_8888}; | 553 | MirSurfaceSpec params{nullptr, 640, 480, mir_pixel_format_abgr_8888}; |
3798 | 513 | params.surface_name = __PRETTY_FUNCTION__; | 554 | params.surface_name = __PRETTY_FUNCTION__; |
3799 | 514 | 555 | ||
3800 | @@ -537,6 +578,8 @@ | |||
3801 | 537 | { | 578 | { |
3802 | 538 | using namespace testing; | 579 | using namespace testing; |
3803 | 539 | 580 | ||
3804 | 581 | auto connection = std::make_shared<MirConnection>(conf); | ||
3805 | 582 | |||
3806 | 540 | MirSurfaceSpec params{nullptr, 640, 480, mir_pixel_format_abgr_8888}; | 583 | MirSurfaceSpec params{nullptr, 640, 480, mir_pixel_format_abgr_8888}; |
3807 | 541 | params.surface_name = __PRETTY_FUNCTION__; | 584 | params.surface_name = __PRETTY_FUNCTION__; |
3808 | 542 | 585 | ||
3809 | @@ -588,6 +631,8 @@ | |||
3810 | 588 | mir_platform_message_create(opcode), | 631 | mir_platform_message_create(opcode), |
3811 | 589 | &mir_platform_message_release); | 632 | &mir_platform_message_release); |
3812 | 590 | 633 | ||
3813 | 634 | auto connection = std::make_shared<MirConnection>(conf); | ||
3814 | 635 | |||
3815 | 591 | EXPECT_CALL(*mock_platform, platform_operation(request.get())) | 636 | EXPECT_CALL(*mock_platform, platform_operation(request.get())) |
3816 | 592 | .WillOnce(Return(response.get())); | 637 | .WillOnce(Return(response.get())); |
3817 | 593 | EXPECT_CALL(*mock_channel, platform_operation(_,_)) | 638 | EXPECT_CALL(*mock_channel, platform_operation(_,_)) |
3818 | @@ -620,6 +665,8 @@ | |||
3819 | 620 | EXPECT_CALL(*mock_channel, platform_operation(_,_)) | 665 | EXPECT_CALL(*mock_channel, platform_operation(_,_)) |
3820 | 621 | .WillOnce(CopyRequestToResponse()); | 666 | .WillOnce(CopyRequestToResponse()); |
3821 | 622 | 667 | ||
3822 | 668 | auto connection = std::make_shared<MirConnection>(conf); | ||
3823 | 669 | |||
3824 | 623 | auto connect_wh = | 670 | auto connect_wh = |
3825 | 624 | connection->connect("MirClientSurfaceTest", &connected_callback, nullptr); | 671 | connection->connect("MirClientSurfaceTest", &connected_callback, nullptr); |
3826 | 625 | mir_wait_for(connect_wh); | 672 | mir_wait_for(connect_wh); |
3827 | @@ -633,3 +680,107 @@ | |||
3828 | 633 | EXPECT_THAT(mir_platform_message_get_opcode(returned_response), Eq(opcode)); | 680 | EXPECT_THAT(mir_platform_message_get_opcode(returned_response), Eq(opcode)); |
3829 | 634 | mir_platform_message_release(returned_response); | 681 | mir_platform_message_release(returned_response); |
3830 | 635 | } | 682 | } |
3831 | 683 | |||
3832 | 684 | TEST_F(MirConnectionTest, dispatch_works_with_automatic_dispatch) | ||
3833 | 685 | { | ||
3834 | 686 | using namespace testing; | ||
3835 | 687 | |||
3836 | 688 | auto channel = std::dynamic_pointer_cast<MockRpcChannel>(conf.the_rpc_channel()); | ||
3837 | 689 | |||
3838 | 690 | auto dispatched = std::make_shared<mir::test::Signal>(); | ||
3839 | 691 | ON_CALL(*channel, dispatch(_)) | ||
3840 | 692 | .WillByDefault(Invoke([dispatched](md::FdEvents) { dispatched->raise(); return true; })); | ||
3841 | 693 | |||
3842 | 694 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::automatic); | ||
3843 | 695 | |||
3844 | 696 | channel->trigger(); | ||
3845 | 697 | |||
3846 | 698 | EXPECT_TRUE(dispatched->wait_for(std::chrono::seconds{1})); | ||
3847 | 699 | } | ||
3848 | 700 | |||
3849 | 701 | TEST_F(MirConnectionTest, manual_dispatch_is_not_automatically_dispatched) | ||
3850 | 702 | { | ||
3851 | 703 | using namespace testing; | ||
3852 | 704 | |||
3853 | 705 | auto channel = std::dynamic_pointer_cast<MockRpcChannel>(conf.the_rpc_channel()); | ||
3854 | 706 | |||
3855 | 707 | auto dispatched = std::make_shared<mir::test::Signal>(); | ||
3856 | 708 | ON_CALL(*channel, dispatch(_)) | ||
3857 | 709 | .WillByDefault(Invoke([dispatched](md::FdEvents) { dispatched->raise(); return true; })); | ||
3858 | 710 | |||
3859 | 711 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::manual); | ||
3860 | 712 | |||
3861 | 713 | channel->trigger(); | ||
3862 | 714 | |||
3863 | 715 | EXPECT_FALSE(dispatched->wait_for(std::chrono::seconds{1})); | ||
3864 | 716 | } | ||
3865 | 717 | |||
3866 | 718 | TEST_F(MirConnectionTest, returns_invalid_watch_fd_when_using_automatic_dispatch) | ||
3867 | 719 | { | ||
3868 | 720 | using namespace testing; | ||
3869 | 721 | |||
3870 | 722 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::automatic); | ||
3871 | 723 | |||
3872 | 724 | EXPECT_THAT(connection->watch_fd(), Lt(0)); | ||
3873 | 725 | } | ||
3874 | 726 | |||
3875 | 727 | TEST_F(MirConnectionTest, returns_pollable_watch_fd_when_using_manual_dispatch) | ||
3876 | 728 | { | ||
3877 | 729 | using namespace testing; | ||
3878 | 730 | |||
3879 | 731 | auto channel = std::dynamic_pointer_cast<MockRpcChannel>(conf.the_rpc_channel()); | ||
3880 | 732 | |||
3881 | 733 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::manual); | ||
3882 | 734 | |||
3883 | 735 | pollfd fd_readable; | ||
3884 | 736 | fd_readable.events = POLLIN; | ||
3885 | 737 | fd_readable.fd = connection->watch_fd(); | ||
3886 | 738 | EXPECT_TRUE(mt::std_call_succeeded(poll(&fd_readable, 1, 0))); | ||
3887 | 739 | } | ||
3888 | 740 | |||
3889 | 741 | TEST_F(MirConnectionTest, can_add_dispatchables_to_connection) | ||
3890 | 742 | { | ||
3891 | 743 | using namespace testing; | ||
3892 | 744 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::manual); | ||
3893 | 745 | |||
3894 | 746 | auto dispatchee = std::make_shared<mt::TestDispatchable>([](){}); | ||
3895 | 747 | connection->add_dispatchee(dispatchee); | ||
3896 | 748 | } | ||
3897 | 749 | |||
3898 | 750 | TEST_F(MirConnectionTest, added_dispatchees_are_dispatched) | ||
3899 | 751 | { | ||
3900 | 752 | using namespace testing; | ||
3901 | 753 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::manual); | ||
3902 | 754 | |||
3903 | 755 | bool dispatched{false}; | ||
3904 | 756 | auto dispatchee = std::make_shared<mt::TestDispatchable>([&dispatched](){ dispatched = true; }); | ||
3905 | 757 | |||
3906 | 758 | connection->add_dispatchee(dispatchee); | ||
3907 | 759 | |||
3908 | 760 | dispatchee->trigger(); | ||
3909 | 761 | |||
3910 | 762 | EXPECT_TRUE(mt::fd_is_readable(connection->watch_fd())); | ||
3911 | 763 | connection->dispatch(); | ||
3912 | 764 | |||
3913 | 765 | EXPECT_TRUE(dispatched); | ||
3914 | 766 | } | ||
3915 | 767 | |||
3916 | 768 | TEST_F(MirConnectionTest, removed_dispatchees_are_no_longer_dispatched) | ||
3917 | 769 | { | ||
3918 | 770 | using namespace testing; | ||
3919 | 771 | auto connection = std::make_shared<MirConnection>(conf, DispatchType::manual); | ||
3920 | 772 | |||
3921 | 773 | bool dispatched{false}; | ||
3922 | 774 | auto dispatchee = std::make_shared<mt::TestDispatchable>([&dispatched](){ dispatched = true; }); | ||
3923 | 775 | |||
3924 | 776 | connection->add_dispatchee(dispatchee); | ||
3925 | 777 | connection->remove_dispatchee(dispatchee); | ||
3926 | 778 | |||
3927 | 779 | dispatchee->trigger(); | ||
3928 | 780 | |||
3929 | 781 | EXPECT_FALSE(mir::test::fd_is_readable(connection->watch_fd())); | ||
3930 | 782 | |||
3931 | 783 | connection->dispatch(); | ||
3932 | 784 | |||
3933 | 785 | EXPECT_FALSE(dispatched); | ||
3934 | 786 | } | ||
3935 | 636 | 787 | ||
3936 | === modified file 'tests/unit-tests/client/test_mir_screencast.cpp' | |||
3937 | --- tests/unit-tests/client/test_mir_screencast.cpp 2015-04-16 19:56:08 +0000 | |||
3938 | +++ tests/unit-tests/client/test_mir_screencast.cpp 2015-05-14 07:50:26 +0000 | |||
3939 | @@ -166,7 +166,7 @@ | |||
3940 | 166 | using namespace ::testing; | 166 | using namespace ::testing; |
3941 | 167 | 167 | ||
3942 | 168 | ON_CALL(*mock_buffer_stream_factory, | 168 | ON_CALL(*mock_buffer_stream_factory, |
3944 | 169 | make_consumer_stream(_,_,_)).WillByDefault( | 169 | make_consumer_stream(_,_,_,_)).WillByDefault( |
3945 | 170 | Return(mt::fake_shared(mock_bs))); | 170 | Return(mt::fake_shared(mock_bs))); |
3946 | 171 | } | 171 | } |
3947 | 172 | 172 | ||
3948 | @@ -191,6 +191,7 @@ | |||
3949 | 191 | .WillOnce(RunClosure()); | 191 | .WillOnce(RunClosure()); |
3950 | 192 | 192 | ||
3951 | 193 | MirScreencast screencast{ | 193 | MirScreencast screencast{ |
3952 | 194 | nullptr, | ||
3953 | 194 | default_region, | 195 | default_region, |
3954 | 195 | default_size, | 196 | default_size, |
3955 | 196 | default_pixel_format, mock_server, | 197 | default_pixel_format, mock_server, |
3956 | @@ -215,6 +216,7 @@ | |||
3957 | 215 | .WillOnce(RunClosure()); | 216 | .WillOnce(RunClosure()); |
3958 | 216 | 217 | ||
3959 | 217 | MirScreencast screencast{ | 218 | MirScreencast screencast{ |
3960 | 219 | nullptr, | ||
3961 | 218 | default_region, | 220 | default_region, |
3962 | 219 | default_size, | 221 | default_size, |
3963 | 220 | default_pixel_format, mock_server, | 222 | default_pixel_format, mock_server, |
3964 | @@ -232,6 +234,7 @@ | |||
3965 | 232 | EXPECT_CALL(mock_cb, call(_, &mock_cb)); | 234 | EXPECT_CALL(mock_cb, call(_, &mock_cb)); |
3966 | 233 | 235 | ||
3967 | 234 | MirScreencast screencast{ | 236 | MirScreencast screencast{ |
3968 | 237 | nullptr, | ||
3969 | 235 | default_region, | 238 | default_region, |
3970 | 236 | default_size, | 239 | default_size, |
3971 | 237 | default_pixel_format, stub_server, | 240 | default_pixel_format, stub_server, |
3972 | @@ -246,6 +249,7 @@ | |||
3973 | 246 | using namespace testing; | 249 | using namespace testing; |
3974 | 247 | 250 | ||
3975 | 248 | MirScreencast screencast{ | 251 | MirScreencast screencast{ |
3976 | 252 | nullptr, | ||
3977 | 249 | default_region, | 253 | default_region, |
3978 | 250 | default_size, | 254 | default_size, |
3979 | 251 | default_pixel_format, stub_server, | 255 | default_pixel_format, stub_server, |
3980 | @@ -268,6 +272,7 @@ | |||
3981 | 268 | 272 | ||
3982 | 269 | EXPECT_THROW({ | 273 | EXPECT_THROW({ |
3983 | 270 | MirScreencast screencast( | 274 | MirScreencast screencast( |
3984 | 275 | nullptr, | ||
3985 | 271 | default_region, | 276 | default_region, |
3986 | 272 | invalid_size, | 277 | invalid_size, |
3987 | 273 | default_pixel_format, stub_server, | 278 | default_pixel_format, stub_server, |
3988 | @@ -277,6 +282,7 @@ | |||
3989 | 277 | 282 | ||
3990 | 278 | EXPECT_THROW({ | 283 | EXPECT_THROW({ |
3991 | 279 | MirScreencast screencast( | 284 | MirScreencast screencast( |
3992 | 285 | nullptr, | ||
3993 | 280 | invalid_region, | 286 | invalid_region, |
3994 | 281 | default_size, | 287 | default_size, |
3995 | 282 | default_pixel_format, stub_server, | 288 | default_pixel_format, stub_server, |
3996 | @@ -286,6 +292,7 @@ | |||
3997 | 286 | 292 | ||
3998 | 287 | EXPECT_THROW({ | 293 | EXPECT_THROW({ |
3999 | 288 | MirScreencast screencast( | 294 | MirScreencast screencast( |
4000 | 295 | nullptr, | ||
4001 | 289 | default_region, | 296 | default_region, |
4002 | 290 | default_size, | 297 | default_size, |
4003 | 291 | mir_pixel_format_invalid, stub_server, | 298 | mir_pixel_format_invalid, stub_server, |
4004 | @@ -302,6 +309,7 @@ | |||
4005 | 302 | .WillOnce(DoAll(SetCreateError(), RunClosure())); | 309 | .WillOnce(DoAll(SetCreateError(), RunClosure())); |
4006 | 303 | 310 | ||
4007 | 304 | MirScreencast screencast{ | 311 | MirScreencast screencast{ |
4008 | 312 | nullptr, | ||
4009 | 305 | default_region, | 313 | default_region, |
4010 | 306 | default_size, | 314 | default_size, |
4011 | 307 | default_pixel_format, mock_server, | 315 | default_pixel_format, mock_server, |
4012 | @@ -323,6 +331,7 @@ | |||
4013 | 323 | EXPECT_CALL(mock_cb, call(_,&mock_cb)); | 331 | EXPECT_CALL(mock_cb, call(_,&mock_cb)); |
4014 | 324 | 332 | ||
4015 | 325 | MirScreencast screencast{ | 333 | MirScreencast screencast{ |
4016 | 334 | nullptr, | ||
4017 | 326 | default_region, | 335 | default_region, |
4018 | 327 | default_size, | 336 | default_size, |
4019 | 328 | default_pixel_format, mock_server, | 337 | default_pixel_format, mock_server, |
4020 | 329 | 338 | ||
4021 | === modified file 'tests/unit-tests/client/test_protobuf_rpc_channel.cpp' | |||
4022 | --- tests/unit-tests/client/test_protobuf_rpc_channel.cpp 2015-04-13 05:50:18 +0000 | |||
4023 | +++ tests/unit-tests/client/test_protobuf_rpc_channel.cpp 2015-05-14 07:50:26 +0000 | |||
4024 | @@ -27,12 +27,16 @@ | |||
4025 | 27 | #include "mir_protobuf_wire.pb.h" | 27 | #include "mir_protobuf_wire.pb.h" |
4026 | 28 | 28 | ||
4027 | 29 | #include "mir_test_doubles/null_client_event_sink.h" | 29 | #include "mir_test_doubles/null_client_event_sink.h" |
4028 | 30 | #include "mir_test/fd_utils.h" | ||
4029 | 30 | 31 | ||
4030 | 31 | #include <list> | 32 | #include <list> |
4031 | 32 | #include <endian.h> | 33 | #include <endian.h> |
4032 | 33 | 34 | ||
4033 | 35 | #include <sys/eventfd.h> | ||
4034 | 34 | #include <fcntl.h> | 36 | #include <fcntl.h> |
4035 | 35 | 37 | ||
4036 | 38 | #include <boost/throw_exception.hpp> | ||
4037 | 39 | |||
4038 | 36 | #include <google/protobuf/descriptor.h> | 40 | #include <google/protobuf/descriptor.h> |
4039 | 37 | 41 | ||
4040 | 38 | #include <gtest/gtest.h> | 42 | #include <gtest/gtest.h> |
4041 | @@ -42,6 +46,9 @@ | |||
4042 | 42 | namespace mclr = mir::client::rpc; | 46 | namespace mclr = mir::client::rpc; |
4043 | 43 | namespace mtd = mir::test::doubles; | 47 | namespace mtd = mir::test::doubles; |
4044 | 44 | namespace md = mir::dispatch; | 48 | namespace md = mir::dispatch; |
4045 | 49 | namespace mt = mir::test; | ||
4046 | 50 | |||
4047 | 51 | namespace mt = mir::test; | ||
4048 | 45 | 52 | ||
4049 | 46 | namespace | 53 | namespace |
4050 | 47 | { | 54 | { |
4051 | @@ -58,7 +65,15 @@ | |||
4052 | 58 | { | 65 | { |
4053 | 59 | public: | 66 | public: |
4054 | 60 | MockStreamTransport() | 67 | MockStreamTransport() |
4055 | 68 | : event_fd{eventfd(0, EFD_CLOEXEC)} | ||
4056 | 61 | { | 69 | { |
4057 | 70 | if (event_fd == mir::Fd::invalid) | ||
4058 | 71 | { | ||
4059 | 72 | BOOST_THROW_EXCEPTION((std::system_error{errno, | ||
4060 | 73 | std::system_category(), | ||
4061 | 74 | "Failed to create event fd"})); | ||
4062 | 75 | } | ||
4063 | 76 | |||
4064 | 62 | using namespace testing; | 77 | using namespace testing; |
4065 | 63 | ON_CALL(*this, register_observer(_)) | 78 | ON_CALL(*this, register_observer(_)) |
4066 | 64 | .WillByDefault(Invoke(std::bind(&MockStreamTransport::register_observer_default, | 79 | .WillByDefault(Invoke(std::bind(&MockStreamTransport::register_observer_default, |
4067 | @@ -82,6 +97,8 @@ | |||
4068 | 82 | 97 | ||
4069 | 83 | void add_server_message(std::vector<uint8_t> const& message) | 98 | void add_server_message(std::vector<uint8_t> const& message) |
4070 | 84 | { | 99 | { |
4071 | 100 | eventfd_t data_added{message.size()}; | ||
4072 | 101 | eventfd_write(event_fd, data_added); | ||
4073 | 85 | received_data.insert(received_data.end(), message.begin(), message.end()); | 102 | received_data.insert(received_data.end(), message.begin(), message.end()); |
4074 | 86 | } | 103 | } |
4075 | 87 | void add_server_message(std::vector<uint8_t> const& message, std::initializer_list<mir::Fd> fds) | 104 | void add_server_message(std::vector<uint8_t> const& message, std::initializer_list<mir::Fd> fds) |
4076 | @@ -95,24 +112,30 @@ | |||
4077 | 95 | return received_data.empty() && received_fds.empty(); | 112 | return received_data.empty() && received_fds.empty(); |
4078 | 96 | } | 113 | } |
4079 | 97 | 114 | ||
4080 | 98 | void notify_data_received() | ||
4081 | 99 | { | ||
4082 | 100 | do | ||
4083 | 101 | { | ||
4084 | 102 | for(auto& observer : observers) | ||
4085 | 103 | observer->on_data_available(); | ||
4086 | 104 | } | ||
4087 | 105 | while (!all_data_consumed()); | ||
4088 | 106 | } | ||
4089 | 107 | |||
4090 | 108 | MOCK_METHOD1(register_observer, void(std::shared_ptr<Observer> const&)); | 115 | MOCK_METHOD1(register_observer, void(std::shared_ptr<Observer> const&)); |
4091 | 109 | MOCK_METHOD1(unregister_observer, void(std::shared_ptr<Observer> const&)); | 116 | MOCK_METHOD1(unregister_observer, void(std::shared_ptr<Observer> const&)); |
4092 | 110 | MOCK_METHOD2(receive_data, void(void*, size_t)); | 117 | MOCK_METHOD2(receive_data, void(void*, size_t)); |
4093 | 111 | MOCK_METHOD3(receive_data, void(void*, size_t, std::vector<mir::Fd>&)); | 118 | MOCK_METHOD3(receive_data, void(void*, size_t, std::vector<mir::Fd>&)); |
4094 | 112 | MOCK_METHOD2(send_message, void(std::vector<uint8_t> const&, std::vector<mir::Fd> const&)); | 119 | MOCK_METHOD2(send_message, void(std::vector<uint8_t> const&, std::vector<mir::Fd> const&)); |
4098 | 113 | MOCK_CONST_METHOD0(watch_fd, mir::Fd()); | 120 | |
4099 | 114 | MOCK_METHOD1(dispatch, bool(md::FdEvents)); | 121 | mir::Fd watch_fd() const override |
4100 | 115 | MOCK_CONST_METHOD0(relevant_events, md::FdEvents()); | 122 | { |
4101 | 123 | return event_fd; | ||
4102 | 124 | } | ||
4103 | 125 | |||
4104 | 126 | bool dispatch(md::FdEvents /*events*/) override | ||
4105 | 127 | { | ||
4106 | 128 | for (auto& observer : observers) | ||
4107 | 129 | { | ||
4108 | 130 | observer->on_data_available(); | ||
4109 | 131 | } | ||
4110 | 132 | return true; | ||
4111 | 133 | } | ||
4112 | 134 | |||
4113 | 135 | md::FdEvents relevant_events() const override | ||
4114 | 136 | { | ||
4115 | 137 | return md::FdEvent::readable; | ||
4116 | 138 | } | ||
4117 | 116 | 139 | ||
4118 | 117 | // Transport interface | 140 | // Transport interface |
4119 | 118 | void register_observer_default(std::shared_ptr<Observer> const& observer) | 141 | void register_observer_default(std::shared_ptr<Observer> const& observer) |
4120 | @@ -128,6 +151,9 @@ | |||
4121 | 128 | 151 | ||
4122 | 129 | void receive_data_default(void* buffer, size_t read_bytes, std::vector<mir::Fd>& fds) | 152 | void receive_data_default(void* buffer, size_t read_bytes, std::vector<mir::Fd>& fds) |
4123 | 130 | { | 153 | { |
4124 | 154 | if (read_bytes == 0) | ||
4125 | 155 | return; | ||
4126 | 156 | |||
4127 | 131 | auto num_fds = fds.size(); | 157 | auto num_fds = fds.size(); |
4128 | 132 | if (read_bytes > received_data.size()) | 158 | if (read_bytes > received_data.size()) |
4129 | 133 | { | 159 | { |
4130 | @@ -143,6 +169,11 @@ | |||
4131 | 143 | 169 | ||
4132 | 144 | received_data.erase(received_data.begin(), received_data.begin() + read_bytes); | 170 | received_data.erase(received_data.begin(), received_data.begin() + read_bytes); |
4133 | 145 | received_fds.erase(received_fds.begin(), received_fds.begin() + num_fds); | 171 | received_fds.erase(received_fds.begin(), received_fds.begin() + num_fds); |
4134 | 172 | |||
4135 | 173 | eventfd_t remaining_bytes; | ||
4136 | 174 | eventfd_read(event_fd, &remaining_bytes); | ||
4137 | 175 | remaining_bytes -= read_bytes; | ||
4138 | 176 | eventfd_write(event_fd, remaining_bytes); | ||
4139 | 146 | } | 177 | } |
4140 | 147 | 178 | ||
4141 | 148 | void send_message_default(std::vector<uint8_t> const& buffer) | 179 | void send_message_default(std::vector<uint8_t> const& buffer) |
4142 | @@ -156,6 +187,9 @@ | |||
4143 | 156 | std::vector<uint8_t> received_data; | 187 | std::vector<uint8_t> received_data; |
4144 | 157 | std::vector<mir::Fd> received_fds; | 188 | std::vector<mir::Fd> received_fds; |
4145 | 158 | std::list<std::vector<uint8_t>> sent_messages; | 189 | std::list<std::vector<uint8_t>> sent_messages; |
4146 | 190 | |||
4147 | 191 | private: | ||
4148 | 192 | mir::Fd event_fd; | ||
4149 | 159 | }; | 193 | }; |
4150 | 160 | 194 | ||
4151 | 161 | class MirProtobufRpcChannelTest : public testing::Test | 195 | class MirProtobufRpcChannelTest : public testing::Test |
4152 | @@ -176,53 +210,56 @@ | |||
4153 | 176 | 210 | ||
4154 | 177 | MockStreamTransport* transport; | 211 | MockStreamTransport* transport; |
4155 | 178 | std::shared_ptr<mcl::LifecycleControl> lifecycle; | 212 | std::shared_ptr<mcl::LifecycleControl> lifecycle; |
4157 | 179 | std::shared_ptr<::google::protobuf::RpcChannel> channel; | 213 | std::shared_ptr<mclr::MirProtobufRpcChannel> channel; |
4158 | 180 | }; | 214 | }; |
4159 | 181 | 215 | ||
4160 | 182 | } | 216 | } |
4161 | 183 | 217 | ||
4204 | 184 | TEST_F(MirProtobufRpcChannelTest, ReadsFullMessages) | 218 | TEST_F(MirProtobufRpcChannelTest, reads_full_messages) |
4205 | 185 | { | 219 | { |
4206 | 186 | std::vector<uint8_t> empty_message(sizeof(uint16_t)); | 220 | std::vector<uint8_t> empty_message(sizeof(uint16_t)); |
4207 | 187 | std::vector<uint8_t> small_message(sizeof(uint16_t) + 8); | 221 | std::vector<uint8_t> small_message(sizeof(uint16_t) + 8); |
4208 | 188 | std::vector<uint8_t> large_message(sizeof(uint16_t) + 4096); | 222 | std::vector<uint8_t> large_message(sizeof(uint16_t) + 4096); |
4209 | 189 | 223 | ||
4210 | 190 | *reinterpret_cast<uint16_t*>(empty_message.data()) = htobe16(0); | 224 | *reinterpret_cast<uint16_t*>(empty_message.data()) = htobe16(0); |
4211 | 191 | *reinterpret_cast<uint16_t*>(small_message.data()) = htobe16(8); | 225 | *reinterpret_cast<uint16_t*>(small_message.data()) = htobe16(8); |
4212 | 192 | *reinterpret_cast<uint16_t*>(large_message.data()) = htobe16(4096); | 226 | *reinterpret_cast<uint16_t*>(large_message.data()) = htobe16(4096); |
4213 | 193 | 227 | ||
4214 | 194 | transport->add_server_message(empty_message); | 228 | transport->add_server_message(empty_message); |
4215 | 195 | transport->notify_data_received(); | 229 | transport->dispatch(md::FdEvent::readable); |
4216 | 196 | EXPECT_TRUE(transport->all_data_consumed()); | 230 | EXPECT_TRUE(transport->all_data_consumed()); |
4217 | 197 | 231 | ||
4218 | 198 | transport->add_server_message(small_message); | 232 | transport->add_server_message(small_message); |
4219 | 199 | transport->notify_data_received(); | 233 | transport->dispatch(md::FdEvent::readable); |
4220 | 200 | EXPECT_TRUE(transport->all_data_consumed()); | 234 | EXPECT_TRUE(transport->all_data_consumed()); |
4221 | 201 | 235 | ||
4222 | 202 | transport->add_server_message(large_message); | 236 | transport->add_server_message(large_message); |
4223 | 203 | transport->notify_data_received(); | 237 | transport->dispatch(md::FdEvent::readable); |
4224 | 204 | EXPECT_TRUE(transport->all_data_consumed()); | 238 | EXPECT_TRUE(transport->all_data_consumed()); |
4225 | 205 | } | 239 | } |
4226 | 206 | 240 | ||
4227 | 207 | TEST_F(MirProtobufRpcChannelTest, ReadsAllQueuedMessages) | 241 | TEST_F(MirProtobufRpcChannelTest, reads_all_queued_messages) |
4228 | 208 | { | 242 | { |
4229 | 209 | std::vector<uint8_t> empty_message(sizeof(uint16_t)); | 243 | std::vector<uint8_t> empty_message(sizeof(uint16_t)); |
4230 | 210 | std::vector<uint8_t> small_message(sizeof(uint16_t) + 8); | 244 | std::vector<uint8_t> small_message(sizeof(uint16_t) + 8); |
4231 | 211 | std::vector<uint8_t> large_message(sizeof(uint16_t) + 4096); | 245 | std::vector<uint8_t> large_message(sizeof(uint16_t) + 4096); |
4232 | 212 | 246 | ||
4233 | 213 | *reinterpret_cast<uint16_t*>(empty_message.data()) = htobe16(0); | 247 | *reinterpret_cast<uint16_t*>(empty_message.data()) = htobe16(0); |
4234 | 214 | *reinterpret_cast<uint16_t*>(small_message.data()) = htobe16(8); | 248 | *reinterpret_cast<uint16_t*>(small_message.data()) = htobe16(8); |
4235 | 215 | *reinterpret_cast<uint16_t*>(large_message.data()) = htobe16(4096); | 249 | *reinterpret_cast<uint16_t*>(large_message.data()) = htobe16(4096); |
4236 | 216 | 250 | ||
4237 | 217 | transport->add_server_message(empty_message); | 251 | transport->add_server_message(empty_message); |
4238 | 218 | transport->add_server_message(small_message); | 252 | transport->add_server_message(small_message); |
4239 | 219 | transport->add_server_message(large_message); | 253 | transport->add_server_message(large_message); |
4240 | 220 | 254 | ||
4241 | 221 | transport->notify_data_received(); | 255 | while(mt::fd_is_readable(channel->watch_fd())) |
4242 | 222 | EXPECT_TRUE(transport->all_data_consumed()); | 256 | { |
4243 | 223 | } | 257 | channel->dispatch(md::FdEvent::readable); |
4244 | 224 | 258 | } | |
4245 | 225 | TEST_F(MirProtobufRpcChannelTest, SendsMessagesAtomically) | 259 | EXPECT_TRUE(transport->all_data_consumed()); |
4246 | 260 | } | ||
4247 | 261 | |||
4248 | 262 | TEST_F(MirProtobufRpcChannelTest, sends_messages_atomically) | ||
4249 | 226 | { | 263 | { |
4250 | 227 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; | 264 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; |
4251 | 228 | mir::protobuf::ConnectParameters message; | 265 | mir::protobuf::ConnectParameters message; |
4252 | @@ -233,7 +270,7 @@ | |||
4253 | 233 | EXPECT_EQ(transport->sent_messages.size(), 1); | 270 | EXPECT_EQ(transport->sent_messages.size(), 1); |
4254 | 234 | } | 271 | } |
4255 | 235 | 272 | ||
4257 | 236 | TEST_F(MirProtobufRpcChannelTest, SetsCorrectSizeWhenSendingMessage) | 273 | TEST_F(MirProtobufRpcChannelTest, sets_correct_size_when_sending_message) |
4258 | 237 | { | 274 | { |
4259 | 238 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; | 275 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; |
4260 | 239 | mir::protobuf::ConnectParameters message; | 276 | mir::protobuf::ConnectParameters message; |
4261 | @@ -246,7 +283,7 @@ | |||
4262 | 246 | EXPECT_EQ(transport->sent_messages.front().size() - sizeof(uint16_t), message_header); | 283 | EXPECT_EQ(transport->sent_messages.front().size() - sizeof(uint16_t), message_header); |
4263 | 247 | } | 284 | } |
4264 | 248 | 285 | ||
4266 | 249 | TEST_F(MirProtobufRpcChannelTest, ReadsFds) | 286 | TEST_F(MirProtobufRpcChannelTest, reads_fds) |
4267 | 250 | { | 287 | { |
4268 | 251 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; | 288 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; |
4269 | 252 | mir::protobuf::Buffer reply; | 289 | mir::protobuf::Buffer reply; |
4270 | @@ -288,7 +325,10 @@ | |||
4271 | 288 | std::vector<uint8_t> dummy = {1}; | 325 | std::vector<uint8_t> dummy = {1}; |
4272 | 289 | transport->add_server_message(dummy, fds); | 326 | transport->add_server_message(dummy, fds); |
4273 | 290 | 327 | ||
4275 | 291 | transport->notify_data_received(); | 328 | while(mt::fd_is_readable(channel->watch_fd())) |
4276 | 329 | { | ||
4277 | 330 | channel->dispatch(md::FdEvent::readable); | ||
4278 | 331 | } | ||
4279 | 292 | } | 332 | } |
4280 | 293 | 333 | ||
4281 | 294 | ASSERT_EQ(reply.fd_size(), fds.size()); | 334 | ASSERT_EQ(reply.fd_size(), fds.size()); |
4282 | @@ -300,7 +340,7 @@ | |||
4283 | 300 | } | 340 | } |
4284 | 301 | } | 341 | } |
4285 | 302 | 342 | ||
4287 | 303 | TEST_F(MirProtobufRpcChannelTest, NotifiesOfDisconnectOnWriteError) | 343 | TEST_F(MirProtobufRpcChannelTest, notifies_of_disconnect_on_write_error) |
4288 | 304 | { | 344 | { |
4289 | 305 | using namespace ::testing; | 345 | using namespace ::testing; |
4290 | 306 | 346 | ||
4291 | @@ -328,7 +368,7 @@ | |||
4292 | 328 | EXPECT_TRUE(disconnected); | 368 | EXPECT_TRUE(disconnected); |
4293 | 329 | } | 369 | } |
4294 | 330 | 370 | ||
4296 | 331 | TEST_F(MirProtobufRpcChannelTest, ForwardsDisconnectNotification) | 371 | TEST_F(MirProtobufRpcChannelTest, forwards_disconnect_notification) |
4297 | 332 | { | 372 | { |
4298 | 333 | using namespace ::testing; | 373 | using namespace ::testing; |
4299 | 334 | 374 | ||
4300 | @@ -350,7 +390,7 @@ | |||
4301 | 350 | EXPECT_TRUE(disconnected); | 390 | EXPECT_TRUE(disconnected); |
4302 | 351 | } | 391 | } |
4303 | 352 | 392 | ||
4305 | 353 | TEST_F(MirProtobufRpcChannelTest, NotifiesOfDisconnectOnlyOnce) | 393 | TEST_F(MirProtobufRpcChannelTest, notifies_of_disconnect_only_once) |
4306 | 354 | { | 394 | { |
4307 | 355 | using namespace ::testing; | 395 | using namespace ::testing; |
4308 | 356 | 396 | ||
4309 | @@ -388,3 +428,196 @@ | |||
4310 | 388 | 428 | ||
4311 | 389 | EXPECT_TRUE(disconnected); | 429 | EXPECT_TRUE(disconnected); |
4312 | 390 | } | 430 | } |
4313 | 431 | |||
4314 | 432 | namespace | ||
4315 | 433 | { | ||
4316 | 434 | void set_flag(bool* flag) | ||
4317 | 435 | { | ||
4318 | 436 | *flag = true; | ||
4319 | 437 | } | ||
4320 | 438 | } | ||
4321 | 439 | |||
4322 | 440 | TEST_F(MirProtobufRpcChannelTest, delays_messages_not_requested) | ||
4323 | 441 | { | ||
4324 | 442 | using namespace ::testing; | ||
4325 | 443 | |||
4326 | 444 | auto typed_channel = std::dynamic_pointer_cast<mclr::MirProtobufRpcChannel>(channel); | ||
4327 | 445 | |||
4328 | 446 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; | ||
4329 | 447 | mir::protobuf::DRMMagic request; | ||
4330 | 448 | mir::protobuf::DRMAuthMagicStatus reply; | ||
4331 | 449 | |||
4332 | 450 | bool first_response_called{false}; | ||
4333 | 451 | bool second_response_called{false}; | ||
4334 | 452 | channel_user.drm_auth_magic(nullptr, | ||
4335 | 453 | &request, | ||
4336 | 454 | &reply, | ||
4337 | 455 | google::protobuf::NewCallback(&set_flag, &first_response_called)); | ||
4338 | 456 | |||
4339 | 457 | typed_channel->process_next_request_first(); | ||
4340 | 458 | channel_user.drm_auth_magic(nullptr, | ||
4341 | 459 | &request, | ||
4342 | 460 | &reply, | ||
4343 | 461 | google::protobuf::NewCallback(&set_flag, &second_response_called)); | ||
4344 | 462 | |||
4345 | 463 | mir::protobuf::wire::Invocation wire_request; | ||
4346 | 464 | mir::protobuf::wire::Result wire_reply; | ||
4347 | 465 | |||
4348 | 466 | wire_request.ParseFromArray(transport->sent_messages.front().data() + sizeof(uint16_t), | ||
4349 | 467 | transport->sent_messages.front().size() - sizeof(uint16_t)); | ||
4350 | 468 | |||
4351 | 469 | transport->sent_messages.pop_front(); | ||
4352 | 470 | |||
4353 | 471 | wire_reply.set_id(wire_request.id()); | ||
4354 | 472 | wire_reply.set_response(reply.SerializeAsString()); | ||
4355 | 473 | |||
4356 | 474 | std::vector<uint8_t> buffer(wire_reply.ByteSize() + sizeof(uint16_t)); | ||
4357 | 475 | *reinterpret_cast<uint16_t*>(buffer.data()) = htobe16(wire_reply.ByteSize()); | ||
4358 | 476 | ASSERT_TRUE(wire_reply.SerializeToArray(buffer.data() + sizeof(uint16_t), buffer.size() - sizeof(uint16_t))); | ||
4359 | 477 | |||
4360 | 478 | transport->add_server_message(buffer); | ||
4361 | 479 | |||
4362 | 480 | wire_request.ParseFromArray(transport->sent_messages.front().data() + sizeof(uint16_t), | ||
4363 | 481 | transport->sent_messages.front().size() - sizeof(uint16_t)); | ||
4364 | 482 | |||
4365 | 483 | transport->sent_messages.pop_front(); | ||
4366 | 484 | |||
4367 | 485 | wire_reply.set_id(wire_request.id()); | ||
4368 | 486 | wire_reply.set_response(reply.SerializeAsString()); | ||
4369 | 487 | |||
4370 | 488 | buffer.resize(wire_reply.ByteSize() + sizeof(uint16_t)); | ||
4371 | 489 | *reinterpret_cast<uint16_t*>(buffer.data()) = htobe16(wire_reply.ByteSize()); | ||
4372 | 490 | ASSERT_TRUE(wire_reply.SerializeToArray(buffer.data() + sizeof(uint16_t), buffer.size() - sizeof(uint16_t))); | ||
4373 | 491 | |||
4374 | 492 | transport->add_server_message(buffer); | ||
4375 | 493 | |||
4376 | 494 | // Read the first message; this should be queued for later processing... | ||
4377 | 495 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4378 | 496 | typed_channel->dispatch(md::FdEvent::readable); | ||
4379 | 497 | |||
4380 | 498 | EXPECT_FALSE(first_response_called); | ||
4381 | 499 | EXPECT_FALSE(second_response_called); | ||
4382 | 500 | |||
4383 | 501 | // Read the second message; this should be processed immediately... | ||
4384 | 502 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4385 | 503 | typed_channel->dispatch(md::FdEvent::readable); | ||
4386 | 504 | |||
4387 | 505 | EXPECT_FALSE(first_response_called); | ||
4388 | 506 | EXPECT_TRUE(second_response_called); | ||
4389 | 507 | |||
4390 | 508 | // Now, the first message should be ready to be processed... | ||
4391 | 509 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4392 | 510 | typed_channel->dispatch(md::FdEvent::readable); | ||
4393 | 511 | |||
4394 | 512 | EXPECT_TRUE(first_response_called); | ||
4395 | 513 | EXPECT_TRUE(second_response_called); | ||
4396 | 514 | } | ||
4397 | 515 | |||
4398 | 516 | TEST_F(MirProtobufRpcChannelTest, delays_messages_with_fds_not_requested) | ||
4399 | 517 | { | ||
4400 | 518 | using namespace ::testing; | ||
4401 | 519 | |||
4402 | 520 | auto typed_channel = std::dynamic_pointer_cast<mclr::MirProtobufRpcChannel>(channel); | ||
4403 | 521 | |||
4404 | 522 | mir::protobuf::DisplayServer::Stub channel_user{channel.get(), mir::protobuf::DisplayServer::STUB_DOESNT_OWN_CHANNEL}; | ||
4405 | 523 | mir::protobuf::DRMMagic drm_request; | ||
4406 | 524 | mir::protobuf::DRMAuthMagicStatus drm_reply; | ||
4407 | 525 | |||
4408 | 526 | mir::protobuf::Buffer buffer_reply; | ||
4409 | 527 | mir::protobuf::BufferRequest buffer_request; | ||
4410 | 528 | |||
4411 | 529 | bool first_response_called{false}; | ||
4412 | 530 | bool second_response_called{false}; | ||
4413 | 531 | |||
4414 | 532 | |||
4415 | 533 | channel_user.exchange_buffer(nullptr, | ||
4416 | 534 | &buffer_request, | ||
4417 | 535 | &buffer_reply, | ||
4418 | 536 | google::protobuf::NewCallback(&set_flag, &first_response_called)); | ||
4419 | 537 | |||
4420 | 538 | typed_channel->process_next_request_first(); | ||
4421 | 539 | channel_user.drm_auth_magic(nullptr, | ||
4422 | 540 | &drm_request, | ||
4423 | 541 | &drm_reply, | ||
4424 | 542 | google::protobuf::NewCallback(&set_flag, &second_response_called)); | ||
4425 | 543 | |||
4426 | 544 | |||
4427 | 545 | std::initializer_list<mir::Fd> fds = {mir::Fd{open("/dev/null", O_RDONLY)}, | ||
4428 | 546 | mir::Fd{open("/dev/null", O_RDONLY)}, | ||
4429 | 547 | mir::Fd{open("/dev/null", O_RDONLY)}}; | ||
4430 | 548 | |||
4431 | 549 | { | ||
4432 | 550 | mir::protobuf::Buffer reply_message; | ||
4433 | 551 | |||
4434 | 552 | for (auto fd : fds) | ||
4435 | 553 | reply_message.add_fd(fd); | ||
4436 | 554 | reply_message.set_fds_on_side_channel(fds.size()); | ||
4437 | 555 | |||
4438 | 556 | mir::protobuf::wire::Invocation request; | ||
4439 | 557 | mir::protobuf::wire::Result reply; | ||
4440 | 558 | |||
4441 | 559 | request.ParseFromArray(transport->sent_messages.front().data() + sizeof(uint16_t), | ||
4442 | 560 | transport->sent_messages.front().size() - sizeof(uint16_t)); | ||
4443 | 561 | |||
4444 | 562 | transport->sent_messages.pop_front(); | ||
4445 | 563 | |||
4446 | 564 | reply.set_id(request.id()); | ||
4447 | 565 | reply.set_response(reply_message.SerializeAsString()); | ||
4448 | 566 | |||
4449 | 567 | ASSERT_TRUE(reply.has_id()); | ||
4450 | 568 | ASSERT_TRUE(reply.has_response()); | ||
4451 | 569 | |||
4452 | 570 | std::vector<uint8_t> buffer(reply.ByteSize() + sizeof(uint16_t)); | ||
4453 | 571 | *reinterpret_cast<uint16_t*>(buffer.data()) = htobe16(reply.ByteSize()); | ||
4454 | 572 | ASSERT_TRUE(reply.SerializeToArray(buffer.data() + sizeof(uint16_t), buffer.size() - sizeof(uint16_t))); | ||
4455 | 573 | |||
4456 | 574 | transport->add_server_message(buffer); | ||
4457 | 575 | |||
4458 | 576 | // Because our protocol is a bit silly... | ||
4459 | 577 | std::vector<uint8_t> dummy = {1}; | ||
4460 | 578 | transport->add_server_message(dummy, fds); | ||
4461 | 579 | } | ||
4462 | 580 | |||
4463 | 581 | { | ||
4464 | 582 | mir::protobuf::DRMAuthMagicStatus reply; | ||
4465 | 583 | |||
4466 | 584 | mir::protobuf::wire::Invocation wire_request; | ||
4467 | 585 | mir::protobuf::wire::Result wire_reply; | ||
4468 | 586 | |||
4469 | 587 | wire_request.ParseFromArray(transport->sent_messages.front().data() + sizeof(uint16_t), | ||
4470 | 588 | transport->sent_messages.front().size() - sizeof(uint16_t)); | ||
4471 | 589 | |||
4472 | 590 | transport->sent_messages.pop_front(); | ||
4473 | 591 | |||
4474 | 592 | wire_reply.set_id(wire_request.id()); | ||
4475 | 593 | wire_reply.set_response(reply.SerializeAsString()); | ||
4476 | 594 | |||
4477 | 595 | std::vector<uint8_t> buffer(wire_reply.ByteSize() + sizeof(uint16_t)); | ||
4478 | 596 | *reinterpret_cast<uint16_t*>(buffer.data()) = htobe16(wire_reply.ByteSize()); | ||
4479 | 597 | ASSERT_TRUE(wire_reply.SerializeToArray(buffer.data() + sizeof(uint16_t), buffer.size() - sizeof(uint16_t))); | ||
4480 | 598 | |||
4481 | 599 | transport->add_server_message(buffer); | ||
4482 | 600 | } | ||
4483 | 601 | |||
4484 | 602 | // Read the first message; this should be queued for later processing... | ||
4485 | 603 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4486 | 604 | typed_channel->dispatch(md::FdEvent::readable); | ||
4487 | 605 | |||
4488 | 606 | EXPECT_FALSE(first_response_called); | ||
4489 | 607 | EXPECT_FALSE(second_response_called); | ||
4490 | 608 | |||
4491 | 609 | // Read the second message; this should be processed immediately... | ||
4492 | 610 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4493 | 611 | typed_channel->dispatch(md::FdEvent::readable); | ||
4494 | 612 | |||
4495 | 613 | EXPECT_FALSE(first_response_called); | ||
4496 | 614 | EXPECT_TRUE(second_response_called); | ||
4497 | 615 | |||
4498 | 616 | // Now, the first message should be ready to be processed... | ||
4499 | 617 | EXPECT_TRUE(mt::fd_is_readable(typed_channel->watch_fd())); | ||
4500 | 618 | typed_channel->dispatch(md::FdEvent::readable); | ||
4501 | 619 | |||
4502 | 620 | EXPECT_TRUE(first_response_called); | ||
4503 | 621 | EXPECT_TRUE(second_response_called); | ||
4504 | 622 | } | ||
4505 | 623 | |||
4506 | 391 | 624 | ||
4507 | === modified file 'tests/unit-tests/dispatch/CMakeLists.txt' | |||
4508 | --- tests/unit-tests/dispatch/CMakeLists.txt 2015-03-31 02:35:42 +0000 | |||
4509 | +++ tests/unit-tests/dispatch/CMakeLists.txt 2015-05-14 07:50:26 +0000 | |||
4510 | @@ -1,6 +1,6 @@ | |||
4511 | 1 | list(APPEND UNIT_TEST_SOURCES | 1 | list(APPEND UNIT_TEST_SOURCES |
4512 | 2 | ${CMAKE_CURRENT_SOURCE_DIR}/test_threaded_dispatcher.cpp | ||
4513 | 2 | ${CMAKE_CURRENT_SOURCE_DIR}/test_action_queue.cpp | 3 | ${CMAKE_CURRENT_SOURCE_DIR}/test_action_queue.cpp |
4514 | 3 | ${CMAKE_CURRENT_SOURCE_DIR}/test_simple_dispatch_thread.cpp | ||
4515 | 4 | ${CMAKE_CURRENT_SOURCE_DIR}/test_multiplexing_dispatchable.cpp | 4 | ${CMAKE_CURRENT_SOURCE_DIR}/test_multiplexing_dispatchable.cpp |
4516 | 5 | ${CMAKE_CURRENT_SOURCE_DIR}/test_dispatch_utils.cpp | 5 | ${CMAKE_CURRENT_SOURCE_DIR}/test_dispatch_utils.cpp |
4517 | 6 | ) | 6 | ) |
4518 | 7 | 7 | ||
4519 | === modified file 'tests/unit-tests/dispatch/test_multiplexing_dispatchable.cpp' | |||
4520 | --- tests/unit-tests/dispatch/test_multiplexing_dispatchable.cpp 2015-02-11 23:15:33 +0000 | |||
4521 | +++ tests/unit-tests/dispatch/test_multiplexing_dispatchable.cpp 2015-05-14 07:50:26 +0000 | |||
4522 | @@ -17,7 +17,7 @@ | |||
4523 | 17 | */ | 17 | */ |
4524 | 18 | 18 | ||
4525 | 19 | #include "mir/dispatch/multiplexing_dispatchable.h" | 19 | #include "mir/dispatch/multiplexing_dispatchable.h" |
4527 | 20 | #include "mir/dispatch/simple_dispatch_thread.h" | 20 | #include "mir/dispatch/threaded_dispatcher.h" |
4528 | 21 | #include "mir/fd.h" | 21 | #include "mir/fd.h" |
4529 | 22 | #include "mir_test/pipe.h" | 22 | #include "mir_test/pipe.h" |
4530 | 23 | #include "mir_test/signal.h" | 23 | #include "mir_test/signal.h" |
4531 | @@ -217,8 +217,8 @@ | |||
4532 | 217 | auto dispatcher = std::make_shared<md::MultiplexingDispatchable>(); | 217 | auto dispatcher = std::make_shared<md::MultiplexingDispatchable>(); |
4533 | 218 | dispatcher->add_watch(dispatchee); | 218 | dispatcher->add_watch(dispatchee); |
4534 | 219 | 219 | ||
4537 | 220 | md::SimpleDispatchThread first_loop{dispatcher}; | 220 | md::ThreadedDispatcher eventloop{"Fools!", dispatcher}; |
4538 | 221 | md::SimpleDispatchThread second_loop{dispatcher}; | 221 | eventloop.add_thread(); |
4539 | 222 | 222 | ||
4540 | 223 | EXPECT_TRUE(second_dispatch->wait_for(std::chrono::seconds{5})); | 223 | EXPECT_TRUE(second_dispatch->wait_for(std::chrono::seconds{5})); |
4541 | 224 | } | 224 | } |
4542 | @@ -315,15 +315,15 @@ | |||
4543 | 315 | 315 | ||
4544 | 316 | dispatchee->trigger(); | 316 | dispatchee->trigger(); |
4545 | 317 | 317 | ||
4547 | 318 | md::SimpleDispatchThread eventloop{dispatcher}; | 318 | md::ThreadedDispatcher eventloop{"I'll destroy", dispatcher}; |
4548 | 319 | 319 | ||
4550 | 320 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{1})); | 320 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{5})); |
4551 | 321 | 321 | ||
4552 | 322 | dispatcher->remove_watch(dispatchee); | 322 | dispatcher->remove_watch(dispatchee); |
4553 | 323 | dispatchee.reset(); | 323 | dispatchee.reset(); |
4554 | 324 | canary.reset(); | 324 | canary.reset(); |
4555 | 325 | 325 | ||
4557 | 326 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{2})); | 326 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{5})); |
4558 | 327 | } | 327 | } |
4559 | 328 | 328 | ||
4560 | 329 | TEST(MultiplexingDispatchableTest, destruction_is_threadsafe) | 329 | TEST(MultiplexingDispatchableTest, destruction_is_threadsafe) |
4561 | @@ -348,28 +348,27 @@ | |||
4562 | 348 | 348 | ||
4563 | 349 | mt::AutoJoinThread dispatch_thread{[dispatcher]() { dispatcher->dispatch(md::FdEvent::readable); }}; | 349 | mt::AutoJoinThread dispatch_thread{[dispatcher]() { dispatcher->dispatch(md::FdEvent::readable); }}; |
4564 | 350 | 350 | ||
4566 | 351 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{1})); | 351 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{5})); |
4567 | 352 | 352 | ||
4568 | 353 | dispatcher->remove_watch(dispatchee); | 353 | dispatcher->remove_watch(dispatchee); |
4569 | 354 | dispatcher.reset(); | 354 | dispatcher.reset(); |
4570 | 355 | dispatchee.reset(); | 355 | dispatchee.reset(); |
4571 | 356 | canary.reset(); | 356 | canary.reset(); |
4572 | 357 | 357 | ||
4574 | 358 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{2})); | 358 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{5})); |
4575 | 359 | } | 359 | } |
4576 | 360 | 360 | ||
4577 | 361 | TEST(MultiplexingDispatchableTest, stress_test_threading) | 361 | TEST(MultiplexingDispatchableTest, stress_test_threading) |
4578 | 362 | { | 362 | { |
4579 | 363 | using namespace testing; | 363 | using namespace testing; |
4580 | 364 | |||
4581 | 365 | int const dispatchee_count{20}; | 364 | int const dispatchee_count{20}; |
4582 | 366 | 365 | ||
4583 | 367 | auto dispatcher = std::make_shared<md::MultiplexingDispatchable>(); | 366 | auto dispatcher = std::make_shared<md::MultiplexingDispatchable>(); |
4584 | 368 | 367 | ||
4586 | 369 | std::vector<std::shared_ptr<md::SimpleDispatchThread>> eventloops; | 368 | auto event_dispatcher = std::make_shared<md::ThreadedDispatcher>(__func__, dispatcher); |
4587 | 370 | for (int i = 0 ; i < dispatchee_count + 5 ; ++i) | 369 | for (int i = 0 ; i < dispatchee_count + 5 ; ++i) |
4588 | 371 | { | 370 | { |
4590 | 372 | eventloops.push_back(std::make_shared<md::SimpleDispatchThread>(dispatcher)); | 371 | event_dispatcher->add_thread(); |
4591 | 373 | } | 372 | } |
4592 | 374 | 373 | ||
4593 | 375 | std::vector<std::shared_ptr<mt::Signal>> canary_tomb; | 374 | std::vector<std::shared_ptr<mt::Signal>> canary_tomb; |
4594 | @@ -397,12 +396,12 @@ | |||
4595 | 397 | 396 | ||
4596 | 398 | dispatchees.clear(); | 397 | dispatchees.clear(); |
4597 | 399 | dispatcher.reset(); | 398 | dispatcher.reset(); |
4599 | 400 | eventloops.clear(); | 399 | event_dispatcher.reset(); |
4600 | 401 | 400 | ||
4601 | 402 | for (auto headstone : canary_tomb) | 401 | for (auto headstone : canary_tomb) |
4602 | 403 | { | 402 | { |
4603 | 404 | // Use assert so as to not block for *ages* on failure | 403 | // Use assert so as to not block for *ages* on failure |
4605 | 405 | ASSERT_TRUE(headstone->wait_for(std::chrono::seconds{2})); | 404 | ASSERT_TRUE(headstone->wait_for(std::chrono::seconds{5})); |
4606 | 406 | } | 405 | } |
4607 | 407 | } | 406 | } |
4608 | 408 | 407 | ||
4609 | @@ -456,10 +455,10 @@ | |||
4610 | 456 | 455 | ||
4611 | 457 | first_dispatchee->trigger(); | 456 | first_dispatchee->trigger(); |
4612 | 458 | 457 | ||
4615 | 459 | md::SimpleDispatchThread eventloop_one{dispatcher}; | 458 | md::ThreadedDispatcher eventloop{"them all!", dispatcher}; |
4616 | 460 | md::SimpleDispatchThread eventloop_two{dispatcher}; | 459 | eventloop.add_thread(); |
4617 | 461 | 460 | ||
4619 | 462 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{1})); | 461 | EXPECT_TRUE(in_dispatch->wait_for(std::chrono::seconds{5})); |
4620 | 463 | 462 | ||
4621 | 464 | dispatcher->remove_watch(dummy_dispatchee); | 463 | dispatcher->remove_watch(dummy_dispatchee); |
4622 | 465 | dispatcher->remove_watch(first_dispatchee); | 464 | dispatcher->remove_watch(first_dispatchee); |
4623 | @@ -470,7 +469,7 @@ | |||
4624 | 470 | 469 | ||
4625 | 471 | unblock_dispatchee->raise(); | 470 | unblock_dispatchee->raise(); |
4626 | 472 | 471 | ||
4628 | 473 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{2})); | 472 | EXPECT_TRUE(canary_killed->wait_for(std::chrono::seconds{5})); |
4629 | 474 | } | 473 | } |
4630 | 475 | 474 | ||
4631 | 476 | TEST(MultiplexingDispatchableTest, automatic_removals_are_threadsafe) | 475 | TEST(MultiplexingDispatchableTest, automatic_removals_are_threadsafe) |
4632 | @@ -481,7 +480,11 @@ | |||
4633 | 481 | 480 | ||
4634 | 482 | dispatcher->add_watch(dispatchee, md::DispatchReentrancy::reentrant); | 481 | dispatcher->add_watch(dispatchee, md::DispatchReentrancy::reentrant); |
4635 | 483 | 482 | ||
4637 | 484 | md::SimpleDispatchThread one{dispatcher}, two{dispatcher}, three{dispatcher}, four{dispatcher}; | 483 | md::ThreadedDispatcher eventloop{"Eeelo", dispatcher}; |
4638 | 484 | |||
4639 | 485 | eventloop.add_thread(); | ||
4640 | 486 | eventloop.add_thread(); | ||
4641 | 487 | eventloop.add_thread(); | ||
4642 | 485 | 488 | ||
4643 | 486 | dispatchee->trigger(); | 489 | dispatchee->trigger(); |
4644 | 487 | } | 490 | } |
4645 | 488 | 491 | ||
4646 | === removed file 'tests/unit-tests/dispatch/test_simple_dispatch_thread.cpp' | |||
4647 | --- tests/unit-tests/dispatch/test_simple_dispatch_thread.cpp 2015-05-01 14:47:55 +0000 | |||
4648 | +++ tests/unit-tests/dispatch/test_simple_dispatch_thread.cpp 1970-01-01 00:00:00 +0000 | |||
4649 | @@ -1,291 +0,0 @@ | |||
4650 | 1 | /* | ||
4651 | 2 | * Copyright © 2015 Canonical Ltd. | ||
4652 | 3 | * | ||
4653 | 4 | * This program is free software: you can redistribute it and/or modify | ||
4654 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
4655 | 6 | * published by the Free Software Foundation. | ||
4656 | 7 | * | ||
4657 | 8 | * This program is distributed in the hope that it will be useful, | ||
4658 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4659 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4660 | 11 | * GNU General Public License for more details. | ||
4661 | 12 | * | ||
4662 | 13 | * You should have received a copy of the GNU General Public License | ||
4663 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4664 | 15 | * | ||
4665 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
4666 | 17 | */ | ||
4667 | 18 | |||
4668 | 19 | #include "mir/dispatch/simple_dispatch_thread.h" | ||
4669 | 20 | #include "mir/dispatch/dispatchable.h" | ||
4670 | 21 | #include "mir/fd.h" | ||
4671 | 22 | #include "mir_test/pipe.h" | ||
4672 | 23 | #include "mir_test/signal.h" | ||
4673 | 24 | #include "mir_test/test_dispatchable.h" | ||
4674 | 25 | #include "mir_test_framework/process.h" | ||
4675 | 26 | #include "mir_test/cross_process_action.h" | ||
4676 | 27 | |||
4677 | 28 | #include <fcntl.h> | ||
4678 | 29 | |||
4679 | 30 | #include <atomic> | ||
4680 | 31 | #include <exception> | ||
4681 | 32 | #include <thread> | ||
4682 | 33 | |||
4683 | 34 | #include <gtest/gtest.h> | ||
4684 | 35 | #include <gmock/gmock.h> | ||
4685 | 36 | |||
4686 | 37 | namespace md = mir::dispatch; | ||
4687 | 38 | namespace mt = mir::test; | ||
4688 | 39 | |||
4689 | 40 | namespace | ||
4690 | 41 | { | ||
4691 | 42 | class SimpleDispatchThreadTest : public ::testing::Test | ||
4692 | 43 | { | ||
4693 | 44 | public: | ||
4694 | 45 | SimpleDispatchThreadTest() | ||
4695 | 46 | { | ||
4696 | 47 | mt::Pipe pipe{O_NONBLOCK}; | ||
4697 | 48 | watch_fd = pipe.read_fd(); | ||
4698 | 49 | test_fd = pipe.write_fd(); | ||
4699 | 50 | } | ||
4700 | 51 | |||
4701 | 52 | mir::Fd watch_fd; | ||
4702 | 53 | mir::Fd test_fd; | ||
4703 | 54 | }; | ||
4704 | 55 | |||
4705 | 56 | class MockDispatchable : public md::Dispatchable | ||
4706 | 57 | { | ||
4707 | 58 | public: | ||
4708 | 59 | MOCK_CONST_METHOD0(watch_fd, mir::Fd()); | ||
4709 | 60 | MOCK_METHOD1(dispatch, bool(md::FdEvents)); | ||
4710 | 61 | MOCK_CONST_METHOD0(relevant_events, md::FdEvents()); | ||
4711 | 62 | }; | ||
4712 | 63 | } | ||
4713 | 64 | |||
4714 | 65 | TEST_F(SimpleDispatchThreadTest, calls_dispatch_when_fd_is_readable) | ||
4715 | 66 | { | ||
4716 | 67 | using namespace testing; | ||
4717 | 68 | |||
4718 | 69 | auto dispatched = std::make_shared<mt::Signal>(); | ||
4719 | 70 | auto dispatchable = std::make_shared<mt::TestDispatchable>([dispatched]() | ||
4720 | 71 | { | ||
4721 | 72 | dispatched->raise(); | ||
4722 | 73 | }); | ||
4723 | 74 | |||
4724 | 75 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4725 | 76 | |||
4726 | 77 | dispatchable->trigger(); | ||
4727 | 78 | |||
4728 | 79 | EXPECT_TRUE(dispatched->wait_for(std::chrono::seconds{1})); | ||
4729 | 80 | } | ||
4730 | 81 | |||
4731 | 82 | TEST_F(SimpleDispatchThreadTest, stops_calling_dispatch_once_fd_is_not_readable) | ||
4732 | 83 | { | ||
4733 | 84 | using namespace testing; | ||
4734 | 85 | |||
4735 | 86 | std::atomic<int> dispatch_count{0}; | ||
4736 | 87 | auto dispatchable = std::make_shared<mt::TestDispatchable>([&dispatch_count]() | ||
4737 | 88 | { | ||
4738 | 89 | ++dispatch_count; | ||
4739 | 90 | }); | ||
4740 | 91 | |||
4741 | 92 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4742 | 93 | |||
4743 | 94 | dispatchable->trigger(); | ||
4744 | 95 | |||
4745 | 96 | std::this_thread::sleep_for(std::chrono::seconds{1}); | ||
4746 | 97 | |||
4747 | 98 | EXPECT_THAT(dispatch_count, Eq(1)); | ||
4748 | 99 | } | ||
4749 | 100 | |||
4750 | 101 | TEST_F(SimpleDispatchThreadTest, passes_dispatch_events_through) | ||
4751 | 102 | { | ||
4752 | 103 | using namespace testing; | ||
4753 | 104 | |||
4754 | 105 | auto dispatched_with_only_readable = std::make_shared<mt::Signal>(); | ||
4755 | 106 | auto dispatched_with_hangup = std::make_shared<mt::Signal>(); | ||
4756 | 107 | auto delegate = [dispatched_with_only_readable, dispatched_with_hangup](md::FdEvents events) | ||
4757 | 108 | { | ||
4758 | 109 | if (events == md::FdEvent::readable) | ||
4759 | 110 | { | ||
4760 | 111 | dispatched_with_only_readable->raise(); | ||
4761 | 112 | } | ||
4762 | 113 | if (events & md::FdEvent::remote_closed) | ||
4763 | 114 | { | ||
4764 | 115 | dispatched_with_hangup->raise(); | ||
4765 | 116 | return false; | ||
4766 | 117 | } | ||
4767 | 118 | return true; | ||
4768 | 119 | }; | ||
4769 | 120 | auto dispatchable = | ||
4770 | 121 | std::make_shared<mt::TestDispatchable>(delegate, md::FdEvent::readable | md::FdEvent::remote_closed); | ||
4771 | 122 | |||
4772 | 123 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4773 | 124 | |||
4774 | 125 | dispatchable->trigger(); | ||
4775 | 126 | EXPECT_TRUE(dispatched_with_only_readable->wait_for(std::chrono::seconds{1})); | ||
4776 | 127 | |||
4777 | 128 | dispatchable->hangup(); | ||
4778 | 129 | EXPECT_TRUE(dispatched_with_hangup->wait_for(std::chrono::seconds{1})); | ||
4779 | 130 | } | ||
4780 | 131 | |||
4781 | 132 | TEST_F(SimpleDispatchThreadTest, doesnt_call_dispatch_after_first_false_return) | ||
4782 | 133 | { | ||
4783 | 134 | using namespace testing; | ||
4784 | 135 | using namespace std::chrono_literals; | ||
4785 | 136 | |||
4786 | 137 | int constexpr expected_count{10}; | ||
4787 | 138 | auto const dispatched_more_than_enough = std::make_shared<mt::Signal>(); | ||
4788 | 139 | |||
4789 | 140 | auto delegate = | ||
4790 | 141 | [dispatched_more_than_enough, dispatch_count = 0](md::FdEvents) mutable | ||
4791 | 142 | { | ||
4792 | 143 | if (++dispatch_count == expected_count) | ||
4793 | 144 | { | ||
4794 | 145 | return false; | ||
4795 | 146 | } | ||
4796 | 147 | if (dispatch_count > expected_count) | ||
4797 | 148 | { | ||
4798 | 149 | dispatched_more_than_enough->raise(); | ||
4799 | 150 | } | ||
4800 | 151 | return true; | ||
4801 | 152 | }; | ||
4802 | 153 | auto const dispatchable = std::make_shared<mt::TestDispatchable>(delegate); | ||
4803 | 154 | |||
4804 | 155 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4805 | 156 | |||
4806 | 157 | for (int i = 0; i < expected_count + 1; ++i) | ||
4807 | 158 | { | ||
4808 | 159 | dispatchable->trigger(); | ||
4809 | 160 | } | ||
4810 | 161 | |||
4811 | 162 | EXPECT_FALSE(dispatched_more_than_enough->wait_for(1s)); | ||
4812 | 163 | } | ||
4813 | 164 | |||
4814 | 165 | TEST_F(SimpleDispatchThreadTest, only_calls_dispatch_with_remote_closed_when_relevant) | ||
4815 | 166 | { | ||
4816 | 167 | using namespace testing; | ||
4817 | 168 | |||
4818 | 169 | auto dispatchable = std::make_shared<NiceMock<MockDispatchable>>(); | ||
4819 | 170 | ON_CALL(*dispatchable, watch_fd()).WillByDefault(Return(test_fd)); | ||
4820 | 171 | ON_CALL(*dispatchable, relevant_events()).WillByDefault(Return(md::FdEvent::writable)); | ||
4821 | 172 | auto dispatched_writable = std::make_shared<mt::Signal>(); | ||
4822 | 173 | auto dispatched_closed = std::make_shared<mt::Signal>(); | ||
4823 | 174 | |||
4824 | 175 | ON_CALL(*dispatchable, dispatch(_)).WillByDefault(Invoke([=](md::FdEvents events) | ||
4825 | 176 | { | ||
4826 | 177 | if (events & md::FdEvent::writable) | ||
4827 | 178 | { | ||
4828 | 179 | dispatched_writable->raise(); | ||
4829 | 180 | } | ||
4830 | 181 | if (events & md::FdEvent::remote_closed) | ||
4831 | 182 | { | ||
4832 | 183 | dispatched_closed->raise(); | ||
4833 | 184 | } | ||
4834 | 185 | return true; | ||
4835 | 186 | })); | ||
4836 | 187 | |||
4837 | 188 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4838 | 189 | |||
4839 | 190 | EXPECT_TRUE(dispatched_writable->wait_for(std::chrono::seconds{1})); | ||
4840 | 191 | |||
4841 | 192 | // Make the fd remote-closed... | ||
4842 | 193 | watch_fd = mir::Fd{}; | ||
4843 | 194 | EXPECT_FALSE(dispatched_closed->wait_for(std::chrono::seconds{1})); | ||
4844 | 195 | } | ||
4845 | 196 | |||
4846 | 197 | // Regression test for: lp #1439719 | ||
4847 | 198 | // The bug involves uninitialized memory and is also sensitive to signal | ||
4848 | 199 | // timings, so this test does not always catch the problem. However, repeated | ||
4849 | 200 | // runs (~300, YMMV) consistently fail when run against the problematic code. | ||
4850 | 201 | TEST_F(SimpleDispatchThreadTest, keeps_dispatching_after_signal_interruption) | ||
4851 | 202 | { | ||
4852 | 203 | using namespace std::chrono_literals; | ||
4853 | 204 | mt::CrossProcessAction stop_and_restart_process; | ||
4854 | 205 | |||
4855 | 206 | auto child = mir_test_framework::fork_and_run_in_a_different_process( | ||
4856 | 207 | [&] | ||
4857 | 208 | { | ||
4858 | 209 | auto dispatched = std::make_shared<mt::Signal>(); | ||
4859 | 210 | auto dispatchable = std::make_shared<mt::TestDispatchable>( | ||
4860 | 211 | [dispatched]() { dispatched->raise(); }); | ||
4861 | 212 | |||
4862 | 213 | md::SimpleDispatchThread dispatcher{dispatchable}; | ||
4863 | 214 | // Ensure the dispatcher has started | ||
4864 | 215 | dispatchable->trigger(); | ||
4865 | 216 | EXPECT_TRUE(dispatched->wait_for(1s)); | ||
4866 | 217 | |||
4867 | 218 | stop_and_restart_process(); | ||
4868 | 219 | |||
4869 | 220 | dispatched->reset(); | ||
4870 | 221 | // The dispatcher shouldn't have been affected by the signal | ||
4871 | 222 | dispatchable->trigger(); | ||
4872 | 223 | EXPECT_TRUE(dispatched->wait_for(1s)); | ||
4873 | 224 | exit(HasFailure() ? EXIT_FAILURE : EXIT_SUCCESS); | ||
4874 | 225 | }, | ||
4875 | 226 | []{ return 1; }); | ||
4876 | 227 | |||
4877 | 228 | stop_and_restart_process.exec( | ||
4878 | 229 | [child] | ||
4879 | 230 | { | ||
4880 | 231 | // Increase chances of interrupting the dispatch mechanism | ||
4881 | 232 | for (int i = 0; i < 100; ++i) | ||
4882 | 233 | { | ||
4883 | 234 | child->stop(); | ||
4884 | 235 | child->cont(); | ||
4885 | 236 | } | ||
4886 | 237 | }); | ||
4887 | 238 | |||
4888 | 239 | auto const result = child->wait_for_termination(10s); | ||
4889 | 240 | EXPECT_TRUE(result.succeeded()); | ||
4890 | 241 | } | ||
4891 | 242 | |||
4892 | 243 | using SimpleDispatchThreadDeathTest = SimpleDispatchThreadTest; | ||
4893 | 244 | |||
4894 | 245 | TEST_F(SimpleDispatchThreadDeathTest, destroying_dispatcher_from_a_callback_is_an_error) | ||
4895 | 246 | { | ||
4896 | 247 | using namespace testing; | ||
4897 | 248 | using namespace std::literals::chrono_literals; | ||
4898 | 249 | |||
4899 | 250 | EXPECT_EXIT( | ||
4900 | 251 | { | ||
4901 | 252 | std::mutex mutex; | ||
4902 | 253 | md::SimpleDispatchThread* dispatcher; | ||
4903 | 254 | |||
4904 | 255 | auto dispatchable = std::make_shared<mt::TestDispatchable>([&dispatcher, &mutex]{ | ||
4905 | 256 | std::lock_guard<decltype(mutex)> lock{mutex}; | ||
4906 | 257 | delete dispatcher; | ||
4907 | 258 | }); | ||
4908 | 259 | |||
4909 | 260 | { | ||
4910 | 261 | std::lock_guard<decltype(mutex)> lock{mutex}; | ||
4911 | 262 | dispatchable->trigger(); | ||
4912 | 263 | dispatcher = new md::SimpleDispatchThread{dispatchable}; | ||
4913 | 264 | } | ||
4914 | 265 | std::this_thread::sleep_for(10s); | ||
4915 | 266 | }, KilledBySignal(SIGABRT), ".*Destroying SimpleDispatchThread.*"); | ||
4916 | 267 | } | ||
4917 | 268 | |||
4918 | 269 | TEST_F(SimpleDispatchThreadTest, executes_exception_handler_with_current_exception) | ||
4919 | 270 | { | ||
4920 | 271 | using namespace std::chrono_literals; | ||
4921 | 272 | auto dispatched = std::make_shared<mt::Signal>(); | ||
4922 | 273 | std::exception_ptr exception; | ||
4923 | 274 | |||
4924 | 275 | auto dispatchable = std::make_shared<mt::TestDispatchable>( | ||
4925 | 276 | []() | ||
4926 | 277 | { | ||
4927 | 278 | throw std::runtime_error("thrown"); | ||
4928 | 279 | }); | ||
4929 | 280 | |||
4930 | 281 | md::SimpleDispatchThread dispatcher{dispatchable, | ||
4931 | 282 | [&dispatched,&exception]() | ||
4932 | 283 | { | ||
4933 | 284 | exception = std::current_exception(); | ||
4934 | 285 | if (exception) | ||
4935 | 286 | dispatched->raise(); | ||
4936 | 287 | }}; | ||
4937 | 288 | dispatchable->trigger(); | ||
4938 | 289 | EXPECT_TRUE(dispatched->wait_for(10s)); | ||
4939 | 290 | EXPECT_TRUE(exception!=nullptr); | ||
4940 | 291 | } | ||
4941 | 292 | 0 | ||
4942 | === added file 'tests/unit-tests/dispatch/test_threaded_dispatcher.cpp' | |||
4943 | --- tests/unit-tests/dispatch/test_threaded_dispatcher.cpp 1970-01-01 00:00:00 +0000 | |||
4944 | +++ tests/unit-tests/dispatch/test_threaded_dispatcher.cpp 2015-05-14 07:50:26 +0000 | |||
4945 | @@ -0,0 +1,403 @@ | |||
4946 | 1 | /* | ||
4947 | 2 | * Copyright © 2015 Canonical Ltd. | ||
4948 | 3 | * | ||
4949 | 4 | * This program is free software: you can redistribute it and/or modify | ||
4950 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
4951 | 6 | * published by the Free Software Foundation. | ||
4952 | 7 | * | ||
4953 | 8 | * This program is distributed in the hope that it will be useful, | ||
4954 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4955 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4956 | 11 | * GNU General Public License for more details. | ||
4957 | 12 | * | ||
4958 | 13 | * You should have received a copy of the GNU General Public License | ||
4959 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4960 | 15 | * | ||
4961 | 16 | * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> | ||
4962 | 17 | */ | ||
4963 | 18 | |||
4964 | 19 | #include "mir/dispatch/threaded_dispatcher.h" | ||
4965 | 20 | #include "mir/dispatch/dispatchable.h" | ||
4966 | 21 | #include "mir/fd.h" | ||
4967 | 22 | #include "mir_test/pipe.h" | ||
4968 | 23 | #include "mir_test/signal.h" | ||
4969 | 24 | #include "mir_test/test_dispatchable.h" | ||
4970 | 25 | #include "mir_test_framework/process.h" | ||
4971 | 26 | #include "mir_test/cross_process_action.h" | ||
4972 | 27 | |||
4973 | 28 | #include <fcntl.h> | ||
4974 | 29 | |||
4975 | 30 | #include <atomic> | ||
4976 | 31 | #include <thread> | ||
4977 | 32 | |||
4978 | 33 | #include <gtest/gtest.h> | ||
4979 | 34 | #include <gmock/gmock.h> | ||
4980 | 35 | |||
4981 | 36 | namespace md = mir::dispatch; | ||
4982 | 37 | namespace mt = mir::test; | ||
4983 | 38 | |||
4984 | 39 | namespace | ||
4985 | 40 | { | ||
4986 | 41 | class ThreadedDispatcherTest : public ::testing::Test | ||
4987 | 42 | { | ||
4988 | 43 | public: | ||
4989 | 44 | ThreadedDispatcherTest() | ||
4990 | 45 | { | ||
4991 | 46 | mt::Pipe pipe{O_NONBLOCK}; | ||
4992 | 47 | watch_fd = pipe.read_fd(); | ||
4993 | 48 | test_fd = pipe.write_fd(); | ||
4994 | 49 | } | ||
4995 | 50 | |||
4996 | 51 | mir::Fd watch_fd; | ||
4997 | 52 | mir::Fd test_fd; | ||
4998 | 53 | }; | ||
4999 | 54 | |||
5000 | 55 | class MockDispatchable : public md::Dispatchable |
Marked as WIP; I'll break this up to make the review easier.