Merge lp:~alan-griffiths/mir/rework-BroadcastingSessionEventSink-for-greyback into lp:mir
- rework-BroadcastingSessionEventSink-for-greyback
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Chris Halse Rogers |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4232 |
Proposed branch: | lp:~alan-griffiths/mir/rework-BroadcastingSessionEventSink-for-greyback |
Merge into: | lp:mir |
Diff against target: |
610 lines (+151/-188) 13 files modified
src/include/common/mir/thread_safe_list.h (+3/-3) src/include/server/mir/scene/session_event_handler_register.h (+3/-8) src/server/input/config_changer.cpp (+26/-19) src/server/input/config_changer.h (+2/-0) src/server/scene/broadcasting_session_event_sink.cpp (+16/-59) src/server/scene/broadcasting_session_event_sink.h (+10/-20) src/server/scene/mediating_display_changer.cpp (+48/-35) src/server/scene/mediating_display_changer.h (+5/-1) src/server/scene/session_manager.cpp (+1/-1) tests/include/mir/test/doubles/null_session_event_sink.h (+1/-1) tests/unit-tests/scene/test_abstract_shell.cpp (+1/-1) tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp (+34/-39) tests/unit-tests/scene/test_session_manager.cpp (+1/-1) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/rework-BroadcastingSessionEventSink-for-greyback |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Halse Rogers | Approve | ||
Mir CI Bot | continuous-integration | Approve | |
Review via email: mp+329262@code.launchpad.net |
Commit message
Reimplement BroadcastingSes
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
Chris Halse Rogers (raof) wrote : | # |
So, I'd quite like to gradually migrate all our observer-pattern code to use mir::ObserverRe
Both for consistency's sake, but also because being able to associate the Observer with an Executor makes MediatingDispla
Chris Halse Rogers (raof) wrote : | # |
Oh. I marked that as “needs information”. I actually meant “let me just finish the branch that migrates to ObserverRegistrar, and see how that looks.
Alan Griffiths (alan-griffiths) wrote : | # |
> Oh. I marked that as “needs information”. I actually meant “let me just finish
> the branch that migrates to ObserverRegistrar, and see how that looks.
Sure. I was just offering a viable solution that didn't lead to intermittent test failures.
Chris Halse Rogers (raof) wrote : | # |
Yeah, let's just land this.
I can migrate stuff to ObserverRegistrar later.
Preview Diff
1 | === modified file 'src/include/common/mir/thread_safe_list.h' |
2 | --- src/include/common/mir/thread_safe_list.h 2017-07-28 17:00:43 +0000 |
3 | +++ src/include/common/mir/thread_safe_list.h 2017-08-18 15:06:41 +0000 |
4 | @@ -34,7 +34,7 @@ |
5 | * - copy-assignable |
6 | * - add(): |
7 | * - copy-assignable |
8 | - * - operator bool: returns whether this is a valid element |
9 | + * - conversion to bool: indicates whether this is a valid element |
10 | * - remove(), remove_all(): |
11 | * - copy-assignable |
12 | * - Element{}: default construction should create an invalid element |
13 | @@ -42,7 +42,7 @@ |
14 | * - bool operator!=: inequality of elements |
15 | * - clear(): |
16 | * - copy-assignable |
17 | - * - Element{}: default construction should create an invalid element |
18 | + * - Element{}: value initialization should create an invalid element |
19 | */ |
20 | |
21 | template<class Element> |
22 | @@ -60,7 +60,7 @@ |
23 | { |
24 | ListItem() {} |
25 | RecursiveReadWriteMutex mutex; |
26 | - Element element; |
27 | + Element element{}; |
28 | std::atomic<ListItem*> next{nullptr}; |
29 | |
30 | ~ListItem() { delete next.load(); } |
31 | |
32 | === modified file 'src/include/server/mir/scene/session_event_handler_register.h' |
33 | --- src/include/server/mir/scene/session_event_handler_register.h 2017-07-28 17:00:43 +0000 |
34 | +++ src/include/server/mir/scene/session_event_handler_register.h 2017-08-18 15:06:41 +0000 |
35 | @@ -19,26 +19,21 @@ |
36 | #ifndef MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ |
37 | #define MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ |
38 | |
39 | -#include <functional> |
40 | #include <memory> |
41 | |
42 | namespace mir |
43 | { |
44 | namespace scene |
45 | { |
46 | -class Session; |
47 | +class SessionEventSink; |
48 | |
49 | class SessionEventHandlerRegister |
50 | { |
51 | public: |
52 | virtual ~SessionEventHandlerRegister() = default; |
53 | |
54 | - virtual void register_focus_change_handler( |
55 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0; |
56 | - virtual void register_no_focus_handler( |
57 | - std::function<void()> const& handler) = 0; |
58 | - virtual void register_session_stopping_handler( |
59 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0; |
60 | + virtual void add(SessionEventSink* handler) = 0; |
61 | + virtual void remove(SessionEventSink* handler) = 0; |
62 | |
63 | protected: |
64 | SessionEventHandlerRegister() = default; |
65 | |
66 | === renamed file 'src/server/scene/session_event_sink.h' => 'src/include/server/mir/scene/session_event_sink.h' |
67 | === modified file 'src/server/input/config_changer.cpp' |
68 | --- src/server/input/config_changer.cpp 2017-07-28 17:00:43 +0000 |
69 | +++ src/server/input/config_changer.cpp 2017-08-18 15:06:41 +0000 |
70 | @@ -19,6 +19,7 @@ |
71 | #include "config_changer.h" |
72 | |
73 | #include "mir/scene/session_event_handler_register.h" |
74 | +#include "mir/scene/session_event_sink.h" |
75 | #include "mir/scene/session_container.h" |
76 | #include "mir/scene/session.h" |
77 | #include "mir/input/device.h" |
78 | @@ -137,9 +138,30 @@ |
79 | std::vector<std::shared_ptr<mi::Device>> added; |
80 | std::vector<MirInputDeviceId> removed; |
81 | }; |
82 | - |
83 | } |
84 | |
85 | +struct mi::ConfigChanger::SessionObserver : ms::SessionEventSink |
86 | +{ |
87 | + SessionObserver(mi::ConfigChanger& self) : self{self} {} |
88 | + |
89 | + void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override |
90 | + { |
91 | + self.focus_change_handler(session); |
92 | + } |
93 | + |
94 | + void handle_no_focus() override |
95 | + { |
96 | + self.no_focus_handler(); |
97 | + } |
98 | + |
99 | + void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override |
100 | + { |
101 | + self.session_stopping_handler(session); |
102 | + } |
103 | + |
104 | + mi::ConfigChanger& self; |
105 | +}; |
106 | + |
107 | mi::ConfigChanger::ConfigChanger( |
108 | std::shared_ptr<InputManager> const& manager, |
109 | std::shared_ptr<InputDeviceHub> const& devices, |
110 | @@ -152,31 +174,16 @@ |
111 | session_event_handler_register{session_event_handler_register}, |
112 | devices_wrapper_DO_NOT_USE{devices_wrapper}, |
113 | device_observer(std::make_shared<DeviceChangeTracker>(*this)), |
114 | + session_observer{std::make_unique<SessionObserver>(*this)}, |
115 | base_configuration_applied(true) |
116 | { |
117 | devices->add_observer(device_observer); |
118 | - |
119 | - session_event_handler_register->register_focus_change_handler( |
120 | - [this](std::shared_ptr<ms::Session> const& session) |
121 | - { |
122 | - focus_change_handler(session); |
123 | - }); |
124 | - |
125 | - session_event_handler_register->register_no_focus_handler( |
126 | - [this] |
127 | - { |
128 | - no_focus_handler(); |
129 | - }); |
130 | - |
131 | - session_event_handler_register->register_session_stopping_handler( |
132 | - [this](std::shared_ptr<ms::Session> const& session) |
133 | - { |
134 | - session_stopping_handler(session); |
135 | - }); |
136 | + session_event_handler_register->add(session_observer.get()); |
137 | } |
138 | |
139 | mi::ConfigChanger::~ConfigChanger() |
140 | { |
141 | + session_event_handler_register->remove(session_observer.get()); |
142 | devices->remove_observer(device_observer); |
143 | } |
144 | |
145 | |
146 | === modified file 'src/server/input/config_changer.h' |
147 | --- src/server/input/config_changer.h 2017-07-28 17:00:43 +0000 |
148 | +++ src/server/input/config_changer.h 2017-08-18 15:06:41 +0000 |
149 | @@ -70,6 +70,8 @@ |
150 | // needs to be owned (but not used) in Mir, where better? |
151 | std::shared_ptr<InputDeviceHub> const devices_wrapper_DO_NOT_USE; |
152 | std::shared_ptr<InputDeviceObserver> const device_observer; |
153 | + struct SessionObserver; |
154 | + std::unique_ptr<SessionObserver> const session_observer; |
155 | bool base_configuration_applied; |
156 | |
157 | std::weak_ptr<frontend::Session> focused_session; |
158 | |
159 | === modified file 'src/server/scene/broadcasting_session_event_sink.cpp' |
160 | --- src/server/scene/broadcasting_session_event_sink.cpp 2017-07-28 17:00:43 +0000 |
161 | +++ src/server/scene/broadcasting_session_event_sink.cpp 2017-08-18 15:06:41 +0000 |
162 | @@ -20,75 +20,32 @@ |
163 | |
164 | namespace ms = mir::scene; |
165 | |
166 | -/* |
167 | - * TODO: Use Boost.Signals2 for this when we default to Boost 1.54, see |
168 | - * https://svn.boost.org/trac/boost/ticket/8102 . For now, just use a custom |
169 | - * mechanism with coarse locking. When emitting events, we copy the handlers |
170 | - * to a temporary vector to avoid calling handlers while locked, while still |
171 | - * being thread-safe. |
172 | - */ |
173 | - |
174 | void ms::BroadcastingSessionEventSink::handle_focus_change( |
175 | std::shared_ptr<Session> const& session) |
176 | { |
177 | - std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers; |
178 | - |
179 | - { |
180 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
181 | - handlers = focus_change_handlers; |
182 | - } |
183 | - |
184 | - for (auto& handler : handlers) |
185 | - handler(session); |
186 | + for_each([&](SessionEventSink* observer) |
187 | + { observer->handle_focus_change(session); }); |
188 | } |
189 | |
190 | void ms::BroadcastingSessionEventSink::handle_no_focus() |
191 | { |
192 | - std::vector<std::function<void()>> handlers; |
193 | - |
194 | - { |
195 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
196 | - handlers = no_focus_handlers; |
197 | - } |
198 | - |
199 | - for (auto& handler : handlers) |
200 | - handler(); |
201 | + for_each([&](SessionEventSink* observer) |
202 | + { observer->handle_no_focus(); }); |
203 | } |
204 | |
205 | void ms::BroadcastingSessionEventSink::handle_session_stopping( |
206 | std::shared_ptr<Session> const& session) |
207 | { |
208 | - std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers; |
209 | - |
210 | - { |
211 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
212 | - handlers = session_stopping_handlers; |
213 | - } |
214 | - |
215 | - for (auto& handler : handlers) |
216 | - handler(session); |
217 | -} |
218 | - |
219 | -void ms::BroadcastingSessionEventSink::register_focus_change_handler( |
220 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler) |
221 | -{ |
222 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
223 | - |
224 | - focus_change_handlers.push_back(handler); |
225 | -} |
226 | - |
227 | -void ms::BroadcastingSessionEventSink::register_no_focus_handler( |
228 | - std::function<void()> const& handler) |
229 | -{ |
230 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
231 | - |
232 | - no_focus_handlers.push_back(handler); |
233 | -} |
234 | - |
235 | -void ms::BroadcastingSessionEventSink::register_session_stopping_handler( |
236 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler) |
237 | -{ |
238 | - std::lock_guard<std::mutex> lg{handler_mutex}; |
239 | - |
240 | - session_stopping_handlers.push_back(handler); |
241 | + for_each([&](SessionEventSink* observer) |
242 | + { observer->handle_session_stopping(session); }); |
243 | +} |
244 | + |
245 | +void ms::BroadcastingSessionEventSink::add(SessionEventSink* handler) |
246 | +{ |
247 | + ThreadSafeList<SessionEventSink*>::add(handler); |
248 | +} |
249 | + |
250 | +void ms::BroadcastingSessionEventSink::remove(SessionEventSink* handler) |
251 | +{ |
252 | + ThreadSafeList<SessionEventSink*>::remove(handler); |
253 | } |
254 | |
255 | === modified file 'src/server/scene/broadcasting_session_event_sink.h' |
256 | --- src/server/scene/broadcasting_session_event_sink.h 2017-07-28 17:00:43 +0000 |
257 | +++ src/server/scene/broadcasting_session_event_sink.h 2017-08-18 15:06:41 +0000 |
258 | @@ -19,36 +19,26 @@ |
259 | #ifndef MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ |
260 | #define MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ |
261 | |
262 | -#include "session_event_sink.h" |
263 | +#include "mir/scene/session_event_sink.h" |
264 | #include "mir/scene/session_event_handler_register.h" |
265 | |
266 | -#include <vector> |
267 | -#include <mutex> |
268 | +#include "mir/thread_safe_list.h" |
269 | |
270 | namespace mir |
271 | { |
272 | namespace scene |
273 | { |
274 | class BroadcastingSessionEventSink : public SessionEventSink, |
275 | - public SessionEventHandlerRegister |
276 | + public SessionEventHandlerRegister, |
277 | + private ThreadSafeList<SessionEventSink*> |
278 | { |
279 | public: |
280 | - void handle_focus_change(std::shared_ptr<Session> const& session); |
281 | - void handle_no_focus(); |
282 | - void handle_session_stopping(std::shared_ptr<Session> const& session); |
283 | - |
284 | - void register_focus_change_handler( |
285 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler); |
286 | - void register_no_focus_handler( |
287 | - std::function<void()> const& handler); |
288 | - void register_session_stopping_handler( |
289 | - std::function<void(std::shared_ptr<Session> const& session)> const& handler); |
290 | - |
291 | -private: |
292 | - std::mutex handler_mutex; |
293 | - std::vector<std::function<void(std::shared_ptr<Session> const&)>> focus_change_handlers; |
294 | - std::vector<std::function<void()>> no_focus_handlers; |
295 | - std::vector<std::function<void(std::shared_ptr<Session> const&)>> session_stopping_handlers; |
296 | + void handle_focus_change(std::shared_ptr<Session> const& session) override; |
297 | + void handle_no_focus() override; |
298 | + void handle_session_stopping(std::shared_ptr<Session> const& session) override; |
299 | + |
300 | + void add(SessionEventSink* handler) override; |
301 | + void remove(SessionEventSink* handler) override; |
302 | }; |
303 | |
304 | } |
305 | |
306 | === modified file 'src/server/scene/mediating_display_changer.cpp' |
307 | --- src/server/scene/mediating_display_changer.cpp 2017-08-09 15:03:31 +0000 |
308 | +++ src/server/scene/mediating_display_changer.cpp 2017-08-18 15:06:41 +0000 |
309 | @@ -23,6 +23,7 @@ |
310 | #include "mir/scene/session_container.h" |
311 | #include "mir/scene/session.h" |
312 | #include "mir/scene/session_event_handler_register.h" |
313 | +#include "mir/scene/session_event_sink.h" |
314 | #include "mir/graphics/display.h" |
315 | #include "mir/compositor/compositor.h" |
316 | #include "mir/geometry/rectangles.h" |
317 | @@ -124,6 +125,45 @@ |
318 | }; |
319 | } |
320 | |
321 | +struct ms::MediatingDisplayChanger::SessionObserver : ms::SessionEventSink |
322 | +{ |
323 | + SessionObserver(ms::MediatingDisplayChanger* self) : self{self} {} |
324 | + |
325 | + void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override |
326 | + { |
327 | + auto const weak_session = std::weak_ptr<ms::Session>(session); |
328 | + self->server_action_queue->enqueue( |
329 | + self, |
330 | + [self=self,weak_session] |
331 | + { |
332 | + if (auto const session = weak_session.lock()) |
333 | + self->focus_change_handler(session); |
334 | + }); |
335 | + } |
336 | + |
337 | + void handle_no_focus() override |
338 | + { |
339 | + self->server_action_queue->enqueue( |
340 | + self, |
341 | + [self=self] { self->no_focus_handler(); }); |
342 | + } |
343 | + |
344 | + void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override |
345 | + { |
346 | + auto const weak_session = std::weak_ptr<ms::Session>(session); |
347 | + self->server_action_queue->enqueue( |
348 | + self, |
349 | + [self=self,weak_session] |
350 | + { |
351 | + if (auto const session = weak_session.lock()) |
352 | + self->session_stopping_handler(session); |
353 | + }); |
354 | + } |
355 | + |
356 | + ms::MediatingDisplayChanger* const self; |
357 | +}; |
358 | + |
359 | + |
360 | ms::MediatingDisplayChanger::MediatingDisplayChanger( |
361 | std::shared_ptr<mg::Display> const& display, |
362 | std::shared_ptr<mc::Compositor> const& compositor, |
363 | @@ -142,45 +182,18 @@ |
364 | observer{observer}, |
365 | base_configuration_{display->configuration()}, |
366 | base_configuration_applied{true}, |
367 | - alarm_factory{alarm_factory} |
368 | + alarm_factory{alarm_factory}, |
369 | + session_observer{std::make_unique<SessionObserver>(this)} |
370 | { |
371 | - session_event_handler_register->register_focus_change_handler( |
372 | - [this](std::shared_ptr<ms::Session> const& session) |
373 | - { |
374 | - auto const weak_session = std::weak_ptr<ms::Session>(session); |
375 | - this->server_action_queue->enqueue( |
376 | - this, |
377 | - [this,weak_session] |
378 | - { |
379 | - if (auto const session = weak_session.lock()) |
380 | - focus_change_handler(session); |
381 | - }); |
382 | - }); |
383 | - |
384 | - session_event_handler_register->register_no_focus_handler( |
385 | - [this] |
386 | - { |
387 | - this->server_action_queue->enqueue( |
388 | - this, |
389 | - [this] { no_focus_handler(); }); |
390 | - }); |
391 | - |
392 | - session_event_handler_register->register_session_stopping_handler( |
393 | - [this](std::shared_ptr<ms::Session> const& session) |
394 | - { |
395 | - auto const weak_session = std::weak_ptr<ms::Session>(session); |
396 | - this->server_action_queue->enqueue( |
397 | - this, |
398 | - [this,weak_session] |
399 | - { |
400 | - if (auto const session = weak_session.lock()) |
401 | - session_stopping_handler(session); |
402 | - }); |
403 | - }); |
404 | - |
405 | + session_event_handler_register->add(session_observer.get()); |
406 | observer->initial_configuration(base_configuration_); |
407 | } |
408 | |
409 | +ms::MediatingDisplayChanger::~MediatingDisplayChanger() |
410 | +{ |
411 | + session_event_handler_register->remove(session_observer.get()); |
412 | +} |
413 | + |
414 | void ms::MediatingDisplayChanger::configure( |
415 | std::shared_ptr<mf::Session> const& session, |
416 | std::shared_ptr<mg::DisplayConfiguration> const& conf) |
417 | |
418 | === modified file 'src/server/scene/mediating_display_changer.h' |
419 | --- src/server/scene/mediating_display_changer.h 2017-07-28 17:00:43 +0000 |
420 | +++ src/server/scene/mediating_display_changer.h 2017-08-18 15:06:41 +0000 |
421 | @@ -65,7 +65,9 @@ |
422 | std::shared_ptr<graphics::DisplayConfigurationObserver> const& observer, |
423 | std::shared_ptr<time::AlarmFactory> const& alarm_factory); |
424 | |
425 | - /* From mir::frontend::DisplayChanger */ |
426 | + ~MediatingDisplayChanger(); |
427 | + |
428 | + /* From mir::frontend::DisplayChanger */ |
429 | std::shared_ptr<graphics::DisplayConfiguration> base_configuration() override; |
430 | void configure(std::shared_ptr<frontend::Session> const& session, |
431 | std::shared_ptr<graphics::DisplayConfiguration> const& conf) override; |
432 | @@ -118,6 +120,8 @@ |
433 | std::shared_ptr<time::AlarmFactory> const alarm_factory; |
434 | std::unique_ptr<time::Alarm> preview_configuration_timeout; |
435 | std::weak_ptr<frontend::Session> currently_previewing_session; |
436 | + struct SessionObserver; |
437 | + std::unique_ptr<SessionObserver> const session_observer; |
438 | }; |
439 | |
440 | } |
441 | |
442 | === modified file 'src/server/scene/session_manager.cpp' |
443 | --- src/server/scene/session_manager.cpp 2017-07-28 17:00:43 +0000 |
444 | +++ src/server/scene/session_manager.cpp 2017-08-18 15:06:41 +0000 |
445 | @@ -25,7 +25,7 @@ |
446 | #include "mir/scene/prompt_session.h" |
447 | #include "mir/scene/application_not_responding_detector.h" |
448 | #include "mir/shell/surface_stack.h" |
449 | -#include "session_event_sink.h" |
450 | +#include "mir/scene/session_event_sink.h" |
451 | #include "mir/frontend/event_sink.h" |
452 | #include "mir/graphics/display.h" |
453 | #include "mir/graphics/display_configuration.h" |
454 | |
455 | === modified file 'tests/include/mir/test/doubles/null_session_event_sink.h' |
456 | --- tests/include/mir/test/doubles/null_session_event_sink.h 2017-07-28 17:00:43 +0000 |
457 | +++ tests/include/mir/test/doubles/null_session_event_sink.h 2017-08-18 15:06:41 +0000 |
458 | @@ -19,7 +19,7 @@ |
459 | #ifndef MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ |
460 | #define MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ |
461 | |
462 | -#include "src/server/scene/session_event_sink.h" |
463 | +#include "src/include/server/mir/scene/session_event_sink.h" |
464 | |
465 | namespace mir |
466 | { |
467 | |
468 | === modified file 'tests/unit-tests/scene/test_abstract_shell.cpp' |
469 | --- tests/unit-tests/scene/test_abstract_shell.cpp 2017-07-28 17:00:43 +0000 |
470 | +++ tests/unit-tests/scene/test_abstract_shell.cpp 2017-08-18 15:06:41 +0000 |
471 | @@ -26,7 +26,7 @@ |
472 | |
473 | #include "src/server/report/null/shell_report.h" |
474 | #include "src/server/scene/default_session_container.h" |
475 | -#include "src/server/scene/session_event_sink.h" |
476 | +#include "src/include/server/mir/scene/session_event_sink.h" |
477 | #include "src/server/scene/session_manager.h" |
478 | |
479 | #include "mir/test/doubles/mock_window_manager.h" |
480 | |
481 | === modified file 'tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp' |
482 | --- tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp 2017-07-28 17:00:43 +0000 |
483 | +++ tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp 2017-08-18 15:06:41 +0000 |
484 | @@ -21,79 +21,74 @@ |
485 | #include "mir/test/fake_shared.h" |
486 | |
487 | #include <gtest/gtest.h> |
488 | +#include <gmock/gmock.h> |
489 | |
490 | namespace ms = mir::scene; |
491 | namespace mtd = mir::test::doubles; |
492 | namespace mt = mir::test; |
493 | +using namespace testing; |
494 | + |
495 | +namespace |
496 | +{ |
497 | +struct MockEventSink : ms::SessionEventSink |
498 | +{ |
499 | + MOCK_METHOD1(handle_focus_change, void (std::shared_ptr<ms::Session> const& session)); |
500 | + MOCK_METHOD1(handle_session_stopping, void (std::shared_ptr<ms::Session> const& session)); |
501 | + MOCK_METHOD0(handle_no_focus, void ()); |
502 | +}; |
503 | +} |
504 | |
505 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change) |
506 | { |
507 | mtd::StubSession session1; |
508 | - std::vector<ms::Session*> handler_called(3, nullptr); |
509 | + MockEventSink handler_called[3]; |
510 | |
511 | ms::BroadcastingSessionEventSink events; |
512 | |
513 | + std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)}; |
514 | + |
515 | for (auto& h : handler_called) |
516 | { |
517 | - events.register_focus_change_handler( |
518 | - [&h](std::shared_ptr<ms::Session> const& session) |
519 | - { |
520 | - h = session.get(); |
521 | - }); |
522 | - } |
523 | - |
524 | - events.handle_focus_change(mt::fake_shared(session1)); |
525 | - |
526 | - for (unsigned int i = 0; i < handler_called.size(); i++) |
527 | - { |
528 | - EXPECT_EQ(&session1, handler_called[i]) << " i = " << i; |
529 | - } |
530 | + events.add(&h); |
531 | + |
532 | + EXPECT_CALL(h, handle_focus_change(session1ptr)).Times(1); |
533 | + } |
534 | + |
535 | + events.handle_focus_change(session1ptr); |
536 | } |
537 | |
538 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus) |
539 | { |
540 | mtd::StubSession session1; |
541 | - std::vector<int> handler_called(3, 0); |
542 | + MockEventSink handler_called[3]; |
543 | |
544 | ms::BroadcastingSessionEventSink events; |
545 | |
546 | for (auto& h : handler_called) |
547 | { |
548 | - events.register_no_focus_handler( |
549 | - [&h] |
550 | - { |
551 | - h = 1; |
552 | - }); |
553 | + events.add(&h); |
554 | + |
555 | + EXPECT_CALL(h, handle_no_focus()).Times(1); |
556 | } |
557 | |
558 | events.handle_no_focus(); |
559 | - |
560 | - for (unsigned int i = 0; i < handler_called.size(); i++) |
561 | - { |
562 | - EXPECT_EQ(1, handler_called[i]) << " i = " << i; |
563 | - } |
564 | } |
565 | |
566 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping) |
567 | { |
568 | mtd::StubSession session1; |
569 | - std::vector<ms::Session*> handler_called(3, nullptr); |
570 | + MockEventSink handler_called[3]; |
571 | |
572 | ms::BroadcastingSessionEventSink events; |
573 | |
574 | + std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)}; |
575 | + |
576 | for (auto& h : handler_called) |
577 | { |
578 | - events.register_session_stopping_handler( |
579 | - [&h](std::shared_ptr<ms::Session> const& session) |
580 | - { |
581 | - h = session.get(); |
582 | - }); |
583 | - } |
584 | - |
585 | - events.handle_session_stopping(mt::fake_shared(session1)); |
586 | - |
587 | - for (unsigned int i = 0; i < handler_called.size(); i++) |
588 | - { |
589 | - EXPECT_EQ(&session1, handler_called[i]) << " i = " << i; |
590 | - } |
591 | + events.add(&h); |
592 | + |
593 | + EXPECT_CALL(h, handle_session_stopping(session1ptr)).Times(1); |
594 | + } |
595 | + |
596 | + events.handle_session_stopping(session1ptr); |
597 | } |
598 | |
599 | === modified file 'tests/unit-tests/scene/test_session_manager.cpp' |
600 | --- tests/unit-tests/scene/test_session_manager.cpp 2017-07-28 17:00:43 +0000 |
601 | +++ tests/unit-tests/scene/test_session_manager.cpp 2017-08-18 15:06:41 +0000 |
602 | @@ -24,7 +24,7 @@ |
603 | |
604 | #include "src/server/scene/basic_surface.h" |
605 | #include "src/server/scene/default_session_container.h" |
606 | -#include "src/server/scene/session_event_sink.h" |
607 | +#include "src/include/server/mir/scene/session_event_sink.h" |
608 | #include "src/server/report/null_report_factory.h" |
609 | |
610 | #include "mir/test/doubles/mock_surface_stack.h" |
PASSED: Continuous integration, rev:4234 /mir-jenkins. ubuntu. com/job/ mir-ci/ 3562/ /mir-jenkins. ubuntu. com/job/ build-mir/ 4881 /mir-jenkins. ubuntu. com/job/ build-0- fetch/5096 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= artful/ 5085 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial/ 5085 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= zesty/5085 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 4918/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= zesty/4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= zesty/4918/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 4918/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 4918/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= zesty/4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= zesty/4918/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 4918/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/4918/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 4918 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 4918/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 3562/rebuild
https:/