Mir

Merge lp:~alan-griffiths/mir/rework-BroadcastingSessionEventSink-for-greyback into lp:mir

Proposed by Alan Griffiths
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
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 BroadcastingSessionEventSink using a similar "observer" idiom to that we use elsewhere.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4234
https://mir-jenkins.ubuntu.com/job/mir-ci/3562/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4881
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5096
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5085
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5085
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5085
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4918/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4918
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4918/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/3562/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

So, I'd quite like to gradually migrate all our observer-pattern code to use mir::ObserverRegistrar<>.

Both for consistency's sake, but also because being able to associate the Observer with an Executor makes MediatingDisplayChanger's callbacks somewhat nicer.

review: Needs Information
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Chris Halse Rogers (raof) wrote :

Yeah, let's just land this.

I can migrate stuff to ObserverRegistrar later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/include/common/mir/thread_safe_list.h'
--- src/include/common/mir/thread_safe_list.h 2017-07-28 17:00:43 +0000
+++ src/include/common/mir/thread_safe_list.h 2017-08-18 15:06:41 +0000
@@ -34,7 +34,7 @@
34 * - copy-assignable34 * - copy-assignable
35 * - add():35 * - add():
36 * - copy-assignable36 * - copy-assignable
37 * - operator bool: returns whether this is a valid element37 * - conversion to bool: indicates whether this is a valid element
38 * - remove(), remove_all():38 * - remove(), remove_all():
39 * - copy-assignable39 * - copy-assignable
40 * - Element{}: default construction should create an invalid element40 * - Element{}: default construction should create an invalid element
@@ -42,7 +42,7 @@
42 * - bool operator!=: inequality of elements42 * - bool operator!=: inequality of elements
43 * - clear():43 * - clear():
44 * - copy-assignable44 * - copy-assignable
45 * - Element{}: default construction should create an invalid element45 * - Element{}: value initialization should create an invalid element
46 */46 */
4747
48template<class Element>48template<class Element>
@@ -60,7 +60,7 @@
60 {60 {
61 ListItem() {}61 ListItem() {}
62 RecursiveReadWriteMutex mutex;62 RecursiveReadWriteMutex mutex;
63 Element element;63 Element element{};
64 std::atomic<ListItem*> next{nullptr};64 std::atomic<ListItem*> next{nullptr};
6565
66 ~ListItem() { delete next.load(); }66 ~ListItem() { delete next.load(); }
6767
=== modified file 'src/include/server/mir/scene/session_event_handler_register.h'
--- src/include/server/mir/scene/session_event_handler_register.h 2017-07-28 17:00:43 +0000
+++ src/include/server/mir/scene/session_event_handler_register.h 2017-08-18 15:06:41 +0000
@@ -19,26 +19,21 @@
19#ifndef MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_19#ifndef MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_
20#define MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_20#define MIR_SCENE_SESSION_EVENT_HANDLER_REGISTER_H_
2121
22#include <functional>
23#include <memory>22#include <memory>
2423
25namespace mir24namespace mir
26{25{
27namespace scene26namespace scene
28{27{
29class Session;28class SessionEventSink;
3029
31class SessionEventHandlerRegister30class SessionEventHandlerRegister
32{31{
33public:32public:
34 virtual ~SessionEventHandlerRegister() = default;33 virtual ~SessionEventHandlerRegister() = default;
3534
36 virtual void register_focus_change_handler(35 virtual void add(SessionEventSink* handler) = 0;
37 std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0;36 virtual void remove(SessionEventSink* handler) = 0;
38 virtual void register_no_focus_handler(
39 std::function<void()> const& handler) = 0;
40 virtual void register_session_stopping_handler(
41 std::function<void(std::shared_ptr<Session> const& session)> const& handler) = 0;
4237
43protected:38protected:
44 SessionEventHandlerRegister() = default;39 SessionEventHandlerRegister() = default;
4540
=== renamed file 'src/server/scene/session_event_sink.h' => 'src/include/server/mir/scene/session_event_sink.h'
=== modified file 'src/server/input/config_changer.cpp'
--- src/server/input/config_changer.cpp 2017-07-28 17:00:43 +0000
+++ src/server/input/config_changer.cpp 2017-08-18 15:06:41 +0000
@@ -19,6 +19,7 @@
19#include "config_changer.h"19#include "config_changer.h"
2020
21#include "mir/scene/session_event_handler_register.h"21#include "mir/scene/session_event_handler_register.h"
22#include "mir/scene/session_event_sink.h"
22#include "mir/scene/session_container.h"23#include "mir/scene/session_container.h"
23#include "mir/scene/session.h"24#include "mir/scene/session.h"
24#include "mir/input/device.h"25#include "mir/input/device.h"
@@ -137,9 +138,30 @@
137 std::vector<std::shared_ptr<mi::Device>> added;138 std::vector<std::shared_ptr<mi::Device>> added;
138 std::vector<MirInputDeviceId> removed;139 std::vector<MirInputDeviceId> removed;
139};140};
140
141}141}
142142
143struct mi::ConfigChanger::SessionObserver : ms::SessionEventSink
144{
145 SessionObserver(mi::ConfigChanger& self) : self{self} {}
146
147 void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override
148 {
149 self.focus_change_handler(session);
150 }
151
152 void handle_no_focus() override
153 {
154 self.no_focus_handler();
155 }
156
157 void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override
158 {
159 self.session_stopping_handler(session);
160 }
161
162 mi::ConfigChanger& self;
163};
164
143mi::ConfigChanger::ConfigChanger(165mi::ConfigChanger::ConfigChanger(
144 std::shared_ptr<InputManager> const& manager,166 std::shared_ptr<InputManager> const& manager,
145 std::shared_ptr<InputDeviceHub> const& devices,167 std::shared_ptr<InputDeviceHub> const& devices,
@@ -152,31 +174,16 @@
152 session_event_handler_register{session_event_handler_register},174 session_event_handler_register{session_event_handler_register},
153 devices_wrapper_DO_NOT_USE{devices_wrapper},175 devices_wrapper_DO_NOT_USE{devices_wrapper},
154 device_observer(std::make_shared<DeviceChangeTracker>(*this)),176 device_observer(std::make_shared<DeviceChangeTracker>(*this)),
177 session_observer{std::make_unique<SessionObserver>(*this)},
155 base_configuration_applied(true)178 base_configuration_applied(true)
156{179{
157 devices->add_observer(device_observer);180 devices->add_observer(device_observer);
158181 session_event_handler_register->add(session_observer.get());
159 session_event_handler_register->register_focus_change_handler(
160 [this](std::shared_ptr<ms::Session> const& session)
161 {
162 focus_change_handler(session);
163 });
164
165 session_event_handler_register->register_no_focus_handler(
166 [this]
167 {
168 no_focus_handler();
169 });
170
171 session_event_handler_register->register_session_stopping_handler(
172 [this](std::shared_ptr<ms::Session> const& session)
173 {
174 session_stopping_handler(session);
175 });
176}182}
177183
178mi::ConfigChanger::~ConfigChanger()184mi::ConfigChanger::~ConfigChanger()
179{185{
186 session_event_handler_register->remove(session_observer.get());
180 devices->remove_observer(device_observer);187 devices->remove_observer(device_observer);
181}188}
182189
183190
=== modified file 'src/server/input/config_changer.h'
--- src/server/input/config_changer.h 2017-07-28 17:00:43 +0000
+++ src/server/input/config_changer.h 2017-08-18 15:06:41 +0000
@@ -70,6 +70,8 @@
70 // needs to be owned (but not used) in Mir, where better?70 // needs to be owned (but not used) in Mir, where better?
71 std::shared_ptr<InputDeviceHub> const devices_wrapper_DO_NOT_USE;71 std::shared_ptr<InputDeviceHub> const devices_wrapper_DO_NOT_USE;
72 std::shared_ptr<InputDeviceObserver> const device_observer;72 std::shared_ptr<InputDeviceObserver> const device_observer;
73 struct SessionObserver;
74 std::unique_ptr<SessionObserver> const session_observer;
73 bool base_configuration_applied;75 bool base_configuration_applied;
7476
75 std::weak_ptr<frontend::Session> focused_session;77 std::weak_ptr<frontend::Session> focused_session;
7678
=== modified file 'src/server/scene/broadcasting_session_event_sink.cpp'
--- src/server/scene/broadcasting_session_event_sink.cpp 2017-07-28 17:00:43 +0000
+++ src/server/scene/broadcasting_session_event_sink.cpp 2017-08-18 15:06:41 +0000
@@ -20,75 +20,32 @@
2020
21namespace ms = mir::scene;21namespace ms = mir::scene;
2222
23/*
24 * TODO: Use Boost.Signals2 for this when we default to Boost 1.54, see
25 * https://svn.boost.org/trac/boost/ticket/8102 . For now, just use a custom
26 * mechanism with coarse locking. When emitting events, we copy the handlers
27 * to a temporary vector to avoid calling handlers while locked, while still
28 * being thread-safe.
29 */
30
31void ms::BroadcastingSessionEventSink::handle_focus_change(23void ms::BroadcastingSessionEventSink::handle_focus_change(
32 std::shared_ptr<Session> const& session)24 std::shared_ptr<Session> const& session)
33{25{
34 std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers;26 for_each([&](SessionEventSink* observer)
3527 { observer->handle_focus_change(session); });
36 {
37 std::lock_guard<std::mutex> lg{handler_mutex};
38 handlers = focus_change_handlers;
39 }
40
41 for (auto& handler : handlers)
42 handler(session);
43}28}
4429
45void ms::BroadcastingSessionEventSink::handle_no_focus()30void ms::BroadcastingSessionEventSink::handle_no_focus()
46{31{
47 std::vector<std::function<void()>> handlers;32 for_each([&](SessionEventSink* observer)
4833 { observer->handle_no_focus(); });
49 {
50 std::lock_guard<std::mutex> lg{handler_mutex};
51 handlers = no_focus_handlers;
52 }
53
54 for (auto& handler : handlers)
55 handler();
56}34}
5735
58void ms::BroadcastingSessionEventSink::handle_session_stopping(36void ms::BroadcastingSessionEventSink::handle_session_stopping(
59 std::shared_ptr<Session> const& session)37 std::shared_ptr<Session> const& session)
60{38{
61 std::vector<std::function<void(std::shared_ptr<Session> const&)>> handlers;39 for_each([&](SessionEventSink* observer)
6240 { observer->handle_session_stopping(session); });
63 {41}
64 std::lock_guard<std::mutex> lg{handler_mutex};42
65 handlers = session_stopping_handlers;43void ms::BroadcastingSessionEventSink::add(SessionEventSink* handler)
66 }44{
6745 ThreadSafeList<SessionEventSink*>::add(handler);
68 for (auto& handler : handlers)46}
69 handler(session);47
70}48void ms::BroadcastingSessionEventSink::remove(SessionEventSink* handler)
7149{
72void ms::BroadcastingSessionEventSink::register_focus_change_handler(50 ThreadSafeList<SessionEventSink*>::remove(handler);
73 std::function<void(std::shared_ptr<Session> const& session)> const& handler)
74{
75 std::lock_guard<std::mutex> lg{handler_mutex};
76
77 focus_change_handlers.push_back(handler);
78}
79
80void ms::BroadcastingSessionEventSink::register_no_focus_handler(
81 std::function<void()> const& handler)
82{
83 std::lock_guard<std::mutex> lg{handler_mutex};
84
85 no_focus_handlers.push_back(handler);
86}
87
88void ms::BroadcastingSessionEventSink::register_session_stopping_handler(
89 std::function<void(std::shared_ptr<Session> const& session)> const& handler)
90{
91 std::lock_guard<std::mutex> lg{handler_mutex};
92
93 session_stopping_handlers.push_back(handler);
94}51}
9552
=== modified file 'src/server/scene/broadcasting_session_event_sink.h'
--- src/server/scene/broadcasting_session_event_sink.h 2017-07-28 17:00:43 +0000
+++ src/server/scene/broadcasting_session_event_sink.h 2017-08-18 15:06:41 +0000
@@ -19,36 +19,26 @@
19#ifndef MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_19#ifndef MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_
20#define MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_20#define MIR_SCENE_BROADCASTING_SESSION_EVENT_SINK_H_
2121
22#include "session_event_sink.h"22#include "mir/scene/session_event_sink.h"
23#include "mir/scene/session_event_handler_register.h"23#include "mir/scene/session_event_handler_register.h"
2424
25#include <vector>25#include "mir/thread_safe_list.h"
26#include <mutex>
2726
28namespace mir27namespace mir
29{28{
30namespace scene29namespace scene
31{30{
32class BroadcastingSessionEventSink : public SessionEventSink,31class BroadcastingSessionEventSink : public SessionEventSink,
33 public SessionEventHandlerRegister32 public SessionEventHandlerRegister,
33 private ThreadSafeList<SessionEventSink*>
34{34{
35public:35public:
36 void handle_focus_change(std::shared_ptr<Session> const& session);36 void handle_focus_change(std::shared_ptr<Session> const& session) override;
37 void handle_no_focus();37 void handle_no_focus() override;
38 void handle_session_stopping(std::shared_ptr<Session> const& session);38 void handle_session_stopping(std::shared_ptr<Session> const& session) override;
3939
40 void register_focus_change_handler(40 void add(SessionEventSink* handler) override;
41 std::function<void(std::shared_ptr<Session> const& session)> const& handler);41 void remove(SessionEventSink* handler) override;
42 void register_no_focus_handler(
43 std::function<void()> const& handler);
44 void register_session_stopping_handler(
45 std::function<void(std::shared_ptr<Session> const& session)> const& handler);
46
47private:
48 std::mutex handler_mutex;
49 std::vector<std::function<void(std::shared_ptr<Session> const&)>> focus_change_handlers;
50 std::vector<std::function<void()>> no_focus_handlers;
51 std::vector<std::function<void(std::shared_ptr<Session> const&)>> session_stopping_handlers;
52};42};
5343
54}44}
5545
=== modified file 'src/server/scene/mediating_display_changer.cpp'
--- src/server/scene/mediating_display_changer.cpp 2017-08-09 15:03:31 +0000
+++ src/server/scene/mediating_display_changer.cpp 2017-08-18 15:06:41 +0000
@@ -23,6 +23,7 @@
23#include "mir/scene/session_container.h"23#include "mir/scene/session_container.h"
24#include "mir/scene/session.h"24#include "mir/scene/session.h"
25#include "mir/scene/session_event_handler_register.h"25#include "mir/scene/session_event_handler_register.h"
26#include "mir/scene/session_event_sink.h"
26#include "mir/graphics/display.h"27#include "mir/graphics/display.h"
27#include "mir/compositor/compositor.h"28#include "mir/compositor/compositor.h"
28#include "mir/geometry/rectangles.h"29#include "mir/geometry/rectangles.h"
@@ -124,6 +125,45 @@
124};125};
125}126}
126127
128struct ms::MediatingDisplayChanger::SessionObserver : ms::SessionEventSink
129{
130 SessionObserver(ms::MediatingDisplayChanger* self) : self{self} {}
131
132 void handle_focus_change(std::shared_ptr<mir::scene::Session> const& session) override
133 {
134 auto const weak_session = std::weak_ptr<ms::Session>(session);
135 self->server_action_queue->enqueue(
136 self,
137 [self=self,weak_session]
138 {
139 if (auto const session = weak_session.lock())
140 self->focus_change_handler(session);
141 });
142 }
143
144 void handle_no_focus() override
145 {
146 self->server_action_queue->enqueue(
147 self,
148 [self=self] { self->no_focus_handler(); });
149 }
150
151 void handle_session_stopping(std::shared_ptr<mir::scene::Session> const& session) override
152 {
153 auto const weak_session = std::weak_ptr<ms::Session>(session);
154 self->server_action_queue->enqueue(
155 self,
156 [self=self,weak_session]
157 {
158 if (auto const session = weak_session.lock())
159 self->session_stopping_handler(session);
160 });
161 }
162
163 ms::MediatingDisplayChanger* const self;
164};
165
166
127ms::MediatingDisplayChanger::MediatingDisplayChanger(167ms::MediatingDisplayChanger::MediatingDisplayChanger(
128 std::shared_ptr<mg::Display> const& display,168 std::shared_ptr<mg::Display> const& display,
129 std::shared_ptr<mc::Compositor> const& compositor,169 std::shared_ptr<mc::Compositor> const& compositor,
@@ -142,45 +182,18 @@
142 observer{observer},182 observer{observer},
143 base_configuration_{display->configuration()},183 base_configuration_{display->configuration()},
144 base_configuration_applied{true},184 base_configuration_applied{true},
145 alarm_factory{alarm_factory}185 alarm_factory{alarm_factory},
186 session_observer{std::make_unique<SessionObserver>(this)}
146{187{
147 session_event_handler_register->register_focus_change_handler(188 session_event_handler_register->add(session_observer.get());
148 [this](std::shared_ptr<ms::Session> const& session)
149 {
150 auto const weak_session = std::weak_ptr<ms::Session>(session);
151 this->server_action_queue->enqueue(
152 this,
153 [this,weak_session]
154 {
155 if (auto const session = weak_session.lock())
156 focus_change_handler(session);
157 });
158 });
159
160 session_event_handler_register->register_no_focus_handler(
161 [this]
162 {
163 this->server_action_queue->enqueue(
164 this,
165 [this] { no_focus_handler(); });
166 });
167
168 session_event_handler_register->register_session_stopping_handler(
169 [this](std::shared_ptr<ms::Session> const& session)
170 {
171 auto const weak_session = std::weak_ptr<ms::Session>(session);
172 this->server_action_queue->enqueue(
173 this,
174 [this,weak_session]
175 {
176 if (auto const session = weak_session.lock())
177 session_stopping_handler(session);
178 });
179 });
180
181 observer->initial_configuration(base_configuration_);189 observer->initial_configuration(base_configuration_);
182}190}
183191
192ms::MediatingDisplayChanger::~MediatingDisplayChanger()
193{
194 session_event_handler_register->remove(session_observer.get());
195}
196
184void ms::MediatingDisplayChanger::configure(197void ms::MediatingDisplayChanger::configure(
185 std::shared_ptr<mf::Session> const& session,198 std::shared_ptr<mf::Session> const& session,
186 std::shared_ptr<mg::DisplayConfiguration> const& conf)199 std::shared_ptr<mg::DisplayConfiguration> const& conf)
187200
=== modified file 'src/server/scene/mediating_display_changer.h'
--- src/server/scene/mediating_display_changer.h 2017-07-28 17:00:43 +0000
+++ src/server/scene/mediating_display_changer.h 2017-08-18 15:06:41 +0000
@@ -65,7 +65,9 @@
65 std::shared_ptr<graphics::DisplayConfigurationObserver> const& observer,65 std::shared_ptr<graphics::DisplayConfigurationObserver> const& observer,
66 std::shared_ptr<time::AlarmFactory> const& alarm_factory);66 std::shared_ptr<time::AlarmFactory> const& alarm_factory);
6767
68 /* From mir::frontend::DisplayChanger */68 ~MediatingDisplayChanger();
69
70 /* From mir::frontend::DisplayChanger */
69 std::shared_ptr<graphics::DisplayConfiguration> base_configuration() override;71 std::shared_ptr<graphics::DisplayConfiguration> base_configuration() override;
70 void configure(std::shared_ptr<frontend::Session> const& session,72 void configure(std::shared_ptr<frontend::Session> const& session,
71 std::shared_ptr<graphics::DisplayConfiguration> const& conf) override;73 std::shared_ptr<graphics::DisplayConfiguration> const& conf) override;
@@ -118,6 +120,8 @@
118 std::shared_ptr<time::AlarmFactory> const alarm_factory;120 std::shared_ptr<time::AlarmFactory> const alarm_factory;
119 std::unique_ptr<time::Alarm> preview_configuration_timeout;121 std::unique_ptr<time::Alarm> preview_configuration_timeout;
120 std::weak_ptr<frontend::Session> currently_previewing_session;122 std::weak_ptr<frontend::Session> currently_previewing_session;
123 struct SessionObserver;
124 std::unique_ptr<SessionObserver> const session_observer;
121};125};
122126
123}127}
124128
=== modified file 'src/server/scene/session_manager.cpp'
--- src/server/scene/session_manager.cpp 2017-07-28 17:00:43 +0000
+++ src/server/scene/session_manager.cpp 2017-08-18 15:06:41 +0000
@@ -25,7 +25,7 @@
25#include "mir/scene/prompt_session.h"25#include "mir/scene/prompt_session.h"
26#include "mir/scene/application_not_responding_detector.h"26#include "mir/scene/application_not_responding_detector.h"
27#include "mir/shell/surface_stack.h"27#include "mir/shell/surface_stack.h"
28#include "session_event_sink.h"28#include "mir/scene/session_event_sink.h"
29#include "mir/frontend/event_sink.h"29#include "mir/frontend/event_sink.h"
30#include "mir/graphics/display.h"30#include "mir/graphics/display.h"
31#include "mir/graphics/display_configuration.h"31#include "mir/graphics/display_configuration.h"
3232
=== modified file 'tests/include/mir/test/doubles/null_session_event_sink.h'
--- tests/include/mir/test/doubles/null_session_event_sink.h 2017-07-28 17:00:43 +0000
+++ tests/include/mir/test/doubles/null_session_event_sink.h 2017-08-18 15:06:41 +0000
@@ -19,7 +19,7 @@
19#ifndef MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_19#ifndef MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_
20#define MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_20#define MIR_TEST_DOUBLES_NULL_SESSION_EVENT_SINK_H_
2121
22#include "src/server/scene/session_event_sink.h"22#include "src/include/server/mir/scene/session_event_sink.h"
2323
24namespace mir24namespace mir
25{25{
2626
=== modified file 'tests/unit-tests/scene/test_abstract_shell.cpp'
--- tests/unit-tests/scene/test_abstract_shell.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_abstract_shell.cpp 2017-08-18 15:06:41 +0000
@@ -26,7 +26,7 @@
2626
27#include "src/server/report/null/shell_report.h"27#include "src/server/report/null/shell_report.h"
28#include "src/server/scene/default_session_container.h"28#include "src/server/scene/default_session_container.h"
29#include "src/server/scene/session_event_sink.h"29#include "src/include/server/mir/scene/session_event_sink.h"
30#include "src/server/scene/session_manager.h"30#include "src/server/scene/session_manager.h"
3131
32#include "mir/test/doubles/mock_window_manager.h"32#include "mir/test/doubles/mock_window_manager.h"
3333
=== modified file 'tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp'
--- tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_broadcasting_session_event_sink.cpp 2017-08-18 15:06:41 +0000
@@ -21,79 +21,74 @@
21#include "mir/test/fake_shared.h"21#include "mir/test/fake_shared.h"
2222
23#include <gtest/gtest.h>23#include <gtest/gtest.h>
24#include <gmock/gmock.h>
2425
25namespace ms = mir::scene;26namespace ms = mir::scene;
26namespace mtd = mir::test::doubles;27namespace mtd = mir::test::doubles;
27namespace mt = mir::test;28namespace mt = mir::test;
29using namespace testing;
30
31namespace
32{
33struct MockEventSink : ms::SessionEventSink
34{
35 MOCK_METHOD1(handle_focus_change, void (std::shared_ptr<ms::Session> const& session));
36 MOCK_METHOD1(handle_session_stopping, void (std::shared_ptr<ms::Session> const& session));
37 MOCK_METHOD0(handle_no_focus, void ());
38};
39}
2840
29TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change)41TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change)
30{42{
31 mtd::StubSession session1;43 mtd::StubSession session1;
32 std::vector<ms::Session*> handler_called(3, nullptr);44 MockEventSink handler_called[3];
3345
34 ms::BroadcastingSessionEventSink events;46 ms::BroadcastingSessionEventSink events;
3547
48 std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)};
49
36 for (auto& h : handler_called)50 for (auto& h : handler_called)
37 {51 {
38 events.register_focus_change_handler(52 events.add(&h);
39 [&h](std::shared_ptr<ms::Session> const& session)53
40 {54 EXPECT_CALL(h, handle_focus_change(session1ptr)).Times(1);
41 h = session.get();55 }
42 });56
43 }57 events.handle_focus_change(session1ptr);
44
45 events.handle_focus_change(mt::fake_shared(session1));
46
47 for (unsigned int i = 0; i < handler_called.size(); i++)
48 {
49 EXPECT_EQ(&session1, handler_called[i]) << " i = " << i;
50 }
51}58}
5259
53TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus)60TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus)
54{61{
55 mtd::StubSession session1;62 mtd::StubSession session1;
56 std::vector<int> handler_called(3, 0);63 MockEventSink handler_called[3];
5764
58 ms::BroadcastingSessionEventSink events;65 ms::BroadcastingSessionEventSink events;
5966
60 for (auto& h : handler_called)67 for (auto& h : handler_called)
61 {68 {
62 events.register_no_focus_handler(69 events.add(&h);
63 [&h]70
64 {71 EXPECT_CALL(h, handle_no_focus()).Times(1);
65 h = 1;
66 });
67 }72 }
6873
69 events.handle_no_focus();74 events.handle_no_focus();
70
71 for (unsigned int i = 0; i < handler_called.size(); i++)
72 {
73 EXPECT_EQ(1, handler_called[i]) << " i = " << i;
74 }
75}75}
7676
77TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping)77TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping)
78{78{
79 mtd::StubSession session1;79 mtd::StubSession session1;
80 std::vector<ms::Session*> handler_called(3, nullptr);80 MockEventSink handler_called[3];
8181
82 ms::BroadcastingSessionEventSink events;82 ms::BroadcastingSessionEventSink events;
8383
84 std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)};
85
84 for (auto& h : handler_called)86 for (auto& h : handler_called)
85 {87 {
86 events.register_session_stopping_handler(88 events.add(&h);
87 [&h](std::shared_ptr<ms::Session> const& session)89
88 {90 EXPECT_CALL(h, handle_session_stopping(session1ptr)).Times(1);
89 h = session.get();91 }
90 });92
91 }93 events.handle_session_stopping(session1ptr);
92
93 events.handle_session_stopping(mt::fake_shared(session1));
94
95 for (unsigned int i = 0; i < handler_called.size(); i++)
96 {
97 EXPECT_EQ(&session1, handler_called[i]) << " i = " << i;
98 }
99}94}
10095
=== modified file 'tests/unit-tests/scene/test_session_manager.cpp'
--- tests/unit-tests/scene/test_session_manager.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_session_manager.cpp 2017-08-18 15:06:41 +0000
@@ -24,7 +24,7 @@
2424
25#include "src/server/scene/basic_surface.h"25#include "src/server/scene/basic_surface.h"
26#include "src/server/scene/default_session_container.h"26#include "src/server/scene/default_session_container.h"
27#include "src/server/scene/session_event_sink.h"27#include "src/include/server/mir/scene/session_event_sink.h"
28#include "src/server/report/null_report_factory.h"28#include "src/server/report/null_report_factory.h"
2929
30#include "mir/test/doubles/mock_surface_stack.h"30#include "mir/test/doubles/mock_surface_stack.h"

Subscribers

People subscribed via source and target branches