Merge lp:~cemil-azizoglu/mir/nested_lifecycle_events into lp:mir
- nested_lifecycle_events
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Cemil Azizoglu |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1774 |
Proposed branch: | lp:~cemil-azizoglu/mir/nested_lifecycle_events |
Merge into: | lp:mir |
Diff against target: |
414 lines (+222/-4) 10 files modified
examples/demo-shell/demo_shell.cpp (+20/-0) examples/demo-shell/window_manager.cpp (+11/-0) include/server/mir/default_server_configuration.h (+4/-0) include/server/mir/shell/host_lifecycle_event_listener.h (+44/-0) src/server/graphics/default_configuration.cpp (+2/-1) src/server/graphics/nested/mir_client_host_connection.cpp (+16/-2) src/server/graphics/nested/mir_client_host_connection.h (+5/-1) src/server/shell/default_configuration.cpp (+12/-0) src/server/shell/null_host_lifecycle_event_listener.h (+38/-0) tests/acceptance-tests/test_nested_mir.cpp (+70/-0) |
To merge this branch: | bzr merge lp:~cemil-azizoglu/mir/nested_lifecycle_events |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Alan Griffiths | Needs Fixing | ||
Alexandros Frantzis (community) | Approve | ||
Andreas Pokorny (community) | Approve | ||
Michael Terry | Pending | ||
Review via email: mp+224426@code.launchpad.net |
Commit message
Listen to lifecycle events in nested server.
Description of the change
Nested server registers a callback for lifecycle events coming from the host. This is necessary for the nested server to receive lifecycle events so that its clients, in turn, can be notified.
To showcase, I have also added the ability to send lifecycle events to the focussed app upon hitting ctl-alt-L, to the example shell.
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
Alan Griffiths (alan-griffiths) wrote : | # |
21 + ${PROJECT_
Not needed: use the canonical include path "mir/scene/
22 + ${PROJECT_
Not allowed (hence disapprove)
Alan Griffiths (alan-griffiths) wrote : | # |
After our discussions on IRC I thought the intent was to provide a "hook" so that shells implemented using Mir could "hook" into these events and process them. As such I think that HostLifecycleEv
~~~~
86 + mirnestedscene
...
193 +add_subdirecto
...
203 +#include "nested/
etc.
This new "scene/nested" library is not justified. All it contains is a default (null) implementation of an interface: scene::
~~~~
144 + std::static_
No obvious need for the cast.
~~~~~
+void DefaultHostLife
283 +{
284 + app_container-
285 + [&state]
286 + {
287 + session-
288 + });
289 +}
I think the default behavior should be to do nothing and let the implementing shell use this as a hook.
Alan Griffiths (alan-griffiths) wrote : | # |
Getting closer. ;)
24 + /* Duplicate impl. Could move to a common library so Mir proper, and examples can share. */
25 + class NullHostLifecyc
26 + {
27 + public:
28 + virtual void lifecycle_
29 + {
30 + printf("This line must not be output\n");
31 + }
32 + };
Not needed as
57 + return host_lifecycle_
58 + []()
59 + {
60 + return std::make_
61 + });
62 + }
Can be simply
return mir::examples:
Although...
45 + auto nested = the_options(
46 +
47 + if (nested)
Do we actually need two paths here? The function will only be called when a HostLifecycleEv
~~~~
362 + EXPECT_CALL(*this, lifecycle_
Expectations should be set in the test body - as that should explain what is being checked. (And it would also be nice to see several notifications checked by InSequence.)
Alan Griffiths (alan-griffiths) wrote : | # |
%s/occured/
~~~~
347 + void TriggerLifecycl
http://
~~~~
387 + TriggerLifecycl
388 + TriggerLifecycl
389 +
390 + InSequence seq;
...
I'm surprised that sending the events before setting the expectations isn't racy.
~~~~
391 + EXPECT_
392 + EXPECT_
Excessively long lines.
I'd prefer to expose the MockHostLifecyc
Something like:
TEST_F(
{
struct MyServerConfigu
{
using NestedServerCon
{
return host_lifecycle_
{
});
}
};
MyServerCon
NestedMirRunner nested_
InSequence seq;
EXPECT_
EXPECT_
trigger_
trigger_
}
(Although that inheritance-
Alan Griffiths (alan-griffiths) wrote : | # |
> 387 + TriggerLifecycl
> 388 + TriggerLifecycl
> 389 +
> 390 + InSequence seq;
> ...
>
> I'm surprised that sending the events before setting the expectations isn't
> racy.
Actually it is.
Sticking in...
std:
...shouldn't hurt but it does.
Alan Griffiths (alan-griffiths) wrote : | # |
LGTM - although the example code sending the same event every time is a bit boring.
BTW does Jenkins not recognize you? It should be reviewing this.
Andreas Pokorny (andreas-pokorny) wrote : | # |
toggling through life cycle would be cool.
All fine but a there is a C-Cast in 169, that should be a static_cast.
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good overall.
A couple of nits:
169 + msh::HostLifecy
The c-cast like mentioned by Andreas, and also '*' should go with the type (msh::HostLifec
58 + if(app)
Space between if and '('.
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
Iterating through an enum is a bit painful and would make the code messy. So I'll leave the example boring, but hopefully to the point. (Other comments addressed.)
Andreas Pokorny (andreas-pokorny) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1790
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Alan Griffiths (alan-griffiths) wrote : | # |
8 + . DefaultServerCo
Don't make changes to the cahngelog in "routine" MPs
These will all show at the same point and lead to spurious merge conflicts.
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
> 8 + . DefaultServerCo
> server.
>
> Don't make changes to the cahngelog in "routine" MPs
>
> These will all show at the same point and lead to spurious merge conflicts.
Fixed.
PS Jenkins bot (ps-jenkins) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1792
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'examples/demo-shell/demo_shell.cpp' | |||
2 | --- examples/demo-shell/demo_shell.cpp 2014-06-04 22:09:06 +0000 | |||
3 | +++ examples/demo-shell/demo_shell.cpp 2014-07-16 15:59:57 +0000 | |||
4 | @@ -29,6 +29,7 @@ | |||
5 | 29 | #include "mir/graphics/display.h" | 29 | #include "mir/graphics/display.h" |
6 | 30 | #include "mir/input/composite_event_filter.h" | 30 | #include "mir/input/composite_event_filter.h" |
7 | 31 | #include "mir/compositor/renderer_factory.h" | 31 | #include "mir/compositor/renderer_factory.h" |
8 | 32 | #include "mir/shell/host_lifecycle_event_listener.h" | ||
9 | 32 | 33 | ||
10 | 33 | #include <iostream> | 34 | #include <iostream> |
11 | 34 | 35 | ||
12 | @@ -38,6 +39,7 @@ | |||
13 | 38 | namespace mf = mir::frontend; | 39 | namespace mf = mir::frontend; |
14 | 39 | namespace mi = mir::input; | 40 | namespace mi = mir::input; |
15 | 40 | namespace mo = mir::options; | 41 | namespace mo = mir::options; |
16 | 42 | namespace msh = mir::shell; | ||
17 | 41 | 43 | ||
18 | 42 | namespace mir | 44 | namespace mir |
19 | 43 | { | 45 | { |
20 | @@ -108,6 +110,24 @@ | |||
21 | 108 | return std::make_shared<DemoRendererFactory>(the_gl_program_factory()); | 110 | return std::make_shared<DemoRendererFactory>(the_gl_program_factory()); |
22 | 109 | } | 111 | } |
23 | 110 | 112 | ||
24 | 113 | class NestedLifecycleEventListener : public msh::HostLifecycleEventListener | ||
25 | 114 | { | ||
26 | 115 | public: | ||
27 | 116 | virtual void lifecycle_event_occurred(MirLifecycleState state) override | ||
28 | 117 | { | ||
29 | 118 | printf("Lifecycle event occurred : state = %d\n", state); | ||
30 | 119 | } | ||
31 | 120 | }; | ||
32 | 121 | |||
33 | 122 | std::shared_ptr<msh::HostLifecycleEventListener> the_host_lifecycle_event_listener() override | ||
34 | 123 | { | ||
35 | 124 | return host_lifecycle_event_listener( | ||
36 | 125 | []() | ||
37 | 126 | { | ||
38 | 127 | return std::make_shared<NestedLifecycleEventListener>(); | ||
39 | 128 | }); | ||
40 | 129 | } | ||
41 | 130 | |||
42 | 111 | private: | 131 | private: |
43 | 112 | std::vector<std::shared_ptr<mi::EventFilter>> const filter_list; | 132 | std::vector<std::shared_ptr<mi::EventFilter>> const filter_list; |
44 | 113 | }; | 133 | }; |
45 | 114 | 134 | ||
46 | === modified file 'examples/demo-shell/window_manager.cpp' | |||
47 | --- examples/demo-shell/window_manager.cpp 2014-06-10 14:40:23 +0000 | |||
48 | +++ examples/demo-shell/window_manager.cpp 2014-07-16 15:59:57 +0000 | |||
49 | @@ -163,6 +163,17 @@ | |||
50 | 163 | return true; | 163 | return true; |
51 | 164 | } | 164 | } |
52 | 165 | else if ((event.key.modifiers & mir_key_modifier_alt) && | 165 | else if ((event.key.modifiers & mir_key_modifier_alt) && |
53 | 166 | (event.key.modifiers & mir_key_modifier_ctrl) && | ||
54 | 167 | (event.key.scan_code == KEY_L) && | ||
55 | 168 | focus_controller) | ||
56 | 169 | { | ||
57 | 170 | auto const app = focus_controller->focussed_application().lock(); | ||
58 | 171 | if (app) | ||
59 | 172 | { | ||
60 | 173 | app->set_lifecycle_state(mir_lifecycle_state_will_suspend); | ||
61 | 174 | } | ||
62 | 175 | } | ||
63 | 176 | else if ((event.key.modifiers & mir_key_modifier_alt) && | ||
64 | 166 | (event.key.modifiers & mir_key_modifier_ctrl)) | 177 | (event.key.modifiers & mir_key_modifier_ctrl)) |
65 | 167 | { | 178 | { |
66 | 168 | MirOrientation orientation = mir_orientation_normal; | 179 | MirOrientation orientation = mir_orientation_normal; |
67 | 169 | 180 | ||
68 | === modified file 'include/server/mir/default_server_configuration.h' | |||
69 | --- include/server/mir/default_server_configuration.h 2014-07-09 10:48:47 +0000 | |||
70 | +++ include/server/mir/default_server_configuration.h 2014-07-16 15:59:57 +0000 | |||
71 | @@ -69,6 +69,7 @@ | |||
72 | 69 | class FocusSetter; | 69 | class FocusSetter; |
73 | 70 | class FocusController; | 70 | class FocusController; |
74 | 71 | class DisplayLayout; | 71 | class DisplayLayout; |
75 | 72 | class HostLifecycleEventListener; | ||
76 | 72 | } | 73 | } |
77 | 73 | namespace time | 74 | namespace time |
78 | 74 | { | 75 | { |
79 | @@ -243,6 +244,8 @@ | |||
80 | 243 | virtual std::shared_ptr<shell::DisplayLayout> the_shell_display_layout(); | 244 | virtual std::shared_ptr<shell::DisplayLayout> the_shell_display_layout(); |
81 | 244 | virtual std::shared_ptr<scene::PromptSessionListener> the_prompt_session_listener(); | 245 | virtual std::shared_ptr<scene::PromptSessionListener> the_prompt_session_listener(); |
82 | 245 | virtual std::shared_ptr<scene::PromptSessionManager> the_prompt_session_manager(); | 246 | virtual std::shared_ptr<scene::PromptSessionManager> the_prompt_session_manager(); |
83 | 247 | virtual std::shared_ptr<shell::HostLifecycleEventListener> the_host_lifecycle_event_listener(); | ||
84 | 248 | |||
85 | 246 | /** @} */ | 249 | /** @} */ |
86 | 247 | 250 | ||
87 | 248 | /** @name internal scene configuration | 251 | /** @name internal scene configuration |
88 | @@ -394,6 +397,7 @@ | |||
89 | 394 | CachedPtr<scene::PromptSessionManager> prompt_session_manager; | 397 | CachedPtr<scene::PromptSessionManager> prompt_session_manager; |
90 | 395 | CachedPtr<scene::SessionCoordinator> session_coordinator; | 398 | CachedPtr<scene::SessionCoordinator> session_coordinator; |
91 | 396 | CachedPtr<EmergencyCleanup> emergency_cleanup; | 399 | CachedPtr<EmergencyCleanup> emergency_cleanup; |
92 | 400 | CachedPtr<shell::HostLifecycleEventListener> host_lifecycle_event_listener; | ||
93 | 397 | 401 | ||
94 | 398 | private: | 402 | private: |
95 | 399 | std::shared_ptr<options::Configuration> const configuration_options; | 403 | std::shared_ptr<options::Configuration> const configuration_options; |
96 | 400 | 404 | ||
97 | === added file 'include/server/mir/shell/host_lifecycle_event_listener.h' | |||
98 | --- include/server/mir/shell/host_lifecycle_event_listener.h 1970-01-01 00:00:00 +0000 | |||
99 | +++ include/server/mir/shell/host_lifecycle_event_listener.h 2014-07-16 15:59:57 +0000 | |||
100 | @@ -0,0 +1,44 @@ | |||
101 | 1 | /* | ||
102 | 2 | * Copyright © 2014 Canonical Ltd. | ||
103 | 3 | * | ||
104 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
105 | 5 | * under the terms of the GNU General Public License version 3, | ||
106 | 6 | * as published by the Free Software Foundation. | ||
107 | 7 | * | ||
108 | 8 | * This program is distributed in the hope that it will be useful, | ||
109 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
110 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
111 | 11 | * GNU General Public License for more details. | ||
112 | 12 | * | ||
113 | 13 | * You should have received a copy of the GNU General Public License | ||
114 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
115 | 15 | * | ||
116 | 16 | * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com> | ||
117 | 17 | */ | ||
118 | 18 | |||
119 | 19 | #ifndef MIR_HOST_LIFECYCLE_EVENT_LISTENER_H_ | ||
120 | 20 | #define MIR_HOST_LIFECYCLE_EVENT_LISTENER_H_ | ||
121 | 21 | |||
122 | 22 | #include "mir_toolkit/common.h" | ||
123 | 23 | |||
124 | 24 | namespace mir | ||
125 | 25 | { | ||
126 | 26 | namespace shell | ||
127 | 27 | { | ||
128 | 28 | |||
129 | 29 | class HostLifecycleEventListener | ||
130 | 30 | { | ||
131 | 31 | public: | ||
132 | 32 | virtual void lifecycle_event_occurred(MirLifecycleState state) = 0; | ||
133 | 33 | |||
134 | 34 | protected: | ||
135 | 35 | HostLifecycleEventListener() = default; | ||
136 | 36 | virtual ~HostLifecycleEventListener() = default; | ||
137 | 37 | HostLifecycleEventListener(HostLifecycleEventListener const&) = delete; | ||
138 | 38 | HostLifecycleEventListener& operator=(HostLifecycleEventListener const&) = delete; | ||
139 | 39 | }; | ||
140 | 40 | |||
141 | 41 | } | ||
142 | 42 | } | ||
143 | 43 | |||
144 | 44 | #endif /* MIR_HOST_LIFECYCLE_EVENT_LISTENER_H_ */ | ||
145 | 0 | 45 | ||
146 | === modified file 'src/server/graphics/default_configuration.cpp' | |||
147 | --- src/server/graphics/default_configuration.cpp 2014-07-09 10:48:47 +0000 | |||
148 | +++ src/server/graphics/default_configuration.cpp 2014-07-16 15:59:57 +0000 | |||
149 | @@ -185,7 +185,8 @@ | |||
150 | 185 | 185 | ||
151 | 186 | return std::make_shared<graphics::nested::MirClientHostConnection>( | 186 | return std::make_shared<graphics::nested::MirClientHostConnection>( |
152 | 187 | host_socket, | 187 | host_socket, |
154 | 188 | my_name); | 188 | my_name, |
155 | 189 | the_host_lifecycle_event_listener()); | ||
156 | 189 | }); | 190 | }); |
157 | 190 | } | 191 | } |
158 | 191 | 192 | ||
159 | 192 | 193 | ||
160 | === modified file 'src/server/graphics/nested/mir_client_host_connection.cpp' | |||
161 | --- src/server/graphics/nested/mir_client_host_connection.cpp 2014-04-17 11:04:41 +0000 | |||
162 | +++ src/server/graphics/nested/mir_client_host_connection.cpp 2014-07-16 15:59:57 +0000 | |||
163 | @@ -40,6 +40,12 @@ | |||
164 | 40 | (*static_cast<std::function<void()>*>(context))(); | 40 | (*static_cast<std::function<void()>*>(context))(); |
165 | 41 | } | 41 | } |
166 | 42 | 42 | ||
167 | 43 | static void nested_lifecycle_event_callback_thunk(MirConnection* /*connection*/, MirLifecycleState state, void *context) | ||
168 | 44 | { | ||
169 | 45 | msh::HostLifecycleEventListener* listener = static_cast<msh::HostLifecycleEventListener*>(context); | ||
170 | 46 | listener->lifecycle_event_occurred(state); | ||
171 | 47 | } | ||
172 | 48 | |||
173 | 43 | class MirClientHostSurface : public mgn::HostSurface | 49 | class MirClientHostSurface : public mgn::HostSurface |
174 | 44 | { | 50 | { |
175 | 45 | public: | 51 | public: |
176 | @@ -80,9 +86,12 @@ | |||
177 | 80 | } | 86 | } |
178 | 81 | 87 | ||
179 | 82 | mgn::MirClientHostConnection::MirClientHostConnection( | 88 | mgn::MirClientHostConnection::MirClientHostConnection( |
181 | 83 | std::string const& host_socket, std::string const& name) | 89 | std::string const& host_socket, |
182 | 90 | std::string const& name, | ||
183 | 91 | std::shared_ptr<msh::HostLifecycleEventListener> const& host_lifecycle_event_listener) | ||
184 | 84 | : mir_connection{mir_connect_sync(host_socket.c_str(), name.c_str())}, | 92 | : mir_connection{mir_connect_sync(host_socket.c_str(), name.c_str())}, |
186 | 85 | conf_change_callback{[]{}} | 93 | conf_change_callback{[]{}}, |
187 | 94 | host_lifecycle_event_listener{host_lifecycle_event_listener} | ||
188 | 86 | { | 95 | { |
189 | 87 | if (!mir_connection_is_valid(mir_connection)) | 96 | if (!mir_connection_is_valid(mir_connection)) |
190 | 88 | { | 97 | { |
191 | @@ -92,6 +101,11 @@ | |||
192 | 92 | 101 | ||
193 | 93 | BOOST_THROW_EXCEPTION(std::runtime_error(msg)); | 102 | BOOST_THROW_EXCEPTION(std::runtime_error(msg)); |
194 | 94 | } | 103 | } |
195 | 104 | |||
196 | 105 | mir_connection_set_lifecycle_event_callback( | ||
197 | 106 | mir_connection, | ||
198 | 107 | nested_lifecycle_event_callback_thunk, | ||
199 | 108 | std::static_pointer_cast<void>(host_lifecycle_event_listener).get()); | ||
200 | 95 | } | 109 | } |
201 | 96 | 110 | ||
202 | 97 | mgn::MirClientHostConnection::~MirClientHostConnection() | 111 | mgn::MirClientHostConnection::~MirClientHostConnection() |
203 | 98 | 112 | ||
204 | === modified file 'src/server/graphics/nested/mir_client_host_connection.h' | |||
205 | --- src/server/graphics/nested/mir_client_host_connection.h 2014-04-17 11:04:41 +0000 | |||
206 | +++ src/server/graphics/nested/mir_client_host_connection.h 2014-07-16 15:59:57 +0000 | |||
207 | @@ -20,11 +20,14 @@ | |||
208 | 20 | #define MIR_GRAPHICS_NESTED_MIR_CLIENT_HOST_CONNECTION_H_ | 20 | #define MIR_GRAPHICS_NESTED_MIR_CLIENT_HOST_CONNECTION_H_ |
209 | 21 | 21 | ||
210 | 22 | #include "host_connection.h" | 22 | #include "host_connection.h" |
211 | 23 | #include "mir/shell/host_lifecycle_event_listener.h" | ||
212 | 23 | 24 | ||
213 | 24 | #include <string> | 25 | #include <string> |
214 | 25 | 26 | ||
215 | 26 | struct MirConnection; | 27 | struct MirConnection; |
216 | 27 | 28 | ||
217 | 29 | namespace msh = mir::shell; | ||
218 | 30 | |||
219 | 28 | namespace mir | 31 | namespace mir |
220 | 29 | { | 32 | { |
221 | 30 | namespace graphics | 33 | namespace graphics |
222 | @@ -35,7 +38,7 @@ | |||
223 | 35 | class MirClientHostConnection : public HostConnection | 38 | class MirClientHostConnection : public HostConnection |
224 | 36 | { | 39 | { |
225 | 37 | public: | 40 | public: |
227 | 38 | MirClientHostConnection(std::string const& host_socket, std::string const& name); | 41 | MirClientHostConnection(std::string const& host_socket, std::string const& name, std::shared_ptr<msh::HostLifecycleEventListener> const& host_lifecycle_event_listener); |
228 | 39 | ~MirClientHostConnection(); | 42 | ~MirClientHostConnection(); |
229 | 40 | 43 | ||
230 | 41 | std::vector<int> platform_fd_items() override; | 44 | std::vector<int> platform_fd_items() override; |
231 | @@ -51,6 +54,7 @@ | |||
232 | 51 | private: | 54 | private: |
233 | 52 | MirConnection* const mir_connection; | 55 | MirConnection* const mir_connection; |
234 | 53 | std::function<void()> conf_change_callback; | 56 | std::function<void()> conf_change_callback; |
235 | 57 | std::shared_ptr<msh::HostLifecycleEventListener> const host_lifecycle_event_listener; | ||
236 | 54 | }; | 58 | }; |
237 | 55 | 59 | ||
238 | 56 | } | 60 | } |
239 | 57 | 61 | ||
240 | === modified file 'src/server/shell/default_configuration.cpp' | |||
241 | --- src/server/shell/default_configuration.cpp 2014-04-15 05:31:19 +0000 | |||
242 | +++ src/server/shell/default_configuration.cpp 2014-07-16 15:59:57 +0000 | |||
243 | @@ -17,6 +17,8 @@ | |||
244 | 17 | */ | 17 | */ |
245 | 18 | 18 | ||
246 | 19 | #include "mir/default_server_configuration.h" | 19 | #include "mir/default_server_configuration.h" |
247 | 20 | #include "null_host_lifecycle_event_listener.h" | ||
248 | 21 | |||
249 | 20 | 22 | ||
250 | 21 | #include "consuming_placement_strategy.h" | 23 | #include "consuming_placement_strategy.h" |
251 | 22 | #include "default_focus_mechanism.h" | 24 | #include "default_focus_mechanism.h" |
252 | @@ -58,3 +60,13 @@ | |||
253 | 58 | return std::make_shared<msh::GraphicsDisplayLayout>(the_display()); | 60 | return std::make_shared<msh::GraphicsDisplayLayout>(the_display()); |
254 | 59 | }); | 61 | }); |
255 | 60 | } | 62 | } |
256 | 63 | |||
257 | 64 | std::shared_ptr<msh::HostLifecycleEventListener> | ||
258 | 65 | mir::DefaultServerConfiguration::the_host_lifecycle_event_listener() | ||
259 | 66 | { | ||
260 | 67 | return host_lifecycle_event_listener( | ||
261 | 68 | []() | ||
262 | 69 | { | ||
263 | 70 | return std::make_shared<msh::NullHostLifecycleEventListener>(); | ||
264 | 71 | }); | ||
265 | 72 | } | ||
266 | 61 | 73 | ||
267 | === added file 'src/server/shell/null_host_lifecycle_event_listener.h' | |||
268 | --- src/server/shell/null_host_lifecycle_event_listener.h 1970-01-01 00:00:00 +0000 | |||
269 | +++ src/server/shell/null_host_lifecycle_event_listener.h 2014-07-16 15:59:57 +0000 | |||
270 | @@ -0,0 +1,38 @@ | |||
271 | 1 | /* | ||
272 | 2 | * Copyright © 2014 Canonical Ltd. | ||
273 | 3 | * | ||
274 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
275 | 5 | * under the terms of the GNU General Public License version 3, | ||
276 | 6 | * as published by the Free Software Foundation. | ||
277 | 7 | * | ||
278 | 8 | * This program is distributed in the hope that it will be useful, | ||
279 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
280 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
281 | 11 | * GNU General Public License for more details. | ||
282 | 12 | * | ||
283 | 13 | * You should have received a copy of the GNU General Public License | ||
284 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
285 | 15 | * | ||
286 | 16 | * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com> | ||
287 | 17 | */ | ||
288 | 18 | |||
289 | 19 | #ifndef MIR_NULL_HOST_LIFECYCLE_EVENT_LISTENER_H_ | ||
290 | 20 | #define MIR_NULL_HOST_LIFECYCLE_EVENT_LISTENER_H_ | ||
291 | 21 | |||
292 | 22 | #include "mir/shell/host_lifecycle_event_listener.h" | ||
293 | 23 | |||
294 | 24 | namespace mir | ||
295 | 25 | { | ||
296 | 26 | namespace shell | ||
297 | 27 | { | ||
298 | 28 | |||
299 | 29 | class NullHostLifecycleEventListener : public HostLifecycleEventListener | ||
300 | 30 | { | ||
301 | 31 | public: | ||
302 | 32 | virtual void lifecycle_event_occurred(MirLifecycleState /*state*/) override {} | ||
303 | 33 | }; | ||
304 | 34 | |||
305 | 35 | } | ||
306 | 36 | } | ||
307 | 37 | |||
308 | 38 | #endif /* MIR_NULL_HOST_LIFECYCLE_EVENT_LISTENER_H_ */ | ||
309 | 0 | 39 | ||
310 | === modified file 'tests/acceptance-tests/test_nested_mir.cpp' | |||
311 | --- tests/acceptance-tests/test_nested_mir.cpp 2014-07-09 17:04:55 +0000 | |||
312 | +++ tests/acceptance-tests/test_nested_mir.cpp 2014-07-16 15:59:57 +0000 | |||
313 | @@ -22,6 +22,9 @@ | |||
314 | 22 | #include "mir/graphics/display_configuration.h" | 22 | #include "mir/graphics/display_configuration.h" |
315 | 23 | #include "mir/display_server.h" | 23 | #include "mir/display_server.h" |
316 | 24 | #include "mir/run_mir.h" | 24 | #include "mir/run_mir.h" |
317 | 25 | #include "mir/shell/focus_controller.h" | ||
318 | 26 | #include "mir/scene/session.h" | ||
319 | 27 | #include "mir/shell/host_lifecycle_event_listener.h" | ||
320 | 25 | 28 | ||
321 | 26 | #include "mir_test_framework/in_process_server.h" | 29 | #include "mir_test_framework/in_process_server.h" |
322 | 27 | #include "mir_test_framework/stubbed_server_configuration.h" | 30 | #include "mir_test_framework/stubbed_server_configuration.h" |
323 | @@ -39,6 +42,7 @@ | |||
324 | 39 | namespace mf = mir::frontend; | 42 | namespace mf = mir::frontend; |
325 | 40 | namespace mg = mir::graphics; | 43 | namespace mg = mir::graphics; |
326 | 41 | namespace mtf = mir_test_framework; | 44 | namespace mtf = mir_test_framework; |
327 | 45 | namespace msh = mir::shell; | ||
328 | 42 | using namespace testing; | 46 | using namespace testing; |
329 | 43 | 47 | ||
330 | 44 | namespace | 48 | namespace |
331 | @@ -137,6 +141,19 @@ | |||
332 | 137 | std::shared_ptr<mg::Platform> const adaptee; | 141 | std::shared_ptr<mg::Platform> const adaptee; |
333 | 138 | }; | 142 | }; |
334 | 139 | 143 | ||
335 | 144 | struct MockHostLifecycleEventListener : msh::HostLifecycleEventListener | ||
336 | 145 | { | ||
337 | 146 | MockHostLifecycleEventListener( | ||
338 | 147 | std::shared_ptr<msh::HostLifecycleEventListener> const& wrapped) : | ||
339 | 148 | wrapped(wrapped) | ||
340 | 149 | { | ||
341 | 150 | } | ||
342 | 151 | |||
343 | 152 | MOCK_METHOD1(lifecycle_event_occurred, void (MirLifecycleState)); | ||
344 | 153 | |||
345 | 154 | std::shared_ptr<msh::HostLifecycleEventListener> const wrapped; | ||
346 | 155 | }; | ||
347 | 156 | |||
348 | 140 | struct NestedServerConfiguration : FakeCommandLine, public mir::DefaultServerConfiguration | 157 | struct NestedServerConfiguration : FakeCommandLine, public mir::DefaultServerConfiguration |
349 | 141 | { | 158 | { |
350 | 142 | NestedServerConfiguration( | 159 | NestedServerConfiguration( |
351 | @@ -262,6 +279,18 @@ | |||
352 | 262 | connection_string = new_connection(); | 279 | connection_string = new_connection(); |
353 | 263 | } | 280 | } |
354 | 264 | 281 | ||
355 | 282 | void trigger_lifecycle_event(MirLifecycleState const lifecycle_state) | ||
356 | 283 | { | ||
357 | 284 | auto const app = the_focus_controller()->focussed_application().lock(); | ||
358 | 285 | |||
359 | 286 | EXPECT_TRUE(app != nullptr) << "Nested server not connected"; | ||
360 | 287 | |||
361 | 288 | if (app) | ||
362 | 289 | { | ||
363 | 290 | app->set_lifecycle_state(lifecycle_state); | ||
364 | 291 | } | ||
365 | 292 | } | ||
366 | 293 | |||
367 | 265 | std::string connection_string; | 294 | std::string connection_string; |
368 | 266 | }; | 295 | }; |
369 | 267 | } | 296 | } |
370 | @@ -323,3 +352,44 @@ | |||
371 | 323 | 352 | ||
372 | 324 | EXPECT_FALSE(config.my_display.lock()) << "after run_mir() exits the display should be released"; | 353 | EXPECT_FALSE(config.my_display.lock()) << "after run_mir() exits the display should be released"; |
373 | 325 | } | 354 | } |
374 | 355 | |||
375 | 356 | TEST_F(NestedServer, receives_lifecycle_events_from_host) | ||
376 | 357 | { | ||
377 | 358 | struct MyServerConfiguration : NestedServerConfiguration | ||
378 | 359 | { | ||
379 | 360 | using NestedServerConfiguration::NestedServerConfiguration; | ||
380 | 361 | |||
381 | 362 | std::shared_ptr<msh::HostLifecycleEventListener> the_host_lifecycle_event_listener() override | ||
382 | 363 | { | ||
383 | 364 | return host_lifecycle_event_listener([this]() | ||
384 | 365 | -> std::shared_ptr<msh::HostLifecycleEventListener> | ||
385 | 366 | { | ||
386 | 367 | return the_mock_host_lifecycle_event_listener(); | ||
387 | 368 | }); | ||
388 | 369 | } | ||
389 | 370 | |||
390 | 371 | std::shared_ptr<MockHostLifecycleEventListener> the_mock_host_lifecycle_event_listener() | ||
391 | 372 | { | ||
392 | 373 | return mock_host_lifecycle_event_listener([this] | ||
393 | 374 | { | ||
394 | 375 | return std::make_shared<MockHostLifecycleEventListener>( | ||
395 | 376 | NestedServerConfiguration::the_host_lifecycle_event_listener()); | ||
396 | 377 | }); | ||
397 | 378 | } | ||
398 | 379 | |||
399 | 380 | mir::CachedPtr<MockHostLifecycleEventListener> mock_host_lifecycle_event_listener; | ||
400 | 381 | }; | ||
401 | 382 | |||
402 | 383 | MyServerConfiguration nested_config{connection_string, the_graphics_platform()}; | ||
403 | 384 | |||
404 | 385 | NestedMirRunner nested_mir{nested_config}; | ||
405 | 386 | |||
406 | 387 | InSequence seq; | ||
407 | 388 | EXPECT_CALL(*(nested_config.the_mock_host_lifecycle_event_listener()), | ||
408 | 389 | lifecycle_event_occurred(mir_lifecycle_state_resumed)).Times(1); | ||
409 | 390 | EXPECT_CALL(*(nested_config.the_mock_host_lifecycle_event_listener()), | ||
410 | 391 | lifecycle_event_occurred(mir_lifecycle_state_will_suspend)).Times(1); | ||
411 | 392 | |||
412 | 393 | trigger_lifecycle_event(mir_lifecycle_state_resumed); | ||
413 | 394 | trigger_lifecycle_event(mir_lifecycle_state_will_suspend); | ||
414 | 395 | } |
Since the nested tests don't work, I modified the demo_shell to test this MP.
https:/ /code.launchpad .net/~cemil- azizoglu/ mir/nested_ lifecycle_ events_ test/+merge/ 224434
The test code needs some private headers exposed in the demo shell, and is not meant to be merged (thus, is marked as "disapprove").