Mir

Merge lp:~robert-ancell/mir/abstract-session-container into lp:~mir-team/mir/trunk

Proposed by Robert Ancell
Status: Merged
Approved by: Robert Ancell
Approved revision: no longer in the source branch.
Merged at revision: 604
Proposed branch: lp:~robert-ancell/mir/abstract-session-container
Merge into: lp:~mir-team/mir/trunk
Diff against target: 357 lines (+89/-46)
11 files modified
3rd_party/gmock-1.6.0/include/gmock/gmock-generated-nice-strict.h (+2/-2)
include/server/mir/shell/default_session_container.h (+54/-0)
include/server/mir/shell/session_container.h (+9/-12)
src/server/default_server_configuration.cpp (+2/-1)
src/server/shell/CMakeLists.txt (+1/-1)
src/server/shell/default_session_container.cpp (+4/-14)
tests/integration-tests/shell/test_session_manager.cpp (+3/-3)
tests/unit-tests/shell/test_registration_order_focus_sequence.cpp (+3/-3)
tests/unit-tests/shell/test_session_manager.cpp (+3/-2)
tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp (+3/-3)
tests/unit-tests/shell/test_the_session_container_implementation.cpp (+5/-5)
To merge this branch: bzr merge lp:~robert-ancell/mir/abstract-session-container
Reviewer Review Type Date Requested Status
Alan Griffiths Abstain
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Review via email: mp+159523@code.launchpad.net

Commit message

Make mir::shell::SessionContainer an abstract class with a default implementation in DefaultSessionManager

Description of the change

Make mir::shell::SessionContainer an abstract class with a default implementation in DefaultSessionManager - the current class isn't useful if you want to access the session list in dynamic ways not present in the interface. The convention in Mir seems to be for the class to be abstract and allow the shell to implement this class if it needs more complex behaviour.

To post a comment you must log in.
Revision history for this message
Kevin DuBois (kdub) wrote :

well, looks good to me.

83 + virtual ~SessionContainer() {};
could be virtual ~SessionContainer() = default; ,which gives the stronger noexcept guarantee. (some of our classes have this, some don't but I think we're moving more towards this convention)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) wrote :

> well, looks good to me.
>
> 83 + virtual ~SessionContainer() {};
> could be virtual ~SessionContainer() = default; ,which gives the stronger
> noexcept guarantee. (some of our classes have this, some don't but I think
> we're moving more towards this convention)

I copied ServerConfiguration here in doing it this way. When I originally had the default destructor it stops the mock SessionContainer classes from working (not sure why).

Revision history for this message
Robert Ancell (robert-ancell) wrote :

I managed to use the noexcept destructor - it required a change from lp:~kdub/mir/nicemock-improvementslp:mir.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Intent is reasonable - although it would be good to have a use-case/acceptance test for "if you want to access the session list in dynamic ways not present in the interface".

There's an unnecessary header:

122 #include "mir/shell/session_container.h"

My doubts about the change from lp:~kdub/mir/nicemock-improvements are expressed there. (Shouldn't that be a prerequisite?)

review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/gmock-1.6.0/include/gmock/gmock-generated-nice-strict.h'
2--- 3rd_party/gmock-1.6.0/include/gmock/gmock-generated-nice-strict.h 2012-08-08 08:07:55 +0000
3+++ 3rd_party/gmock-1.6.0/include/gmock/gmock-generated-nice-strict.h 2013-04-18 08:57:29 +0000
4@@ -151,7 +151,7 @@
5 internal::ImplicitCast_<MockClass*>(this));
6 }
7
8- virtual ~NiceMock() {
9+ virtual ~NiceMock() noexcept {
10 ::testing::Mock::UnregisterCallReaction(
11 internal::ImplicitCast_<MockClass*>(this));
12 }
13@@ -245,7 +245,7 @@
14 internal::ImplicitCast_<MockClass*>(this));
15 }
16
17- virtual ~StrictMock() {
18+ virtual ~StrictMock() noexcept {
19 ::testing::Mock::UnregisterCallReaction(
20 internal::ImplicitCast_<MockClass*>(this));
21 }
22
23=== added file 'include/server/mir/shell/default_session_container.h'
24--- include/server/mir/shell/default_session_container.h 1970-01-01 00:00:00 +0000
25+++ include/server/mir/shell/default_session_container.h 2013-04-18 08:57:29 +0000
26@@ -0,0 +1,54 @@
27+/*
28+ * Copyright © 2012 Canonical Ltd.
29+ *
30+ * This program is free software: you can redistribute it and/or modify it
31+ * under the terms of the GNU General Public License version 3,
32+ * as published by the Free Software Foundation.
33+ *
34+ * This program is distributed in the hope that it will be useful,
35+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
36+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37+ * GNU General Public License for more details.
38+ *
39+ * You should have received a copy of the GNU General Public License
40+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
41+ *
42+ * Authored by: Robert Carr <robert.carr@canonical.com>
43+ */
44+
45+#ifndef MIR_SHELL_DEFAULT_SESSION_CONTAINER_H_
46+#define MIR_SHELL_DEFAULT_SESSION_CONTAINER_H_
47+
48+#include <vector>
49+#include <memory>
50+#include <mutex>
51+
52+#include "mir/shell/session_container.h"
53+
54+namespace mir
55+{
56+namespace frontend
57+{
58+class Session;
59+}
60+
61+namespace shell
62+{
63+
64+class DefaultSessionContainer : public SessionContainer
65+{
66+public:
67+ void insert_session(std::shared_ptr<frontend::Session> const& session);
68+ void remove_session(std::shared_ptr<frontend::Session> const& session);
69+ void for_each(std::function<void(std::shared_ptr<frontend::Session> const&)> f) const;
70+
71+private:
72+ std::vector<std::shared_ptr<frontend::Session>> apps;
73+ mutable std::mutex guard;
74+};
75+
76+}
77+}
78+
79+
80+#endif // MIR_SHELL_DEFAULT_SESSION_CONTAINER_H_
81
82=== modified file 'include/server/mir/shell/session_container.h'
83--- include/server/mir/shell/session_container.h 2013-04-16 09:08:29 +0000
84+++ include/server/mir/shell/session_container.h 2013-04-18 08:57:29 +0000
85@@ -36,20 +36,17 @@
86 class SessionContainer
87 {
88 public:
89- SessionContainer();
90- ~SessionContainer();
91-
92- virtual void insert_session(std::shared_ptr<frontend::Session> const& session);
93- virtual void remove_session(std::shared_ptr<frontend::Session> const& session);
94-
95- void for_each(std::function<void(std::shared_ptr<frontend::Session> const&)> f) const;
96-
97-private:
98+ virtual void insert_session(std::shared_ptr<frontend::Session> const& session) = 0;
99+ virtual void remove_session(std::shared_ptr<frontend::Session> const& session) = 0;
100+
101+ virtual void for_each(std::function<void(std::shared_ptr<frontend::Session> const&)> f) const = 0;
102+
103+protected:
104+ SessionContainer() = default;
105+ virtual ~SessionContainer() = default;
106+
107 SessionContainer(const SessionContainer&) = delete;
108 SessionContainer& operator=(const SessionContainer&) = delete;
109-
110- std::vector<std::shared_ptr<frontend::Session>> apps;
111- mutable std::mutex guard;
112 };
113
114 }
115
116=== modified file 'src/server/default_server_configuration.cpp'
117--- src/server/default_server_configuration.cpp 2013-04-17 16:57:53 +0000
118+++ src/server/default_server_configuration.cpp 2013-04-18 08:57:29 +0000
119@@ -36,6 +36,7 @@
120 #include "mir/shell/registration_order_focus_sequence.h"
121 #include "mir/shell/single_visibility_focus_mechanism.h"
122 #include "mir/shell/session_container.h"
123+#include "mir/shell/default_session_container.h"
124 #include "mir/shell/consuming_placement_strategy.h"
125 #include "mir/shell/organising_surface_factory.h"
126 #include "mir/graphics/display.h"
127@@ -300,7 +301,7 @@
128 mir::DefaultServerConfiguration::the_shell_session_container()
129 {
130 return shell_session_container(
131- []{ return std::make_shared<msh::SessionContainer>(); });
132+ []{ return std::make_shared<msh::DefaultSessionContainer>(); });
133 }
134
135 std::shared_ptr<msh::FocusSetter>
136
137=== modified file 'src/server/shell/CMakeLists.txt'
138--- src/server/shell/CMakeLists.txt 2013-03-21 03:32:59 +0000
139+++ src/server/shell/CMakeLists.txt 2013-04-18 08:57:29 +0000
140@@ -2,7 +2,7 @@
141 SHELL_SOURCES
142
143 application_session.cpp
144- session_container.cpp
145+ default_session_container.cpp
146 session_manager.cpp
147 registration_order_focus_sequence.cpp
148 single_visibility_focus_mechanism.cpp
149
150=== renamed file 'src/server/shell/session_container.cpp' => 'src/server/shell/default_session_container.cpp'
151--- src/server/shell/session_container.cpp 2013-04-16 09:08:29 +0000
152+++ src/server/shell/default_session_container.cpp 2013-04-18 08:57:29 +0000
153@@ -16,7 +16,7 @@
154 * Authored By: Robert Carr <robert.carr@canonical.com>
155 */
156
157-#include "mir/shell/session_container.h"
158+#include "mir/shell/default_session_container.h"
159 #include "mir/frontend/session.h"
160
161 #include <boost/throw_exception.hpp>
162@@ -26,27 +26,17 @@
163 #include <algorithm>
164 #include <stdexcept>
165
166-
167 namespace mf = mir::frontend;
168 namespace msh = mir::shell;
169
170-msh::SessionContainer::SessionContainer()
171-{
172-
173-}
174-
175-msh::SessionContainer::~SessionContainer()
176-{
177-}
178-
179-void msh::SessionContainer::insert_session(std::shared_ptr<mf::Session> const& session)
180+void msh::DefaultSessionContainer::insert_session(std::shared_ptr<mf::Session> const& session)
181 {
182 std::unique_lock<std::mutex> lk(guard);
183
184 apps.push_back(session);
185 }
186
187-void msh::SessionContainer::remove_session(std::shared_ptr<mf::Session> const& session)
188+void msh::DefaultSessionContainer::remove_session(std::shared_ptr<mf::Session> const& session)
189 {
190 std::unique_lock<std::mutex> lk(guard);
191
192@@ -61,7 +51,7 @@
193 }
194 }
195
196-void msh::SessionContainer::for_each(std::function<void(std::shared_ptr<mf::Session> const&)> f) const
197+void msh::DefaultSessionContainer::for_each(std::function<void(std::shared_ptr<mf::Session> const&)> f) const
198 {
199 std::unique_lock<std::mutex> lk(guard);
200
201
202=== modified file 'tests/integration-tests/shell/test_session_manager.cpp'
203--- tests/integration-tests/shell/test_session_manager.cpp 2013-03-22 16:41:59 +0000
204+++ tests/integration-tests/shell/test_session_manager.cpp 2013-04-18 08:57:29 +0000
205@@ -21,7 +21,7 @@
206 #include "mir/shell/focus_sequence.h"
207 #include "mir/shell/focus_setter.h"
208 #include "mir/shell/registration_order_focus_sequence.h"
209-#include "mir/shell/session_container.h"
210+#include "mir/shell/default_session_container.h"
211 #include "mir/surfaces/buffer_bundle.h"
212 #include "mir/surfaces/surface.h"
213 #include "mir/compositor/buffer_swapper.h"
214@@ -45,7 +45,7 @@
215 {
216 using namespace ::testing;
217 mtd::MockSurfaceFactory surface_factory;
218- std::shared_ptr<msh::SessionContainer> container(new msh::SessionContainer());
219+ std::shared_ptr<msh::DefaultSessionContainer> container(new msh::DefaultSessionContainer());
220 msh::RegistrationOrderFocusSequence sequence(container);
221 mtd::MockFocusSetter focus_changer;
222 std::shared_ptr<mf::Session> new_session;
223@@ -78,7 +78,7 @@
224 {
225 using namespace ::testing;
226 mtd::MockSurfaceFactory surface_factory;
227- std::shared_ptr<msh::SessionContainer> model(new msh::SessionContainer());
228+ std::shared_ptr<msh::DefaultSessionContainer> model(new msh::DefaultSessionContainer());
229 msh::RegistrationOrderFocusSequence sequence(model);
230 mtd::MockFocusSetter focus_changer;
231 std::shared_ptr<mf::Session> new_session;
232
233=== modified file 'tests/unit-tests/shell/test_registration_order_focus_sequence.cpp'
234--- tests/unit-tests/shell/test_registration_order_focus_sequence.cpp 2013-03-29 16:51:35 +0000
235+++ tests/unit-tests/shell/test_registration_order_focus_sequence.cpp 2013-04-18 08:57:29 +0000
236@@ -18,7 +18,7 @@
237
238 #include "mir/surfaces/buffer_bundle.h"
239 #include "mir/shell/application_session.h"
240-#include "mir/shell/session_container.h"
241+#include "mir/shell/default_session_container.h"
242 #include "mir/shell/registration_order_focus_sequence.h"
243 #include "mir/frontend/surface_creation_parameters.h"
244 #include "mir/surfaces/surface.h"
245@@ -41,10 +41,10 @@
246 void SetUp()
247 {
248 factory = std::make_shared<mtd::MockSurfaceFactory>();
249- container = std::make_shared<msh::SessionContainer>();
250+ container = std::make_shared<msh::DefaultSessionContainer>();
251 }
252 std::shared_ptr<mtd::MockSurfaceFactory> factory;
253- std::shared_ptr<msh::SessionContainer> container;
254+ std::shared_ptr<msh::DefaultSessionContainer> container;
255
256 static std::string const testing_app_name1;
257 static std::string const testing_app_name2;
258
259=== modified file 'tests/unit-tests/shell/test_session_manager.cpp'
260--- tests/unit-tests/shell/test_session_manager.cpp 2013-04-01 16:11:03 +0000
261+++ tests/unit-tests/shell/test_session_manager.cpp 2013-04-18 08:57:29 +0000
262@@ -19,7 +19,7 @@
263 #include "mir/surfaces/buffer_bundle.h"
264 #include "mir/shell/focus_sequence.h"
265 #include "mir/shell/session_manager.h"
266-#include "mir/shell/session_container.h"
267+#include "mir/shell/default_session_container.h"
268 #include "mir/shell/session.h"
269 #include "mir/frontend/session.h"
270 #include "mir/frontend/surface_creation_parameters.h"
271@@ -48,12 +48,13 @@
272
273 namespace
274 {
275-struct MockSessionContainer : public msh::SessionContainer
276+struct MockSessionContainer : public msh::DefaultSessionContainer
277 {
278 MOCK_METHOD1(insert_session, void(std::shared_ptr<mf::Session> const&));
279 MOCK_METHOD1(remove_session, void(std::shared_ptr<mf::Session> const&));
280 MOCK_METHOD0(lock, void());
281 MOCK_METHOD0(unlock, void());
282+ ~MockSessionContainer() noexcept {}
283 };
284
285 struct MockFocusSequence: public msh::FocusSequence
286
287=== modified file 'tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp'
288--- tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp 2013-04-16 17:42:26 +0000
289+++ tests/unit-tests/shell/test_single_visibility_focus_mechanism.cpp 2013-04-18 08:57:29 +0000
290@@ -18,7 +18,7 @@
291
292 #include "mir/surfaces/buffer_bundle.h"
293 #include "mir/shell/application_session.h"
294-#include "mir/shell/session_container.h"
295+#include "mir/shell/default_session_container.h"
296 #include "mir/shell/registration_order_focus_sequence.h"
297 #include "mir/shell/single_visibility_focus_mechanism.h"
298 #include "mir/shell/session.h"
299@@ -67,7 +67,7 @@
300 NiceMock<mtd::MockInputFocusSelector> input_focus_selector;
301
302 MockShellSession app1, app2, app3;
303- msh::SessionContainer model;
304+ msh::DefaultSessionContainer model;
305
306 ON_CALL(app1, default_surface()).WillByDefault(Return(std::shared_ptr<msh::Surface>()));
307 ON_CALL(app2, default_surface()).WillByDefault(Return(std::shared_ptr<msh::Surface>()));
308@@ -95,7 +95,7 @@
309 using namespace ::testing;
310
311 mtd::MockInputFocusSelector input_focus_selector;
312- msh::SessionContainer model;
313+ msh::DefaultSessionContainer model;
314 auto session = std::make_shared<MockShellSession>();
315 auto surface = std::make_shared<mtd::MockSurface>(std::make_shared<mtd::StubSurfaceBuilder>());
316
317
318=== modified file 'tests/unit-tests/shell/test_the_session_container_implementation.cpp'
319--- tests/unit-tests/shell/test_the_session_container_implementation.cpp 2013-03-22 16:41:59 +0000
320+++ tests/unit-tests/shell/test_the_session_container_implementation.cpp 2013-04-18 08:57:29 +0000
321@@ -18,7 +18,7 @@
322
323 #include "mir/surfaces/buffer_bundle.h"
324 #include "mir/shell/application_session.h"
325-#include "mir/shell/session_container.h"
326+#include "mir/shell/default_session_container.h"
327 #include "mir/frontend/surface_creation_parameters.h"
328 #include "mir/surfaces/surface.h"
329 #include "mir_test_doubles/mock_buffer_bundle.h"
330@@ -32,11 +32,11 @@
331 namespace msh = mir::shell;
332 namespace mtd = mir::test::doubles;
333
334-TEST(SessionContainer, for_each)
335+TEST(DefaultSessionContainer, for_each)
336 {
337 using namespace ::testing;
338 auto factory = std::make_shared<mtd::MockSurfaceFactory>();
339- msh::SessionContainer container;
340+ msh::DefaultSessionContainer container;
341
342 container.insert_session(std::make_shared<msh::ApplicationSession>(factory, "Visual Studio 7"));
343 container.insert_session(std::make_shared<msh::ApplicationSession>(factory, "Visual Studio 8"));
344@@ -58,11 +58,11 @@
345 container.for_each(std::ref(functor));
346 }
347
348-TEST(SessionContainer, invalid_session_throw_behavior)
349+TEST(DefaultSessionContainer, invalid_session_throw_behavior)
350 {
351 using namespace ::testing;
352 auto factory = std::make_shared<mtd::MockSurfaceFactory>();
353- msh::SessionContainer container;
354+ msh::DefaultSessionContainer container;
355
356 auto session = std::make_shared<msh::ApplicationSession>(factory,
357 "Visual Studio 7");

Subscribers

People subscribed via source and target branches