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 | 34 | * - copy-assignable | 34 | * - copy-assignable |
6 | 35 | * - add(): | 35 | * - add(): |
7 | 36 | * - copy-assignable | 36 | * - copy-assignable |
9 | 37 | * - operator bool: returns whether this is a valid element | 37 | * - conversion to bool: indicates whether this is a valid element |
10 | 38 | * - remove(), remove_all(): | 38 | * - remove(), remove_all(): |
11 | 39 | * - copy-assignable | 39 | * - copy-assignable |
12 | 40 | * - Element{}: default construction should create an invalid element | 40 | * - Element{}: default construction should create an invalid element |
13 | @@ -42,7 +42,7 @@ | |||
14 | 42 | * - bool operator!=: inequality of elements | 42 | * - bool operator!=: inequality of elements |
15 | 43 | * - clear(): | 43 | * - clear(): |
16 | 44 | * - copy-assignable | 44 | * - copy-assignable |
18 | 45 | * - Element{}: default construction should create an invalid element | 45 | * - Element{}: value initialization should create an invalid element |
19 | 46 | */ | 46 | */ |
20 | 47 | 47 | ||
21 | 48 | template<class Element> | 48 | template<class Element> |
22 | @@ -60,7 +60,7 @@ | |||
23 | 60 | { | 60 | { |
24 | 61 | ListItem() {} | 61 | ListItem() {} |
25 | 62 | RecursiveReadWriteMutex mutex; | 62 | RecursiveReadWriteMutex mutex; |
27 | 63 | Element element; | 63 | Element element{}; |
28 | 64 | std::atomic<ListItem*> next{nullptr}; | 64 | std::atomic<ListItem*> next{nullptr}; |
29 | 65 | 65 | ||
30 | 66 | ~ListItem() { delete next.load(); } | 66 | ~ListItem() { delete next.load(); } |
31 | 67 | 67 | ||
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 | 19 | #ifndef MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ | 19 | #ifndef MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ |
37 | 20 | #define MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ | 20 | #define MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_ |
38 | 21 | 21 | ||
39 | 22 | #include <functional> | ||
40 | 23 | #include <memory> | 22 | #include <memory> |
41 | 24 | 23 | ||
42 | 25 | namespace mir | 24 | namespace mir |
43 | 26 | { | 25 | { |
44 | 27 | namespace scene | 26 | namespace scene |
45 | 28 | { | 27 | { |
47 | 29 | class Session; | 28 | class SessionEventSink; |
48 | 30 | 29 | ||
49 | 31 | class SessionEventHandlerRegister | 30 | class SessionEventHandlerRegister |
50 | 32 | { | 31 | { |
51 | 33 | public: | 32 | public: |
52 | 34 | virtual ~SessionEventHandlerRegister() = default; | 33 | virtual ~SessionEventHandlerRegister() = default; |
53 | 35 | 34 | ||
60 | 36 | virtual void register_focus_change_handler( | 35 | virtual void add(SessionEventSink* handler) = 0; |
61 | 37 | std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0; | 36 | virtual void remove(SessionEventSink* handler) = 0; |
56 | 38 | virtual void register_no_focus_handler( | ||
57 | 39 | std::function<void()> const& handler) = 0; | ||
58 | 40 | virtual void register_session_stopping_handler( | ||
59 | 41 | std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0; | ||
62 | 42 | 37 | ||
63 | 43 | protected: | 38 | protected: |
64 | 44 | SessionEventHandlerRegister() = default; | 39 | SessionEventHandlerRegister() = default; |
65 | 45 | 40 | ||
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 | 19 | #include "config_changer.h" | 19 | #include "config_changer.h" |
72 | 20 | 20 | ||
73 | 21 | #include "mir/scene/session_event_handler_register.h" | 21 | #include "mir/scene/session_event_handler_register.h" |
74 | 22 | #include "mir/scene/session_event_sink.h" | ||
75 | 22 | #include "mir/scene/session_container.h" | 23 | #include "mir/scene/session_container.h" |
76 | 23 | #include "mir/scene/session.h" | 24 | #include "mir/scene/session.h" |
77 | 24 | #include "mir/input/device.h" | 25 | #include "mir/input/device.h" |
78 | @@ -137,9 +138,30 @@ | |||
79 | 137 | std::vector<std::shared_ptr<mi::Device>> added; | 138 | std::vector<std::shared_ptr<mi::Device>> added; |
80 | 138 | std::vector<MirInputDeviceId> removed; | 139 | std::vector<MirInputDeviceId> removed; |
81 | 139 | }; | 140 | }; |
82 | 140 | |||
83 | 141 | } | 141 | } |
84 | 142 | 142 | ||
85 | 143 | struct mi::ConfigChanger::SessionObserver : ms::SessionEventSink | ||
86 | 144 | { | ||
87 | 145 | SessionObserver(mi::ConfigChanger& self) : self{self} {} | ||
88 | 146 | |||
89 | 147 | void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override | ||
90 | 148 | { | ||
91 | 149 | self.focus_change_handler(session); | ||
92 | 150 | } | ||
93 | 151 | |||
94 | 152 | void handle_no_focus() override | ||
95 | 153 | { | ||
96 | 154 | self.no_focus_handler(); | ||
97 | 155 | } | ||
98 | 156 | |||
99 | 157 | void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override | ||
100 | 158 | { | ||
101 | 159 | self.session_stopping_handler(session); | ||
102 | 160 | } | ||
103 | 161 | |||
104 | 162 | mi::ConfigChanger& self; | ||
105 | 163 | }; | ||
106 | 164 | |||
107 | 143 | mi::ConfigChanger::ConfigChanger( | 165 | mi::ConfigChanger::ConfigChanger( |
108 | 144 | std::shared_ptr<InputManager> const& manager, | 166 | std::shared_ptr<InputManager> const& manager, |
109 | 145 | std::shared_ptr<InputDeviceHub> const& devices, | 167 | std::shared_ptr<InputDeviceHub> const& devices, |
110 | @@ -152,31 +174,16 @@ | |||
111 | 152 | session_event_handler_register{session_event_handler_register}, | 174 | session_event_handler_register{session_event_handler_register}, |
112 | 153 | devices_wrapper_DO_NOT_USE{devices_wrapper}, | 175 | devices_wrapper_DO_NOT_USE{devices_wrapper}, |
113 | 154 | device_observer(std::make_shared<DeviceChangeTracker>(*this)), | 176 | device_observer(std::make_shared<DeviceChangeTracker>(*this)), |
114 | 177 | session_observer{std::make_unique<SessionObserver>(*this)}, | ||
115 | 155 | base_configuration_applied(true) | 178 | base_configuration_applied(true) |
116 | 156 | { | 179 | { |
117 | 157 | devices->add_observer(device_observer); | 180 | devices->add_observer(device_observer); |
136 | 158 | 181 | session_event_handler_register->add(session_observer.get()); | |
119 | 159 | session_event_handler_register->register_focus_change_handler( | ||
120 | 160 | [this](std::shared_ptr<ms::Session> const& session) | ||
121 | 161 | { | ||
122 | 162 | focus_change_handler(session); | ||
123 | 163 | }); | ||
124 | 164 | |||
125 | 165 | session_event_handler_register->register_no_focus_handler( | ||
126 | 166 | [this] | ||
127 | 167 | { | ||
128 | 168 | no_focus_handler(); | ||
129 | 169 | }); | ||
130 | 170 | |||
131 | 171 | session_event_handler_register->register_session_stopping_handler( | ||
132 | 172 | [this](std::shared_ptr<ms::Session> const& session) | ||
133 | 173 | { | ||
134 | 174 | session_stopping_handler(session); | ||
135 | 175 | }); | ||
137 | 176 | } | 182 | } |
138 | 177 | 183 | ||
139 | 178 | mi::ConfigChanger::~ConfigChanger() | 184 | mi::ConfigChanger::~ConfigChanger() |
140 | 179 | { | 185 | { |
141 | 186 | session_event_handler_register->remove(session_observer.get()); | ||
142 | 180 | devices->remove_observer(device_observer); | 187 | devices->remove_observer(device_observer); |
143 | 181 | } | 188 | } |
144 | 182 | 189 | ||
145 | 183 | 190 | ||
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 | 70 | // needs to be owned (but not used) in Mir, where better? | 70 | // needs to be owned (but not used) in Mir, where better? |
151 | 71 | std::shared_ptr<InputDeviceHub> const devices_wrapper_DO_NOT_USE; | 71 | std::shared_ptr<InputDeviceHub> const devices_wrapper_DO_NOT_USE; |
152 | 72 | std::shared_ptr<InputDeviceObserver> const device_observer; | 72 | std::shared_ptr<InputDeviceObserver> const device_observer; |
153 | 73 | struct SessionObserver; | ||
154 | 74 | std::unique_ptr<SessionObserver> const session_observer; | ||
155 | 73 | bool base_configuration_applied; | 75 | bool base_configuration_applied; |
156 | 74 | 76 | ||
157 | 75 | std::weak_ptr<frontend::Session> focused_session; | 77 | std::weak_ptr<frontend::Session> focused_session; |
158 | 76 | 78 | ||
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 | 20 | 20 | ||
164 | 21 | namespace ms = mir::scene; | 21 | namespace ms = mir::scene; |
165 | 22 | 22 | ||
166 | 23 | /* | ||
167 | 24 | * TODO: Use Boost.Signals2 for this when we default to Boost 1.54, see | ||
168 | 25 | * https://svn.boost.org/trac/boost/ticket/8102 . For now, just use a custom | ||
169 | 26 | * mechanism with coarse locking. When emitting events, we copy the handlers | ||
170 | 27 | * to a temporary vector to avoid calling handlers while locked, while still | ||
171 | 28 | * being thread-safe. | ||
172 | 29 | */ | ||
173 | 30 | |||
174 | 31 | void ms::BroadcastingSessionEventSink::handle_focus_change( | 23 | void ms::BroadcastingSessionEventSink::handle_focus_change( |
175 | 32 | std::shared_ptr<Session> const& session) | 24 | std::shared_ptr<Session> const& session) |
176 | 33 | { | 25 | { |
186 | 34 | std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers; | 26 | for_each([&](SessionEventSink* observer) |
187 | 35 | 27 | { observer->handle_focus_change(session); }); | |
179 | 36 | { | ||
180 | 37 | std::lock_guard<std::mutex> lg{handler_mutex}; | ||
181 | 38 | handlers = focus_change_handlers; | ||
182 | 39 | } | ||
183 | 40 | |||
184 | 41 | for (auto& handler : handlers) | ||
185 | 42 | handler(session); | ||
188 | 43 | } | 28 | } |
189 | 44 | 29 | ||
190 | 45 | void ms::BroadcastingSessionEventSink::handle_no_focus() | 30 | void ms::BroadcastingSessionEventSink::handle_no_focus() |
191 | 46 | { | 31 | { |
201 | 47 | std::vector<std::function<void()>> handlers; | 32 | for_each([&](SessionEventSink* observer) |
202 | 48 | 33 | { observer->handle_no_focus(); }); | |
194 | 49 | { | ||
195 | 50 | std::lock_guard<std::mutex> lg{handler_mutex}; | ||
196 | 51 | handlers = no_focus_handlers; | ||
197 | 52 | } | ||
198 | 53 | |||
199 | 54 | for (auto& handler : handlers) | ||
200 | 55 | handler(); | ||
203 | 56 | } | 34 | } |
204 | 57 | 35 | ||
205 | 58 | void ms::BroadcastingSessionEventSink::handle_session_stopping( | 36 | void ms::BroadcastingSessionEventSink::handle_session_stopping( |
206 | 59 | std::shared_ptr<Session> const& session) | 37 | std::shared_ptr<Session> const& session) |
207 | 60 | { | 38 | { |
241 | 61 | std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers; | 39 | for_each([&](SessionEventSink* observer) |
242 | 62 | 40 | { observer->handle_session_stopping(session); }); | |
243 | 63 | { | 41 | } |
244 | 64 | std::lock_guard<std::mutex> lg{handler_mutex}; | 42 | |
245 | 65 | handlers = session_stopping_handlers; | 43 | void ms::BroadcastingSessionEventSink::add(SessionEventSink* handler) |
246 | 66 | } | 44 | { |
247 | 67 | 45 | ThreadSafeList<SessionEventSink*>::add(handler); | |
248 | 68 | for (auto& handler : handlers) | 46 | } |
249 | 69 | handler(session); | 47 | |
250 | 70 | } | 48 | void ms::BroadcastingSessionEventSink::remove(SessionEventSink* handler) |
251 | 71 | 49 | { | |
252 | 72 | void ms::BroadcastingSessionEventSink::register_focus_change_handler( | 50 | ThreadSafeList<SessionEventSink*>::remove(handler); |
220 | 73 | std::function<void(std::shared_ptr<Session> const& session)> const& handler) | ||
221 | 74 | { | ||
222 | 75 | std::lock_guard<std::mutex> lg{handler_mutex}; | ||
223 | 76 | |||
224 | 77 | focus_change_handlers.push_back(handler); | ||
225 | 78 | } | ||
226 | 79 | |||
227 | 80 | void ms::BroadcastingSessionEventSink::register_no_focus_handler( | ||
228 | 81 | std::function<void()> const& handler) | ||
229 | 82 | { | ||
230 | 83 | std::lock_guard<std::mutex> lg{handler_mutex}; | ||
231 | 84 | |||
232 | 85 | no_focus_handlers.push_back(handler); | ||
233 | 86 | } | ||
234 | 87 | |||
235 | 88 | void ms::BroadcastingSessionEventSink::register_session_stopping_handler( | ||
236 | 89 | std::function<void(std::shared_ptr<Session> const& session)> const& handler) | ||
237 | 90 | { | ||
238 | 91 | std::lock_guard<std::mutex> lg{handler_mutex}; | ||
239 | 92 | |||
240 | 93 | session_stopping_handlers.push_back(handler); | ||
253 | 94 | } | 51 | } |
254 | 95 | 52 | ||
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 | 19 | #ifndef MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ | 19 | #ifndef MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ |
260 | 20 | #define MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ | 20 | #define MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_ |
261 | 21 | 21 | ||
263 | 22 | #include "session_event_sink.h" | 22 | #include "mir/scene/session_event_sink.h" |
264 | 23 | #include "mir/scene/session_event_handler_register.h" | 23 | #include "mir/scene/session_event_handler_register.h" |
265 | 24 | 24 | ||
268 | 25 | #include <vector> | 25 | #include "mir/thread_safe_list.h" |
267 | 26 | #include <mutex> | ||
269 | 27 | 26 | ||
270 | 28 | namespace mir | 27 | namespace mir |
271 | 29 | { | 28 | { |
272 | 30 | namespace scene | 29 | namespace scene |
273 | 31 | { | 30 | { |
274 | 32 | class BroadcastingSessionEventSink : public SessionEventSink, | 31 | class BroadcastingSessionEventSink : public SessionEventSink, |
276 | 33 | public SessionEventHandlerRegister | 32 | public SessionEventHandlerRegister, |
277 | 33 | private ThreadSafeList<SessionEventSink*> | ||
278 | 34 | { | 34 | { |
279 | 35 | public: | 35 | public: |
296 | 36 | void handle_focus_change(std::shared_ptr<Session> const& session); | 36 | void handle_focus_change(std::shared_ptr<Session> const& session) override; |
297 | 37 | void handle_no_focus(); | 37 | void handle_no_focus() override; |
298 | 38 | void handle_session_stopping(std::shared_ptr<Session> const& session); | 38 | void handle_session_stopping(std::shared_ptr<Session> const& session) override; |
299 | 39 | 39 | ||
300 | 40 | void register_focus_change_handler( | 40 | void add(SessionEventSink* handler) override; |
301 | 41 | std::function<void(std::shared_ptr<Session> const& session)> const& handler); | 41 | void remove(SessionEventSink* handler) override; |
286 | 42 | void register_no_focus_handler( | ||
287 | 43 | std::function<void()> const& handler); | ||
288 | 44 | void register_session_stopping_handler( | ||
289 | 45 | std::function<void(std::shared_ptr<Session> const& session)> const& handler); | ||
290 | 46 | |||
291 | 47 | private: | ||
292 | 48 | std::mutex handler_mutex; | ||
293 | 49 | std::vector<std::function<void(std::shared_ptr<Session> const&)>> focus_change_handlers; | ||
294 | 50 | std::vector<std::function<void()>> no_focus_handlers; | ||
295 | 51 | std::vector<std::function<void(std::shared_ptr<Session> const&)>> session_stopping_handlers; | ||
302 | 52 | }; | 42 | }; |
303 | 53 | 43 | ||
304 | 54 | } | 44 | } |
305 | 55 | 45 | ||
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 | 23 | #include "mir/scene/session_container.h" | 23 | #include "mir/scene/session_container.h" |
311 | 24 | #include "mir/scene/session.h" | 24 | #include "mir/scene/session.h" |
312 | 25 | #include "mir/scene/session_event_handler_register.h" | 25 | #include "mir/scene/session_event_handler_register.h" |
313 | 26 | #include "mir/scene/session_event_sink.h" | ||
314 | 26 | #include "mir/graphics/display.h" | 27 | #include "mir/graphics/display.h" |
315 | 27 | #include "mir/compositor/compositor.h" | 28 | #include "mir/compositor/compositor.h" |
316 | 28 | #include "mir/geometry/rectangles.h" | 29 | #include "mir/geometry/rectangles.h" |
317 | @@ -124,6 +125,45 @@ | |||
318 | 124 | }; | 125 | }; |
319 | 125 | } | 126 | } |
320 | 126 | 127 | ||
321 | 128 | struct ms::MediatingDisplayChanger::SessionObserver : ms::SessionEventSink | ||
322 | 129 | { | ||
323 | 130 | SessionObserver(ms::MediatingDisplayChanger* self) : self{self} {} | ||
324 | 131 | |||
325 | 132 | void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override | ||
326 | 133 | { | ||
327 | 134 | auto const weak_session = std::weak_ptr<ms::Session>(session); | ||
328 | 135 | self->server_action_queue->enqueue( | ||
329 | 136 | self, | ||
330 | 137 | [self=self,weak_session] | ||
331 | 138 | { | ||
332 | 139 | if (auto const session = weak_session.lock()) | ||
333 | 140 | self->focus_change_handler(session); | ||
334 | 141 | }); | ||
335 | 142 | } | ||
336 | 143 | |||
337 | 144 | void handle_no_focus() override | ||
338 | 145 | { | ||
339 | 146 | self->server_action_queue->enqueue( | ||
340 | 147 | self, | ||
341 | 148 | [self=self] { self->no_focus_handler(); }); | ||
342 | 149 | } | ||
343 | 150 | |||
344 | 151 | void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override | ||
345 | 152 | { | ||
346 | 153 | auto const weak_session = std::weak_ptr<ms::Session>(session); | ||
347 | 154 | self->server_action_queue->enqueue( | ||
348 | 155 | self, | ||
349 | 156 | [self=self,weak_session] | ||
350 | 157 | { | ||
351 | 158 | if (auto const session = weak_session.lock()) | ||
352 | 159 | self->session_stopping_handler(session); | ||
353 | 160 | }); | ||
354 | 161 | } | ||
355 | 162 | |||
356 | 163 | ms::MediatingDisplayChanger* const self; | ||
357 | 164 | }; | ||
358 | 165 | |||
359 | 166 | |||
360 | 127 | ms::MediatingDisplayChanger::MediatingDisplayChanger( | 167 | ms::MediatingDisplayChanger::MediatingDisplayChanger( |
361 | 128 | std::shared_ptr<mg::Display> const& display, | 168 | std::shared_ptr<mg::Display> const& display, |
362 | 129 | std::shared_ptr<mc::Compositor> const& compositor, | 169 | std::shared_ptr<mc::Compositor> const& compositor, |
363 | @@ -142,45 +182,18 @@ | |||
364 | 142 | observer{observer}, | 182 | observer{observer}, |
365 | 143 | base_configuration_{display->configuration()}, | 183 | base_configuration_{display->configuration()}, |
366 | 144 | base_configuration_applied{true}, | 184 | base_configuration_applied{true}, |
368 | 145 | alarm_factory{alarm_factory} | 185 | alarm_factory{alarm_factory}, |
369 | 186 | session_observer{std::make_unique<SessionObserver>(this)} | ||
370 | 146 | { | 187 | { |
405 | 147 | session_event_handler_register->register_focus_change_handler( | 188 | session_event_handler_register->add(session_observer.get()); |
372 | 148 | [this](std::shared_ptr<ms::Session> const& session) | ||
373 | 149 | { | ||
374 | 150 | auto const weak_session = std::weak_ptr<ms::Session>(session); | ||
375 | 151 | this->server_action_queue->enqueue( | ||
376 | 152 | this, | ||
377 | 153 | [this,weak_session] | ||
378 | 154 | { | ||
379 | 155 | if (auto const session = weak_session.lock()) | ||
380 | 156 | focus_change_handler(session); | ||
381 | 157 | }); | ||
382 | 158 | }); | ||
383 | 159 | |||
384 | 160 | session_event_handler_register->register_no_focus_handler( | ||
385 | 161 | [this] | ||
386 | 162 | { | ||
387 | 163 | this->server_action_queue->enqueue( | ||
388 | 164 | this, | ||
389 | 165 | [this] { no_focus_handler(); }); | ||
390 | 166 | }); | ||
391 | 167 | |||
392 | 168 | session_event_handler_register->register_session_stopping_handler( | ||
393 | 169 | [this](std::shared_ptr<ms::Session> const& session) | ||
394 | 170 | { | ||
395 | 171 | auto const weak_session = std::weak_ptr<ms::Session>(session); | ||
396 | 172 | this->server_action_queue->enqueue( | ||
397 | 173 | this, | ||
398 | 174 | [this,weak_session] | ||
399 | 175 | { | ||
400 | 176 | if (auto const session = weak_session.lock()) | ||
401 | 177 | session_stopping_handler(session); | ||
402 | 178 | }); | ||
403 | 179 | }); | ||
404 | 180 | |||
406 | 181 | observer->initial_configuration(base_configuration_); | 189 | observer->initial_configuration(base_configuration_); |
407 | 182 | } | 190 | } |
408 | 183 | 191 | ||
409 | 192 | ms::MediatingDisplayChanger::~MediatingDisplayChanger() | ||
410 | 193 | { | ||
411 | 194 | session_event_handler_register->remove(session_observer.get()); | ||
412 | 195 | } | ||
413 | 196 | |||
414 | 184 | void ms::MediatingDisplayChanger::configure( | 197 | void ms::MediatingDisplayChanger::configure( |
415 | 185 | std::shared_ptr<mf::Session> const& session, | 198 | std::shared_ptr<mf::Session> const& session, |
416 | 186 | std::shared_ptr<mg::DisplayConfiguration> const& conf) | 199 | std::shared_ptr<mg::DisplayConfiguration> const& conf) |
417 | 187 | 200 | ||
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 | 65 | std::shared_ptr<graphics::DisplayConfigurationObserver> const& observer, | 65 | std::shared_ptr<graphics::DisplayConfigurationObserver> const& observer, |
423 | 66 | std::shared_ptr<time::AlarmFactory> const& alarm_factory); | 66 | std::shared_ptr<time::AlarmFactory> const& alarm_factory); |
424 | 67 | 67 | ||
426 | 68 | /* From mir::frontend::DisplayChanger */ | 68 | ~MediatingDisplayChanger(); |
427 | 69 | |||
428 | 70 | /* From mir::frontend::DisplayChanger */ | ||
429 | 69 | std::shared_ptr<graphics::DisplayConfiguration> base_configuration() override; | 71 | std::shared_ptr<graphics::DisplayConfiguration> base_configuration() override; |
430 | 70 | void configure(std::shared_ptr<frontend::Session> const& session, | 72 | void configure(std::shared_ptr<frontend::Session> const& session, |
431 | 71 | std::shared_ptr<graphics::DisplayConfiguration> const& conf) override; | 73 | std::shared_ptr<graphics::DisplayConfiguration> const& conf) override; |
432 | @@ -118,6 +120,8 @@ | |||
433 | 118 | std::shared_ptr<time::AlarmFactory> const alarm_factory; | 120 | std::shared_ptr<time::AlarmFactory> const alarm_factory; |
434 | 119 | std::unique_ptr<time::Alarm> preview_configuration_timeout; | 121 | std::unique_ptr<time::Alarm> preview_configuration_timeout; |
435 | 120 | std::weak_ptr<frontend::Session> currently_previewing_session; | 122 | std::weak_ptr<frontend::Session> currently_previewing_session; |
436 | 123 | struct SessionObserver; | ||
437 | 124 | std::unique_ptr<SessionObserver> const session_observer; | ||
438 | 121 | }; | 125 | }; |
439 | 122 | 126 | ||
440 | 123 | } | 127 | } |
441 | 124 | 128 | ||
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 | 25 | #include "mir/scene/prompt_session.h" | 25 | #include "mir/scene/prompt_session.h" |
447 | 26 | #include "mir/scene/application_not_responding_detector.h" | 26 | #include "mir/scene/application_not_responding_detector.h" |
448 | 27 | #include "mir/shell/surface_stack.h" | 27 | #include "mir/shell/surface_stack.h" |
450 | 28 | #include "session_event_sink.h" | 28 | #include "mir/scene/session_event_sink.h" |
451 | 29 | #include "mir/frontend/event_sink.h" | 29 | #include "mir/frontend/event_sink.h" |
452 | 30 | #include "mir/graphics/display.h" | 30 | #include "mir/graphics/display.h" |
453 | 31 | #include "mir/graphics/display_configuration.h" | 31 | #include "mir/graphics/display_configuration.h" |
454 | 32 | 32 | ||
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 | 19 | #ifndef MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ | 19 | #ifndef MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ |
460 | 20 | #define MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ | 20 | #define MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_ |
461 | 21 | 21 | ||
463 | 22 | #include "src/server/scene/session_event_sink.h" | 22 | #include "src/include/server/mir/scene/session_event_sink.h" |
464 | 23 | 23 | ||
465 | 24 | namespace mir | 24 | namespace mir |
466 | 25 | { | 25 | { |
467 | 26 | 26 | ||
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 | 26 | 26 | ||
473 | 27 | #include "src/server/report/null/shell_report.h" | 27 | #include "src/server/report/null/shell_report.h" |
474 | 28 | #include "src/server/scene/default_session_container.h" | 28 | #include "src/server/scene/default_session_container.h" |
476 | 29 | #include "src/server/scene/session_event_sink.h" | 29 | #include "src/include/server/mir/scene/session_event_sink.h" |
477 | 30 | #include "src/server/scene/session_manager.h" | 30 | #include "src/server/scene/session_manager.h" |
478 | 31 | 31 | ||
479 | 32 | #include "mir/test/doubles/mock_window_manager.h" | 32 | #include "mir/test/doubles/mock_window_manager.h" |
480 | 33 | 33 | ||
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 | 21 | #include "mir/test/fake_shared.h" | 21 | #include "mir/test/fake_shared.h" |
486 | 22 | 22 | ||
487 | 23 | #include <gtest/gtest.h> | 23 | #include <gtest/gtest.h> |
488 | 24 | #include <gmock/gmock.h> | ||
489 | 24 | 25 | ||
490 | 25 | namespace ms = mir::scene; | 26 | namespace ms = mir::scene; |
491 | 26 | namespace mtd = mir::test::doubles; | 27 | namespace mtd = mir::test::doubles; |
492 | 27 | namespace mt = mir::test; | 28 | namespace mt = mir::test; |
493 | 29 | using namespace testing; | ||
494 | 30 | |||
495 | 31 | namespace | ||
496 | 32 | { | ||
497 | 33 | struct MockEventSink : ms::SessionEventSink | ||
498 | 34 | { | ||
499 | 35 | MOCK_METHOD1(handle_focus_change, void (std::shared_ptr<ms::Session> const& session)); | ||
500 | 36 | MOCK_METHOD1(handle_session_stopping, void (std::shared_ptr<ms::Session> const& session)); | ||
501 | 37 | MOCK_METHOD0(handle_no_focus, void ()); | ||
502 | 38 | }; | ||
503 | 39 | } | ||
504 | 28 | 40 | ||
505 | 29 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change) | 41 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change) |
506 | 30 | { | 42 | { |
507 | 31 | mtd::StubSession session1; | 43 | mtd::StubSession session1; |
509 | 32 | std::vector<ms::Session*> handler_called(3, nullptr); | 44 | MockEventSink handler_called[3]; |
510 | 33 | 45 | ||
511 | 34 | ms::BroadcastingSessionEventSink events; | 46 | ms::BroadcastingSessionEventSink events; |
512 | 35 | 47 | ||
513 | 48 | std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)}; | ||
514 | 49 | |||
515 | 36 | for (auto& h : handler_called) | 50 | for (auto& h : handler_called) |
516 | 37 | { | 51 | { |
530 | 38 | events.register_focus_change_handler( | 52 | events.add(&h); |
531 | 39 | [&h](std::shared_ptr<ms::Session> const& session) | 53 | |
532 | 40 | { | 54 | EXPECT_CALL(h, handle_focus_change(session1ptr)).Times(1); |
533 | 41 | h = session.get(); | 55 | } |
534 | 42 | }); | 56 | |
535 | 43 | } | 57 | events.handle_focus_change(session1ptr); |
523 | 44 | |||
524 | 45 | events.handle_focus_change(mt::fake_shared(session1)); | ||
525 | 46 | |||
526 | 47 | for (unsigned int i = 0; i < handler_called.size(); i++) | ||
527 | 48 | { | ||
528 | 49 | EXPECT_EQ(&session1, handler_called[i]) << " i = " << i; | ||
529 | 50 | } | ||
536 | 51 | } | 58 | } |
537 | 52 | 59 | ||
538 | 53 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus) | 60 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus) |
539 | 54 | { | 61 | { |
540 | 55 | mtd::StubSession session1; | 62 | mtd::StubSession session1; |
542 | 56 | std::vector<int> handler_called(3, 0); | 63 | MockEventSink handler_called[3]; |
543 | 57 | 64 | ||
544 | 58 | ms::BroadcastingSessionEventSink events; | 65 | ms::BroadcastingSessionEventSink events; |
545 | 59 | 66 | ||
546 | 60 | for (auto& h : handler_called) | 67 | for (auto& h : handler_called) |
547 | 61 | { | 68 | { |
553 | 62 | events.register_no_focus_handler( | 69 | events.add(&h); |
554 | 63 | [&h] | 70 | |
555 | 64 | { | 71 | EXPECT_CALL(h, handle_no_focus()).Times(1); |
551 | 65 | h = 1; | ||
552 | 66 | }); | ||
556 | 67 | } | 72 | } |
557 | 68 | 73 | ||
558 | 69 | events.handle_no_focus(); | 74 | events.handle_no_focus(); |
559 | 70 | |||
560 | 71 | for (unsigned int i = 0; i < handler_called.size(); i++) | ||
561 | 72 | { | ||
562 | 73 | EXPECT_EQ(1, handler_called[i]) << " i = " << i; | ||
563 | 74 | } | ||
564 | 75 | } | 75 | } |
565 | 76 | 76 | ||
566 | 77 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping) | 77 | TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping) |
567 | 78 | { | 78 | { |
568 | 79 | mtd::StubSession session1; | 79 | mtd::StubSession session1; |
570 | 80 | std::vector<ms::Session*> handler_called(3, nullptr); | 80 | MockEventSink handler_called[3]; |
571 | 81 | 81 | ||
572 | 82 | ms::BroadcastingSessionEventSink events; | 82 | ms::BroadcastingSessionEventSink events; |
573 | 83 | 83 | ||
574 | 84 | std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)}; | ||
575 | 85 | |||
576 | 84 | for (auto& h : handler_called) | 86 | for (auto& h : handler_called) |
577 | 85 | { | 87 | { |
591 | 86 | events.register_session_stopping_handler( | 88 | events.add(&h); |
592 | 87 | [&h](std::shared_ptr<ms::Session> const& session) | 89 | |
593 | 88 | { | 90 | EXPECT_CALL(h, handle_session_stopping(session1ptr)).Times(1); |
594 | 89 | h = session.get(); | 91 | } |
595 | 90 | }); | 92 | |
596 | 91 | } | 93 | events.handle_session_stopping(session1ptr); |
584 | 92 | |||
585 | 93 | events.handle_session_stopping(mt::fake_shared(session1)); | ||
586 | 94 | |||
587 | 95 | for (unsigned int i = 0; i < handler_called.size(); i++) | ||
588 | 96 | { | ||
589 | 97 | EXPECT_EQ(&session1, handler_called[i]) << " i = " << i; | ||
590 | 98 | } | ||
597 | 99 | } | 94 | } |
598 | 100 | 95 | ||
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 | 24 | 24 | ||
604 | 25 | #include "src/server/scene/basic_surface.h" | 25 | #include "src/server/scene/basic_surface.h" |
605 | 26 | #include "src/server/scene/default_session_container.h" | 26 | #include "src/server/scene/default_session_container.h" |
607 | 27 | #include "src/server/scene/session_event_sink.h" | 27 | #include "src/include/server/mir/scene/session_event_sink.h" |
608 | 28 | #include "src/server/report/null_report_factory.h" | 28 | #include "src/server/report/null_report_factory.h" |
609 | 29 | 29 | ||
610 | 30 | #include "mir/test/doubles/mock_surface_stack.h" | 30 | #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:/