Merge lp:~alan-griffiths/mir/spike-exposing-rpc-in-frontend into lp:mir
- spike-exposing-rpc-in-frontend
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Alan Griffiths |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1344 |
Proposed branch: | lp:~alan-griffiths/mir/spike-exposing-rpc-in-frontend |
Merge into: | lp:mir |
Diff against target: |
918 lines (+355/-180) 20 files modified
include/server/mir/default_server_configuration.h (+3/-4) include/server/mir/frontend/message_processor.h (+10/-11) include/server/mir/frontend/protobuf_session_creator.h (+9/-1) include/server/mir/frontend/template_protobuf_message_processor.h (+15/-36) src/server/frontend/CMakeLists.txt (+0/-2) src/server/frontend/default_configuration.cpp (+1/-1) src/server/frontend/null_message_processor.cpp (+0/-26) src/server/frontend/protobuf_message_processor.cpp (+8/-2) src/server/frontend/protobuf_message_processor.h (+6/-3) src/server/frontend/protobuf_session_creator.cpp (+14/-2) src/server/frontend/published_socket_connector.cpp (+1/-1) src/server/frontend/socket_session.cpp (+9/-2) src/server/frontend/socket_session.h (+1/-1) src/server/frontend/template_protobuf_message_processor.cpp (+0/-44) src/shared/protobuf/mir_protobuf_wire.proto (+1/-1) tests/acceptance-tests/test_protobuf.cpp (+216/-7) tests/acceptance-tests/test_protobuf.proto (+1/-0) tests/mir_test_doubles/test_protobuf_socket_server.cpp (+1/-1) tests/unit-tests/frontend/test_published_socket_connector.cpp (+1/-1) tests/unit-tests/frontend/test_socket_session.cpp (+58/-34) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/spike-exposing-rpc-in-frontend |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandros Frantzis (community) | Approve | ||
Kevin DuBois (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+202351@code.launchpad.net |
Commit message
frontend: exposing internals of the RPC mechanism to enable custom function calls to be added.
Description of the change
frontend: exposing internals of the RPC mechanism to enable custom function calls to be added. (As illustrated by DemoPrivateProt
PS Jenkins bot (ps-jenkins) wrote : | # |
Alexandros Frantzis (afrantzis) wrote : | # |
I like the new version better.
Looks OK, besides some stray tabs:
272 + sender(sender),
819 + std::function<
820 + boost::
821 + size_t size)
822 + {
823 + read_size = size;
824 + pstream = &stream;
825 + callback_function = callback;831
831 + ASSERT_
839 + callback_
866 + int const header_size = 2;
Alan Griffiths (alan-griffiths) wrote : | # |
> I like the new version better.
>
> Looks OK, besides some stray tabs:
>
Weird, I've checked that the editor is set to insert spaces, but tabs appear in the text.
Fixed anyway.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1347
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1350
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1354
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://
Kevin DuBois (kdub) wrote : | # |
nit:
l913, 914, 867 seem like bit magic numbers.
other than that, looks okay though
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good.
Preview Diff
1 | === modified file 'include/server/mir/default_server_configuration.h' | |||
2 | --- include/server/mir/default_server_configuration.h 2014-01-13 06:12:33 +0000 | |||
3 | +++ include/server/mir/default_server_configuration.h 2014-01-21 15:42:35 +0000 | |||
4 | @@ -239,6 +239,9 @@ | |||
5 | 239 | 239 | ||
6 | 240 | virtual std::shared_ptr<input::InputChannelFactory> the_input_channel_factory(); | 240 | virtual std::shared_ptr<input::InputChannelFactory> the_input_channel_factory(); |
7 | 241 | virtual std::shared_ptr<scene::MediatingDisplayChanger> the_mediating_display_changer(); | 241 | virtual std::shared_ptr<scene::MediatingDisplayChanger> the_mediating_display_changer(); |
8 | 242 | virtual std::shared_ptr<frontend::ProtobufIpcFactory> the_ipc_factory( | ||
9 | 243 | std::shared_ptr<frontend::Shell> const& shell, | ||
10 | 244 | std::shared_ptr<graphics::GraphicBufferAllocator> const& allocator); | ||
11 | 242 | 245 | ||
12 | 243 | CachedPtr<frontend::Connector> connector; | 246 | CachedPtr<frontend::Connector> connector; |
13 | 244 | 247 | ||
14 | @@ -292,10 +295,6 @@ | |||
15 | 292 | 295 | ||
16 | 293 | private: | 296 | private: |
17 | 294 | std::shared_ptr<input::EventFilter> const default_filter; | 297 | std::shared_ptr<input::EventFilter> const default_filter; |
18 | 295 | // the communications interface to use | ||
19 | 296 | virtual std::shared_ptr<frontend::ProtobufIpcFactory> the_ipc_factory( | ||
20 | 297 | std::shared_ptr<frontend::Shell> const& shell, | ||
21 | 298 | std::shared_ptr<graphics::GraphicBufferAllocator> const& allocator); | ||
22 | 299 | 298 | ||
23 | 300 | virtual std::string the_socket_file() const; | 299 | virtual std::string the_socket_file() const; |
24 | 301 | 300 | ||
25 | 302 | 301 | ||
26 | === renamed file 'src/server/frontend/connected_sessions.h' => 'include/server/mir/frontend/connected_sessions.h' | |||
27 | === modified file 'include/server/mir/frontend/message_processor.h' | |||
28 | --- include/server/mir/frontend/message_processor.h 2014-01-16 14:39:11 +0000 | |||
29 | +++ include/server/mir/frontend/message_processor.h 2014-01-21 15:42:35 +0000 | |||
30 | @@ -1,5 +1,5 @@ | |||
31 | 1 | /* | 1 | /* |
33 | 2 | * Copyright © 2012 Canonical Ltd. | 2 | * Copyright © 2012, 2014 Canonical Ltd. |
34 | 3 | * | 3 | * |
35 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
36 | 5 | * under the terms of the GNU General Public License version 3, | 5 | * under the terms of the GNU General Public License version 3, |
37 | @@ -19,10 +19,15 @@ | |||
38 | 19 | #ifndef MIR_FRONTEND_MESSAGE_PROCESSOR_H_ | 19 | #ifndef MIR_FRONTEND_MESSAGE_PROCESSOR_H_ |
39 | 20 | #define MIR_FRONTEND_MESSAGE_PROCESSOR_H_ | 20 | #define MIR_FRONTEND_MESSAGE_PROCESSOR_H_ |
40 | 21 | 21 | ||
41 | 22 | #include <iosfwd> | ||
42 | 23 | |||
43 | 24 | namespace mir | 22 | namespace mir |
44 | 25 | { | 23 | { |
45 | 24 | namespace protobuf | ||
46 | 25 | { | ||
47 | 26 | namespace wire | ||
48 | 27 | { | ||
49 | 28 | class Invocation; | ||
50 | 29 | } | ||
51 | 30 | } | ||
52 | 26 | namespace frontend | 31 | namespace frontend |
53 | 27 | { | 32 | { |
54 | 28 | namespace detail | 33 | namespace detail |
55 | @@ -31,20 +36,14 @@ | |||
56 | 31 | class MessageProcessor | 36 | class MessageProcessor |
57 | 32 | { | 37 | { |
58 | 33 | public: | 38 | public: |
60 | 34 | virtual bool process_message(std::istream& msg) = 0; | 39 | virtual bool dispatch(mir::protobuf::wire::Invocation const& invocation) = 0; |
61 | 40 | |||
62 | 35 | protected: | 41 | protected: |
63 | 36 | MessageProcessor() = default; | 42 | MessageProcessor() = default; |
64 | 37 | virtual ~MessageProcessor() = default; | 43 | virtual ~MessageProcessor() = default; |
65 | 38 | MessageProcessor(MessageProcessor const&) = delete; | 44 | MessageProcessor(MessageProcessor const&) = delete; |
66 | 39 | MessageProcessor& operator=(MessageProcessor const&) = delete; | 45 | MessageProcessor& operator=(MessageProcessor const&) = delete; |
67 | 40 | }; | 46 | }; |
68 | 41 | |||
69 | 42 | class NullMessageProcessor : MessageProcessor | ||
70 | 43 | { | ||
71 | 44 | public: | ||
72 | 45 | bool process_message(std::istream&); | ||
73 | 46 | }; | ||
74 | 47 | |||
75 | 48 | } | 47 | } |
76 | 49 | } | 48 | } |
77 | 50 | } | 49 | } |
78 | 51 | 50 | ||
79 | === renamed file 'src/server/frontend/protobuf_session_creator.h' => 'include/server/mir/frontend/protobuf_session_creator.h' | |||
80 | --- src/server/frontend/protobuf_session_creator.h 2014-01-15 12:26:01 +0000 | |||
81 | +++ include/server/mir/frontend/protobuf_session_creator.h 2014-01-21 15:42:35 +0000 | |||
82 | @@ -20,12 +20,13 @@ | |||
83 | 20 | #define MIR_FRONTEND_PROTOBUF_SESSION_CREATOR_H_ | 20 | #define MIR_FRONTEND_PROTOBUF_SESSION_CREATOR_H_ |
84 | 21 | 21 | ||
85 | 22 | #include "mir/frontend/session_creator.h" | 22 | #include "mir/frontend/session_creator.h" |
87 | 23 | #include "connected_sessions.h" | 23 | #include "mir/frontend/connected_sessions.h" |
88 | 24 | 24 | ||
89 | 25 | #include <atomic> | 25 | #include <atomic> |
90 | 26 | 26 | ||
91 | 27 | namespace mir | 27 | namespace mir |
92 | 28 | { | 28 | { |
93 | 29 | namespace protobuf { class DisplayServer; } | ||
94 | 29 | namespace frontend | 30 | namespace frontend |
95 | 30 | { | 31 | { |
96 | 31 | class MessageProcessorReport; | 32 | class MessageProcessorReport; |
97 | @@ -35,6 +36,8 @@ | |||
98 | 35 | namespace detail | 36 | namespace detail |
99 | 36 | { | 37 | { |
100 | 37 | struct SocketSession; | 38 | struct SocketSession; |
101 | 39 | class MessageProcessor; | ||
102 | 40 | class ProtobufMessageSender; | ||
103 | 38 | } | 41 | } |
104 | 39 | 42 | ||
105 | 40 | class ProtobufSessionCreator : public SessionCreator | 43 | class ProtobufSessionCreator : public SessionCreator |
106 | @@ -48,6 +51,11 @@ | |||
107 | 48 | 51 | ||
108 | 49 | void create_session_for(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket); | 52 | void create_session_for(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket); |
109 | 50 | 53 | ||
110 | 54 | virtual std::shared_ptr<detail::MessageProcessor> create_processor( | ||
111 | 55 | std::shared_ptr<detail::ProtobufMessageSender> const& sender, | ||
112 | 56 | std::shared_ptr<protobuf::DisplayServer> const& display_server, | ||
113 | 57 | std::shared_ptr<MessageProcessorReport> const& report) const; | ||
114 | 58 | |||
115 | 51 | private: | 59 | private: |
116 | 52 | int next_id(); | 60 | int next_id(); |
117 | 53 | 61 | ||
118 | 54 | 62 | ||
119 | === modified file 'include/server/mir/frontend/template_protobuf_message_processor.h' | |||
120 | --- include/server/mir/frontend/template_protobuf_message_processor.h 2014-01-17 10:55:55 +0000 | |||
121 | +++ include/server/mir/frontend/template_protobuf_message_processor.h 2014-01-21 15:42:35 +0000 | |||
122 | @@ -36,40 +36,15 @@ | |||
123 | 36 | { | 36 | { |
124 | 37 | namespace detail | 37 | namespace detail |
125 | 38 | { | 38 | { |
157 | 39 | class ProtobufMessageSender; | 39 | // Utility metafunction result_ptr_t<> allows invoke() to pick the right |
158 | 40 | 40 | // send_response() overload. The base template resolves to the prototype | |
159 | 41 | // This class is intended to make implementation of a protobuf based MessageProcessor simpler. | 41 | // "send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response)" |
160 | 42 | // The template method process_message() calls dispatch after unpacking the received "invocation" | 42 | // Client code may specialize result_ptr_t to resolve to another overload. |
161 | 43 | // message. The related invoke<>() template handles further unpacking of the parameter | 43 | template<typename ResultType> struct result_ptr_t |
162 | 44 | // message and packing of the response and calls send_response. | 44 | { typedef ::google::protobuf::Message* type; }; |
132 | 45 | // Derived classes can overload send_response, but need to specialize result_ptr_t before instantiating | ||
133 | 46 | // invoke<>() to ensure the correct overload is called. | ||
134 | 47 | class TemplateProtobufMessageProcessor : public MessageProcessor | ||
135 | 48 | { | ||
136 | 49 | public: | ||
137 | 50 | TemplateProtobufMessageProcessor( | ||
138 | 51 | std::shared_ptr<ProtobufMessageSender> const& sender); | ||
139 | 52 | |||
140 | 53 | ~TemplateProtobufMessageProcessor() noexcept {} | ||
141 | 54 | |||
142 | 55 | void send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response); | ||
143 | 56 | |||
144 | 57 | std::shared_ptr<ProtobufMessageSender> const sender; | ||
145 | 58 | |||
146 | 59 | private: | ||
147 | 60 | virtual bool dispatch(mir::protobuf::wire::Invocation const& invocation) = 0; | ||
148 | 61 | |||
149 | 62 | bool process_message(std::istream& msg) override final; | ||
150 | 63 | }; | ||
151 | 64 | |||
152 | 65 | // Utility function result_ptr() allows invoke() to pick the right send_response() overload | ||
153 | 66 | // Client code may specialize result_ptr_t to get an overload of send_response called. | ||
154 | 67 | template<typename ResultType> struct result_ptr_t { typedef ::google::protobuf::Message* type; }; | ||
155 | 68 | template<typename ResultType> inline | ||
156 | 69 | auto result_ptr(ResultType& result) -> typename result_ptr_t<ResultType>::type { return &result; } | ||
163 | 70 | 45 | ||
164 | 71 | // Boiler plate for unpacking a parameter message, invoking a server function, and | 46 | // Boiler plate for unpacking a parameter message, invoking a server function, and |
166 | 72 | // sending the result message. | 47 | // sending the result message. Assumes the existence of Self::send_response(). |
167 | 73 | template<class Self, class Server, class ParameterMessage, class ResultMessage> | 48 | template<class Self, class Server, class ParameterMessage, class ResultMessage> |
168 | 74 | void invoke( | 49 | void invoke( |
169 | 75 | Self* self, | 50 | Self* self, |
170 | @@ -88,10 +63,14 @@ | |||
171 | 88 | try | 63 | try |
172 | 89 | { | 64 | { |
173 | 90 | std::unique_ptr<google::protobuf::Closure> callback( | 65 | std::unique_ptr<google::protobuf::Closure> callback( |
178 | 91 | google::protobuf::NewPermanentCallback(self, | 66 | google::protobuf::NewPermanentCallback< |
179 | 92 | &Self::send_response, | 67 | Self, |
180 | 93 | invocation.id(), | 68 | ::google::protobuf::uint32, |
181 | 94 | result_ptr(result_message))); | 69 | typename result_ptr_t<ResultMessage>::type>( |
182 | 70 | self, | ||
183 | 71 | &Self::send_response, | ||
184 | 72 | invocation.id(), | ||
185 | 73 | &result_message)); | ||
186 | 95 | 74 | ||
187 | 96 | (server->*function)( | 75 | (server->*function)( |
188 | 97 | 0, | 76 | 0, |
189 | 98 | 77 | ||
190 | === modified file 'src/server/frontend/CMakeLists.txt' | |||
191 | --- src/server/frontend/CMakeLists.txt 2014-01-20 07:11:48 +0000 | |||
192 | +++ src/server/frontend/CMakeLists.txt 2014-01-21 15:42:35 +0000 | |||
193 | @@ -8,11 +8,9 @@ | |||
194 | 8 | protobuf_message_processor.cpp | 8 | protobuf_message_processor.cpp |
195 | 9 | protobuf_responder.cpp | 9 | protobuf_responder.cpp |
196 | 10 | protobuf_buffer_packer.cpp | 10 | protobuf_buffer_packer.cpp |
197 | 11 | null_message_processor.cpp | ||
198 | 12 | published_socket_connector.cpp | 11 | published_socket_connector.cpp |
199 | 13 | protobuf_session_creator.cpp | 12 | protobuf_session_creator.cpp |
200 | 14 | socket_session.cpp | 13 | socket_session.cpp |
201 | 15 | template_protobuf_message_processor.cpp | ||
202 | 16 | resource_cache.cpp | 14 | resource_cache.cpp |
203 | 17 | socket_messenger.cpp | 15 | socket_messenger.cpp |
204 | 18 | event_sender.cpp | 16 | event_sender.cpp |
205 | 19 | 17 | ||
206 | === modified file 'src/server/frontend/default_configuration.cpp' | |||
207 | --- src/server/frontend/default_configuration.cpp 2014-01-20 07:11:48 +0000 | |||
208 | +++ src/server/frontend/default_configuration.cpp 2014-01-21 15:42:35 +0000 | |||
209 | @@ -17,10 +17,10 @@ | |||
210 | 17 | */ | 17 | */ |
211 | 18 | 18 | ||
212 | 19 | #include "mir/default_server_configuration.h" | 19 | #include "mir/default_server_configuration.h" |
213 | 20 | #include "mir/frontend/protobuf_session_creator.h" | ||
214 | 20 | 21 | ||
215 | 21 | #include "resource_cache.h" | 22 | #include "resource_cache.h" |
216 | 22 | #include "protobuf_ipc_factory.h" | 23 | #include "protobuf_ipc_factory.h" |
217 | 23 | #include "protobuf_session_creator.h" | ||
218 | 24 | #include "published_socket_connector.h" | 24 | #include "published_socket_connector.h" |
219 | 25 | #include "session_mediator.h" | 25 | #include "session_mediator.h" |
220 | 26 | #include "unauthorized_display_changer.h" | 26 | #include "unauthorized_display_changer.h" |
221 | 27 | 27 | ||
222 | === removed file 'src/server/frontend/null_message_processor.cpp' | |||
223 | --- src/server/frontend/null_message_processor.cpp 2014-01-16 14:39:11 +0000 | |||
224 | +++ src/server/frontend/null_message_processor.cpp 1970-01-01 00:00:00 +0000 | |||
225 | @@ -1,26 +0,0 @@ | |||
226 | 1 | /* | ||
227 | 2 | * Copyright © 2012 Canonical Ltd. | ||
228 | 3 | * | ||
229 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
230 | 5 | * under the terms of the GNU General Public License version 3, | ||
231 | 6 | * as published by the Free Software Foundation. | ||
232 | 7 | * | ||
233 | 8 | * This program is distributed in the hope that it will be useful, | ||
234 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
235 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
236 | 11 | * GNU General Public License for more details. | ||
237 | 12 | * | ||
238 | 13 | * You should have received a copy of the GNU General Public License | ||
239 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
240 | 15 | * | ||
241 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
242 | 17 | */ | ||
243 | 18 | |||
244 | 19 | #include "mir/frontend/message_processor.h" | ||
245 | 20 | |||
246 | 21 | namespace mfd = mir::frontend::detail; | ||
247 | 22 | |||
248 | 23 | bool mfd::NullMessageProcessor::process_message(std::istream& ) | ||
249 | 24 | { | ||
250 | 25 | return false; | ||
251 | 26 | } | ||
252 | 27 | 0 | ||
253 | === modified file 'src/server/frontend/protobuf_message_processor.cpp' | |||
254 | --- src/server/frontend/protobuf_message_processor.cpp 2014-01-20 07:11:48 +0000 | |||
255 | +++ src/server/frontend/protobuf_message_processor.cpp 2014-01-21 15:42:35 +0000 | |||
256 | @@ -17,8 +17,9 @@ | |||
257 | 17 | */ | 17 | */ |
258 | 18 | 18 | ||
259 | 19 | #include "protobuf_message_processor.h" | 19 | #include "protobuf_message_processor.h" |
260 | 20 | #include "mir/frontend/message_processor_report.h" | ||
261 | 20 | #include "mir/frontend/protobuf_message_sender.h" | 21 | #include "mir/frontend/protobuf_message_sender.h" |
263 | 21 | #include "mir/frontend/message_processor_report.h" | 22 | #include "mir/frontend/template_protobuf_message_processor.h" |
264 | 22 | 23 | ||
265 | 23 | namespace mfd = mir::frontend::detail; | 24 | namespace mfd = mir::frontend::detail; |
266 | 24 | 25 | ||
267 | @@ -38,7 +39,7 @@ | |||
268 | 38 | std::shared_ptr<ProtobufMessageSender> const& sender, | 39 | std::shared_ptr<ProtobufMessageSender> const& sender, |
269 | 39 | std::shared_ptr<protobuf::DisplayServer> const& display_server, | 40 | std::shared_ptr<protobuf::DisplayServer> const& display_server, |
270 | 40 | std::shared_ptr<MessageProcessorReport> const& report) : | 41 | std::shared_ptr<MessageProcessorReport> const& report) : |
272 | 41 | TemplateProtobufMessageProcessor(sender), | 42 | sender(sender), |
273 | 42 | display_server(display_server), | 43 | display_server(display_server), |
274 | 43 | report(report) | 44 | report(report) |
275 | 44 | { | 45 | { |
276 | @@ -121,6 +122,11 @@ | |||
277 | 121 | return result; | 122 | return result; |
278 | 122 | } | 123 | } |
279 | 123 | 124 | ||
280 | 125 | void mfd::ProtobufMessageProcessor::send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response) | ||
281 | 126 | { | ||
282 | 127 | sender->send_response(id, response, {}); | ||
283 | 128 | } | ||
284 | 129 | |||
285 | 124 | void mfd::ProtobufMessageProcessor::send_response(::google::protobuf::uint32 id, mir::protobuf::Buffer* response) | 130 | void mfd::ProtobufMessageProcessor::send_response(::google::protobuf::uint32 id, mir::protobuf::Buffer* response) |
286 | 125 | { | 131 | { |
287 | 126 | const auto& fd = extract_fds_from(response); | 132 | const auto& fd = extract_fds_from(response); |
288 | 127 | 133 | ||
289 | === modified file 'src/server/frontend/protobuf_message_processor.h' | |||
290 | --- src/server/frontend/protobuf_message_processor.h 2014-01-20 07:11:48 +0000 | |||
291 | +++ src/server/frontend/protobuf_message_processor.h 2014-01-21 15:42:35 +0000 | |||
292 | @@ -20,7 +20,7 @@ | |||
293 | 20 | #ifndef MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_ | 20 | #ifndef MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_ |
294 | 21 | #define MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_ | 21 | #define MIR_FRONTEND_PROTOBUF_MESSAGE_PROCESSOR_H_ |
295 | 22 | 22 | ||
297 | 23 | #include "mir/frontend/template_protobuf_message_processor.h" | 23 | #include "mir/frontend/message_processor.h" |
298 | 24 | 24 | ||
299 | 25 | #include "mir_protobuf.pb.h" | 25 | #include "mir_protobuf.pb.h" |
300 | 26 | 26 | ||
301 | @@ -36,7 +36,9 @@ | |||
302 | 36 | 36 | ||
303 | 37 | namespace detail | 37 | namespace detail |
304 | 38 | { | 38 | { |
306 | 39 | class ProtobufMessageProcessor : public TemplateProtobufMessageProcessor | 39 | class ProtobufMessageSender; |
307 | 40 | |||
308 | 41 | class ProtobufMessageProcessor : public MessageProcessor | ||
309 | 40 | { | 42 | { |
310 | 41 | public: | 43 | public: |
311 | 42 | ProtobufMessageProcessor( | 44 | ProtobufMessageProcessor( |
312 | @@ -46,7 +48,7 @@ | |||
313 | 46 | 48 | ||
314 | 47 | ~ProtobufMessageProcessor() noexcept {} | 49 | ~ProtobufMessageProcessor() noexcept {} |
315 | 48 | 50 | ||
317 | 49 | using TemplateProtobufMessageProcessor::send_response; | 51 | void send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response); |
318 | 50 | void send_response(::google::protobuf::uint32 id, protobuf::Buffer* response); | 52 | void send_response(::google::protobuf::uint32 id, protobuf::Buffer* response); |
319 | 51 | void send_response(::google::protobuf::uint32 id, protobuf::Connection* response); | 53 | void send_response(::google::protobuf::uint32 id, protobuf::Connection* response); |
320 | 52 | void send_response(::google::protobuf::uint32 id, protobuf::Surface* response); | 54 | void send_response(::google::protobuf::uint32 id, protobuf::Surface* response); |
321 | @@ -54,6 +56,7 @@ | |||
322 | 54 | private: | 56 | private: |
323 | 55 | bool dispatch(mir::protobuf::wire::Invocation const& invocation); | 57 | bool dispatch(mir::protobuf::wire::Invocation const& invocation); |
324 | 56 | 58 | ||
325 | 59 | std::shared_ptr<ProtobufMessageSender> const sender; | ||
326 | 57 | std::shared_ptr<protobuf::DisplayServer> const display_server; | 60 | std::shared_ptr<protobuf::DisplayServer> const display_server; |
327 | 58 | std::shared_ptr<MessageProcessorReport> const report; | 61 | std::shared_ptr<MessageProcessorReport> const report; |
328 | 59 | }; | 62 | }; |
329 | 60 | 63 | ||
330 | === modified file 'src/server/frontend/protobuf_session_creator.cpp' | |||
331 | --- src/server/frontend/protobuf_session_creator.cpp 2014-01-20 07:11:48 +0000 | |||
332 | +++ src/server/frontend/protobuf_session_creator.cpp 2014-01-21 15:42:35 +0000 | |||
333 | @@ -16,7 +16,7 @@ | |||
334 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> |
335 | 17 | */ | 17 | */ |
336 | 18 | 18 | ||
338 | 19 | #include "protobuf_session_creator.h" | 19 | #include "mir/frontend/protobuf_session_creator.h" |
339 | 20 | 20 | ||
340 | 21 | #include "event_sender.h" | 21 | #include "event_sender.h" |
341 | 22 | #include "protobuf_message_processor.h" | 22 | #include "protobuf_message_processor.h" |
342 | @@ -67,7 +67,7 @@ | |||
343 | 67 | ipc_factory->resource_cache()); | 67 | ipc_factory->resource_cache()); |
344 | 68 | 68 | ||
345 | 69 | auto const event_sink = std::make_shared<detail::EventSender>(messenger); | 69 | auto const event_sink = std::make_shared<detail::EventSender>(messenger); |
347 | 70 | auto const msg_processor = std::make_shared<detail::ProtobufMessageProcessor>( | 70 | auto const msg_processor = create_processor( |
348 | 71 | message_sender, | 71 | message_sender, |
349 | 72 | ipc_factory->make_ipc_server(event_sink, authorized_to_resize_display), | 72 | ipc_factory->make_ipc_server(event_sink, authorized_to_resize_display), |
350 | 73 | report); | 73 | report); |
351 | @@ -77,3 +77,15 @@ | |||
352 | 77 | session->read_next_message(); | 77 | session->read_next_message(); |
353 | 78 | } | 78 | } |
354 | 79 | } | 79 | } |
355 | 80 | |||
356 | 81 | std::shared_ptr<mfd::MessageProcessor> | ||
357 | 82 | mf::ProtobufSessionCreator::create_processor( | ||
358 | 83 | std::shared_ptr<mfd::ProtobufMessageSender> const& sender, | ||
359 | 84 | std::shared_ptr<protobuf::DisplayServer> const& display_server, | ||
360 | 85 | std::shared_ptr<mf::MessageProcessorReport> const& report) const | ||
361 | 86 | { | ||
362 | 87 | return std::make_shared<detail::ProtobufMessageProcessor>( | ||
363 | 88 | sender, | ||
364 | 89 | display_server, | ||
365 | 90 | report); | ||
366 | 91 | } | ||
367 | 80 | 92 | ||
368 | === modified file 'src/server/frontend/published_socket_connector.cpp' | |||
369 | --- src/server/frontend/published_socket_connector.cpp 2014-01-13 06:12:33 +0000 | |||
370 | +++ src/server/frontend/published_socket_connector.cpp 2014-01-21 15:42:35 +0000 | |||
371 | @@ -17,7 +17,7 @@ | |||
372 | 17 | */ | 17 | */ |
373 | 18 | 18 | ||
374 | 19 | #include "published_socket_connector.h" | 19 | #include "published_socket_connector.h" |
376 | 20 | #include "protobuf_session_creator.h" | 20 | #include "mir/frontend/protobuf_session_creator.h" |
377 | 21 | 21 | ||
378 | 22 | #include "mir/frontend/connector_report.h" | 22 | #include "mir/frontend/connector_report.h" |
379 | 23 | 23 | ||
380 | 24 | 24 | ||
381 | === modified file 'src/server/frontend/socket_session.cpp' | |||
382 | --- src/server/frontend/socket_session.cpp 2014-01-20 07:11:48 +0000 | |||
383 | +++ src/server/frontend/socket_session.cpp 2014-01-21 15:42:35 +0000 | |||
384 | @@ -21,6 +21,8 @@ | |||
385 | 21 | #include "message_receiver.h" | 21 | #include "message_receiver.h" |
386 | 22 | #include "mir/frontend/message_processor.h" | 22 | #include "mir/frontend/message_processor.h" |
387 | 23 | 23 | ||
388 | 24 | #include "mir_protobuf_wire.pb.h" | ||
389 | 25 | |||
390 | 24 | #include <boost/signals2.hpp> | 26 | #include <boost/signals2.hpp> |
391 | 25 | #include <boost/throw_exception.hpp> | 27 | #include <boost/throw_exception.hpp> |
392 | 26 | 28 | ||
393 | @@ -85,8 +87,13 @@ | |||
394 | 85 | } | 87 | } |
395 | 86 | 88 | ||
396 | 87 | std::istream msg(&message); | 89 | std::istream msg(&message); |
399 | 88 | 90 | mir::protobuf::wire::Invocation invocation; | |
400 | 89 | if (processor->process_message(msg)) | 91 | invocation.ParseFromIstream(&msg); |
401 | 92 | |||
402 | 93 | if (!invocation.has_protocol_version() || invocation.protocol_version() != 1) | ||
403 | 94 | BOOST_THROW_EXCEPTION(std::runtime_error("Unsupported protocol version")); | ||
404 | 95 | |||
405 | 96 | if (processor->dispatch(invocation)) | ||
406 | 90 | { | 97 | { |
407 | 91 | read_next_message(); | 98 | read_next_message(); |
408 | 92 | } | 99 | } |
409 | 93 | 100 | ||
410 | === modified file 'src/server/frontend/socket_session.h' | |||
411 | --- src/server/frontend/socket_session.h 2014-01-16 14:39:11 +0000 | |||
412 | +++ src/server/frontend/socket_session.h 2014-01-21 15:42:35 +0000 | |||
413 | @@ -20,7 +20,7 @@ | |||
414 | 20 | #ifndef MIR_FRONTEND_DETAIL_SOCKET_SESSION_H_ | 20 | #ifndef MIR_FRONTEND_DETAIL_SOCKET_SESSION_H_ |
415 | 21 | #define MIR_FRONTEND_DETAIL_SOCKET_SESSION_H_ | 21 | #define MIR_FRONTEND_DETAIL_SOCKET_SESSION_H_ |
416 | 22 | 22 | ||
418 | 23 | #include "connected_sessions.h" | 23 | #include "mir/frontend/connected_sessions.h" |
419 | 24 | 24 | ||
420 | 25 | #include <boost/asio.hpp> | 25 | #include <boost/asio.hpp> |
421 | 26 | 26 | ||
422 | 27 | 27 | ||
423 | === removed file 'src/server/frontend/template_protobuf_message_processor.cpp' | |||
424 | --- src/server/frontend/template_protobuf_message_processor.cpp 2014-01-16 14:39:11 +0000 | |||
425 | +++ src/server/frontend/template_protobuf_message_processor.cpp 1970-01-01 00:00:00 +0000 | |||
426 | @@ -1,44 +0,0 @@ | |||
427 | 1 | /* | ||
428 | 2 | * Copyright © 2014 Canonical Ltd. | ||
429 | 3 | * | ||
430 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
431 | 5 | * under the terms of the GNU General Public License version 3, | ||
432 | 6 | * as published by the Free Software Foundation. | ||
433 | 7 | * | ||
434 | 8 | * This program is distributed in the hope that it will be useful, | ||
435 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
436 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
437 | 11 | * GNU General Public License for more details. | ||
438 | 12 | * | ||
439 | 13 | * You should have received a copy of the GNU General Public License | ||
440 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
441 | 15 | * | ||
442 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
443 | 17 | */ | ||
444 | 18 | |||
445 | 19 | #include "mir/frontend/template_protobuf_message_processor.h" | ||
446 | 20 | #include "mir/frontend/protobuf_message_sender.h" | ||
447 | 21 | |||
448 | 22 | namespace mfd = mir::frontend::detail; | ||
449 | 23 | |||
450 | 24 | mfd::TemplateProtobufMessageProcessor::TemplateProtobufMessageProcessor( | ||
451 | 25 | std::shared_ptr<ProtobufMessageSender> const& sender) : | ||
452 | 26 | sender(sender) | ||
453 | 27 | { | ||
454 | 28 | } | ||
455 | 29 | |||
456 | 30 | bool mfd::TemplateProtobufMessageProcessor::process_message(std::istream& msg) | ||
457 | 31 | { | ||
458 | 32 | mir::protobuf::wire::Invocation invocation; | ||
459 | 33 | invocation.ParseFromIstream(&msg); | ||
460 | 34 | |||
461 | 35 | if (invocation.has_protocol_version() && invocation.protocol_version() != 1) | ||
462 | 36 | BOOST_THROW_EXCEPTION(std::runtime_error("Unsupported protocol version")); | ||
463 | 37 | |||
464 | 38 | return dispatch(invocation); | ||
465 | 39 | } | ||
466 | 40 | |||
467 | 41 | void mfd::TemplateProtobufMessageProcessor::send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response) | ||
468 | 42 | { | ||
469 | 43 | sender->send_response(id, response, {}); | ||
470 | 44 | } | ||
471 | 45 | 0 | ||
472 | === modified file 'src/shared/protobuf/mir_protobuf_wire.proto' | |||
473 | --- src/shared/protobuf/mir_protobuf_wire.proto 2013-08-29 03:48:16 +0000 | |||
474 | +++ src/shared/protobuf/mir_protobuf_wire.proto 2014-01-21 15:42:35 +0000 | |||
475 | @@ -4,7 +4,7 @@ | |||
476 | 4 | required uint32 id = 1; | 4 | required uint32 id = 1; |
477 | 5 | required string method_name = 2; | 5 | required string method_name = 2; |
478 | 6 | required bytes parameters = 3; | 6 | required bytes parameters = 3; |
480 | 7 | optional uint32 protocol_version = 4; | 7 | required uint32 protocol_version = 4; |
481 | 8 | } | 8 | } |
482 | 9 | 9 | ||
483 | 10 | message Result { | 10 | message Result { |
484 | 11 | 11 | ||
485 | === modified file 'tests/acceptance-tests/test_protobuf.cpp' | |||
486 | --- tests/acceptance-tests/test_protobuf.cpp 2014-01-10 17:34:40 +0000 | |||
487 | +++ tests/acceptance-tests/test_protobuf.cpp 2014-01-21 15:42:35 +0000 | |||
488 | @@ -20,29 +20,169 @@ | |||
489 | 20 | 20 | ||
490 | 21 | #include "mir_toolkit/mir_client_library.h" | 21 | #include "mir_toolkit/mir_client_library.h" |
491 | 22 | #include "mir/client/private.h" | 22 | #include "mir/client/private.h" |
492 | 23 | #include "mir/frontend/protobuf_message_sender.h" | ||
493 | 24 | #include "mir/frontend/protobuf_session_creator.h" | ||
494 | 25 | #include "mir/frontend/template_protobuf_message_processor.h" | ||
495 | 23 | 26 | ||
496 | 24 | #include "mir_test_framework/stubbed_server_configuration.h" | 27 | #include "mir_test_framework/stubbed_server_configuration.h" |
497 | 25 | #include "mir_test_framework/in_process_server.h" | 28 | #include "mir_test_framework/in_process_server.h" |
498 | 26 | 29 | ||
499 | 27 | #include <gtest/gtest.h> | 30 | #include <gtest/gtest.h> |
500 | 31 | #include <gmock/gmock.h> | ||
501 | 28 | 32 | ||
502 | 29 | #include <atomic> | 33 | #include <atomic> |
503 | 30 | 34 | ||
504 | 35 | namespace mf = mir::frontend; | ||
505 | 36 | namespace mfd = mir::frontend::detail; | ||
506 | 37 | |||
507 | 38 | /*************************************************************************/ | ||
508 | 39 | /*************************************************************************/ | ||
509 | 40 | /* Note that the functionality demonstrated here relies on "detail" and */ | ||
510 | 41 | /* is not guaranteed to be supported in future. */ | ||
511 | 42 | /*************************************************************************/ | ||
512 | 43 | /*************************************************************************/ | ||
513 | 31 | namespace | 44 | namespace |
514 | 32 | { | 45 | { |
520 | 33 | class DemoPrivateProtobuf : public mir_test_framework::InProcessServer | 46 | struct DemoMirServer : mir::protobuf::MirServer |
521 | 34 | { | 47 | { |
522 | 35 | mir::DefaultServerConfiguration& server_config() override { return server_config_; } | 48 | MOCK_CONST_METHOD1(on_call, std::string(std::string)); |
523 | 36 | 49 | ||
524 | 37 | mir_test_framework::StubbedServerConfiguration server_config_; | 50 | DemoMirServer() |
525 | 51 | { | ||
526 | 52 | using namespace testing; | ||
527 | 53 | ON_CALL(*this, on_call(_)).WillByDefault(Return("ok")); | ||
528 | 54 | } | ||
529 | 55 | |||
530 | 56 | void function( | ||
531 | 57 | ::google::protobuf::RpcController* , | ||
532 | 58 | ::mir::protobuf::Parameters const* parameters, | ||
533 | 59 | ::mir::protobuf::Result* response, | ||
534 | 60 | ::google::protobuf::Closure* done) | ||
535 | 61 | { | ||
536 | 62 | response->set_value(on_call(parameters->name())); | ||
537 | 63 | done->Run(); | ||
538 | 64 | } | ||
539 | 65 | }; | ||
540 | 66 | |||
541 | 67 | // using a global for easy access from tests and DemoMessageProcessor::dispatch() | ||
542 | 68 | DemoMirServer* demo_mir_server; | ||
543 | 69 | |||
544 | 70 | struct DemoMessageProcessor : mfd::MessageProcessor | ||
545 | 71 | { | ||
546 | 72 | DemoMessageProcessor( | ||
547 | 73 | std::shared_ptr<mfd::ProtobufMessageSender> const& sender, | ||
548 | 74 | std::shared_ptr<mfd::MessageProcessor> const& wrapped) : | ||
549 | 75 | sender(sender), | ||
550 | 76 | wrapped(wrapped) {} | ||
551 | 77 | |||
552 | 78 | bool dispatch(mir::protobuf::wire::Invocation const& invocation) | ||
553 | 79 | { | ||
554 | 80 | if ("function" == invocation.method_name()) | ||
555 | 81 | { | ||
556 | 82 | mfd::invoke( | ||
557 | 83 | this, | ||
558 | 84 | demo_mir_server, | ||
559 | 85 | &DemoMirServer::function, | ||
560 | 86 | invocation); | ||
561 | 87 | return true; | ||
562 | 88 | } | ||
563 | 89 | |||
564 | 90 | return wrapped->dispatch(invocation); | ||
565 | 91 | } | ||
566 | 92 | |||
567 | 93 | void send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response) | ||
568 | 94 | { | ||
569 | 95 | sender->send_response(id, response, {}); | ||
570 | 96 | } | ||
571 | 97 | |||
572 | 98 | std::shared_ptr<mfd::ProtobufMessageSender> const sender; | ||
573 | 99 | std::shared_ptr<mfd::MessageProcessor> const wrapped; | ||
574 | 100 | }; | ||
575 | 101 | |||
576 | 102 | struct DemoSessionCreator : mf::ProtobufSessionCreator | ||
577 | 103 | { | ||
578 | 104 | using ProtobufSessionCreator::ProtobufSessionCreator; | ||
579 | 105 | |||
580 | 106 | MOCK_CONST_METHOD3(create_processor, | ||
581 | 107 | std::shared_ptr<mfd::MessageProcessor>( | ||
582 | 108 | std::shared_ptr<mfd::ProtobufMessageSender> const& sender, | ||
583 | 109 | std::shared_ptr<mir::protobuf::DisplayServer> const& display_server, | ||
584 | 110 | std::shared_ptr<mf::MessageProcessorReport> const& report)); | ||
585 | 111 | |||
586 | 112 | std::shared_ptr<mfd::MessageProcessor> create_wrapped_processor( | ||
587 | 113 | std::shared_ptr<mfd::ProtobufMessageSender> const& sender, | ||
588 | 114 | std::shared_ptr<mir::protobuf::DisplayServer> const& display_server, | ||
589 | 115 | std::shared_ptr<mf::MessageProcessorReport> const& report) const | ||
590 | 116 | { | ||
591 | 117 | auto const wrapped = mf::ProtobufSessionCreator::create_processor( | ||
592 | 118 | sender, | ||
593 | 119 | display_server, | ||
594 | 120 | report); | ||
595 | 121 | |||
596 | 122 | return std::make_shared<DemoMessageProcessor>(sender, wrapped); | ||
597 | 123 | } | ||
598 | 124 | |||
599 | 125 | std::shared_ptr<mfd::MessageProcessor> create_unwrapped_processor( | ||
600 | 126 | std::shared_ptr<mfd::ProtobufMessageSender> const& sender, | ||
601 | 127 | std::shared_ptr<mir::protobuf::DisplayServer> const& display_server, | ||
602 | 128 | std::shared_ptr<mf::MessageProcessorReport> const& report) const | ||
603 | 129 | { | ||
604 | 130 | return mf::ProtobufSessionCreator::create_processor( | ||
605 | 131 | sender, | ||
606 | 132 | display_server, | ||
607 | 133 | report); | ||
608 | 134 | } | ||
609 | 135 | }; | ||
610 | 136 | |||
611 | 137 | struct DemoServerConfiguration : mir_test_framework::StubbedServerConfiguration | ||
612 | 138 | { | ||
613 | 139 | std::shared_ptr<mf::SessionCreator> the_session_creator() override | ||
614 | 140 | { | ||
615 | 141 | return session_creator([this] | ||
616 | 142 | { | ||
617 | 143 | return std::make_shared<DemoSessionCreator>( | ||
618 | 144 | the_ipc_factory(the_frontend_shell(), the_buffer_allocator()), | ||
619 | 145 | the_session_authorizer(), | ||
620 | 146 | the_message_processor_report()); | ||
621 | 147 | }); | ||
622 | 148 | } | ||
623 | 149 | |||
624 | 150 | }; | ||
625 | 151 | |||
626 | 152 | struct DemoPrivateProtobuf : mir_test_framework::InProcessServer | ||
627 | 153 | { | ||
628 | 154 | mir::DefaultServerConfiguration& server_config() override { return my_server_config; } | ||
629 | 155 | |||
630 | 156 | DemoServerConfiguration my_server_config; | ||
631 | 157 | |||
632 | 158 | std::shared_ptr<DemoSessionCreator> demo_session_creator; | ||
633 | 159 | |||
634 | 160 | void SetUp() | ||
635 | 161 | { | ||
636 | 162 | ::demo_mir_server = &demo_mir_server; | ||
637 | 163 | |||
638 | 164 | mir_test_framework::InProcessServer::SetUp(); | ||
639 | 165 | demo_session_creator = std::dynamic_pointer_cast<DemoSessionCreator>(my_server_config.the_session_creator()); | ||
640 | 166 | |||
641 | 167 | using namespace testing; | ||
642 | 168 | ASSERT_THAT(demo_session_creator, NotNull()); | ||
643 | 169 | |||
644 | 170 | ON_CALL(*demo_session_creator, create_processor(_, _, _)) | ||
645 | 171 | .WillByDefault(Invoke(demo_session_creator.get(), &DemoSessionCreator::create_unwrapped_processor)); | ||
646 | 172 | } | ||
647 | 173 | |||
648 | 174 | testing::NiceMock<DemoMirServer> demo_mir_server; | ||
649 | 38 | }; | 175 | }; |
650 | 39 | 176 | ||
651 | 40 | void callback(std::atomic<bool>* called_back) { called_back->store(true); } | 177 | void callback(std::atomic<bool>* called_back) { called_back->store(true); } |
652 | 41 | char const* const nothing_returned = "Nothing returned"; | 178 | char const* const nothing_returned = "Nothing returned"; |
653 | 42 | } | 179 | } |
654 | 43 | 180 | ||
656 | 44 | TEST_F(DemoPrivateProtobuf, client_can_call_server) | 181 | TEST_F(DemoPrivateProtobuf, client_calls_server) |
657 | 45 | { | 182 | { |
658 | 183 | using namespace testing; | ||
659 | 184 | EXPECT_CALL(*demo_session_creator, create_processor(_, _, _)); | ||
660 | 185 | |||
661 | 46 | auto const connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | 186 | auto const connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
662 | 47 | ASSERT_TRUE(mir_connection_is_valid(connection)); | 187 | ASSERT_TRUE(mir_connection_is_valid(connection)); |
663 | 48 | 188 | ||
664 | @@ -72,5 +212,74 @@ | |||
665 | 72 | mir_connection_release(connection); | 212 | mir_connection_release(connection); |
666 | 73 | 213 | ||
667 | 74 | EXPECT_TRUE(called_back); | 214 | EXPECT_TRUE(called_back); |
669 | 75 | EXPECT_EQ(nothing_returned, result.error()); | 215 | EXPECT_THAT(result.error(), Eq(nothing_returned)); |
670 | 216 | } | ||
671 | 217 | |||
672 | 218 | TEST_F(DemoPrivateProtobuf, wrapping_message_processor) | ||
673 | 219 | { | ||
674 | 220 | using namespace testing; | ||
675 | 221 | EXPECT_CALL(*demo_session_creator, create_processor(_, _, _)) | ||
676 | 222 | .Times(1) | ||
677 | 223 | .WillOnce(Invoke(demo_session_creator.get(), &DemoSessionCreator::create_wrapped_processor)); | ||
678 | 224 | |||
679 | 225 | auto const connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
680 | 226 | |||
681 | 227 | mir_connection_release(connection); | ||
682 | 228 | } | ||
683 | 229 | |||
684 | 230 | TEST_F(DemoPrivateProtobuf, server_receives_function_call) | ||
685 | 231 | { | ||
686 | 232 | using namespace testing; | ||
687 | 233 | EXPECT_CALL(*demo_session_creator, create_processor(_, _, _)) | ||
688 | 234 | .WillRepeatedly(Invoke(demo_session_creator.get(), &DemoSessionCreator::create_wrapped_processor)); | ||
689 | 235 | |||
690 | 236 | auto const connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
691 | 237 | ASSERT_TRUE(mir_connection_is_valid(connection)); | ||
692 | 238 | |||
693 | 239 | auto const rpc_channel = mir::client::the_rpc_channel(connection); | ||
694 | 240 | |||
695 | 241 | using namespace mir::protobuf; | ||
696 | 242 | using namespace google::protobuf; | ||
697 | 243 | |||
698 | 244 | MirServer::Stub server(rpc_channel.get()); | ||
699 | 245 | |||
700 | 246 | Parameters parameters; | ||
701 | 247 | Result result; | ||
702 | 248 | parameters.set_name(__PRETTY_FUNCTION__); | ||
703 | 249 | |||
704 | 250 | EXPECT_CALL(demo_mir_server, on_call(__PRETTY_FUNCTION__)).Times(1); | ||
705 | 251 | |||
706 | 252 | server.function(nullptr, ¶meters, &result, NewCallback([]{})); | ||
707 | 253 | |||
708 | 254 | mir_connection_release(connection); | ||
709 | 255 | } | ||
710 | 256 | |||
711 | 257 | |||
712 | 258 | TEST_F(DemoPrivateProtobuf, client_receives_result) | ||
713 | 259 | { | ||
714 | 260 | using namespace testing; | ||
715 | 261 | EXPECT_CALL(*demo_session_creator, create_processor(_, _, _)) | ||
716 | 262 | .WillRepeatedly(Invoke(demo_session_creator.get(), &DemoSessionCreator::create_wrapped_processor)); | ||
717 | 263 | EXPECT_CALL(demo_mir_server, on_call(_)).WillRepeatedly(Return(__PRETTY_FUNCTION__)); | ||
718 | 264 | |||
719 | 265 | auto const connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | ||
720 | 266 | ASSERT_TRUE(mir_connection_is_valid(connection)); | ||
721 | 267 | |||
722 | 268 | auto const rpc_channel = mir::client::the_rpc_channel(connection); | ||
723 | 269 | |||
724 | 270 | using namespace mir::protobuf; | ||
725 | 271 | using namespace google::protobuf; | ||
726 | 272 | |||
727 | 273 | MirServer::Stub server(rpc_channel.get()); | ||
728 | 274 | |||
729 | 275 | Parameters parameters; | ||
730 | 276 | Result result; | ||
731 | 277 | parameters.set_name(__PRETTY_FUNCTION__); | ||
732 | 278 | |||
733 | 279 | server.function(nullptr, ¶meters, &result, NewCallback([]{})); | ||
734 | 280 | |||
735 | 281 | mir_connection_release(connection); | ||
736 | 282 | |||
737 | 283 | EXPECT_THAT(result.has_error(), Eq(false)); | ||
738 | 284 | EXPECT_THAT(result.value(), Eq(__PRETTY_FUNCTION__)); | ||
739 | 76 | } | 285 | } |
740 | 77 | 286 | ||
741 | === modified file 'tests/acceptance-tests/test_protobuf.proto' | |||
742 | --- tests/acceptance-tests/test_protobuf.proto 2014-01-10 16:51:32 +0000 | |||
743 | +++ tests/acceptance-tests/test_protobuf.proto 2014-01-21 15:42:35 +0000 | |||
744 | @@ -9,6 +9,7 @@ | |||
745 | 9 | 9 | ||
746 | 10 | message Result { | 10 | message Result { |
747 | 11 | optional string error = 127; | 11 | optional string error = 127; |
748 | 12 | optional string value = 1; | ||
749 | 12 | } | 13 | } |
750 | 13 | 14 | ||
751 | 14 | service MirServer { | 15 | service MirServer { |
752 | 15 | 16 | ||
753 | === modified file 'tests/mir_test_doubles/test_protobuf_socket_server.cpp' | |||
754 | --- tests/mir_test_doubles/test_protobuf_socket_server.cpp 2014-01-15 12:26:01 +0000 | |||
755 | +++ tests/mir_test_doubles/test_protobuf_socket_server.cpp 2014-01-21 15:42:35 +0000 | |||
756 | @@ -21,8 +21,8 @@ | |||
757 | 21 | #include "mir_test_doubles/stub_session_authorizer.h" | 21 | #include "mir_test_doubles/stub_session_authorizer.h" |
758 | 22 | #include "mir/frontend/connector_report.h" | 22 | #include "mir/frontend/connector_report.h" |
759 | 23 | #include "mir/frontend/null_message_processor_report.h" | 23 | #include "mir/frontend/null_message_processor_report.h" |
760 | 24 | #include "mir/frontend/protobuf_session_creator.h" | ||
761 | 24 | #include "src/server/frontend/published_socket_connector.h" | 25 | #include "src/server/frontend/published_socket_connector.h" |
762 | 25 | #include "src/server/frontend/protobuf_session_creator.h" | ||
763 | 26 | 26 | ||
764 | 27 | namespace mt = mir::test; | 27 | namespace mt = mir::test; |
765 | 28 | namespace mtd = mir::test::doubles; | 28 | namespace mtd = mir::test::doubles; |
766 | 29 | 29 | ||
767 | === modified file 'tests/unit-tests/frontend/test_published_socket_connector.cpp' | |||
768 | --- tests/unit-tests/frontend/test_published_socket_connector.cpp 2014-01-20 07:11:48 +0000 | |||
769 | +++ tests/unit-tests/frontend/test_published_socket_connector.cpp 2014-01-21 15:42:35 +0000 | |||
770 | @@ -20,9 +20,9 @@ | |||
771 | 20 | #include "mir/frontend/connector.h" | 20 | #include "mir/frontend/connector.h" |
772 | 21 | #include "mir/frontend/connector_report.h" | 21 | #include "mir/frontend/connector_report.h" |
773 | 22 | #include "mir/frontend/null_message_processor_report.h" | 22 | #include "mir/frontend/null_message_processor_report.h" |
774 | 23 | #include "mir/frontend/protobuf_session_creator.h" | ||
775 | 23 | #include "src/server/frontend/resource_cache.h" | 24 | #include "src/server/frontend/resource_cache.h" |
776 | 24 | #include "src/server/frontend/published_socket_connector.h" | 25 | #include "src/server/frontend/published_socket_connector.h" |
777 | 25 | #include "src/server/frontend/protobuf_session_creator.h" | ||
778 | 26 | 26 | ||
779 | 27 | #include "mir_protobuf.pb.h" | 27 | #include "mir_protobuf.pb.h" |
780 | 28 | 28 | ||
781 | 29 | 29 | ||
782 | === modified file 'tests/unit-tests/frontend/test_socket_session.cpp' | |||
783 | --- tests/unit-tests/frontend/test_socket_session.cpp 2014-01-20 07:11:48 +0000 | |||
784 | +++ tests/unit-tests/frontend/test_socket_session.cpp 2014-01-21 15:42:35 +0000 | |||
785 | @@ -1,5 +1,5 @@ | |||
786 | 1 | /* | 1 | /* |
788 | 2 | * Copyright © 2013 Canonical Ltd. | 2 | * Copyright © 2013, 2014 Canonical Ltd. |
789 | 3 | * | 3 | * |
790 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
791 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
792 | @@ -14,6 +14,7 @@ | |||
793 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
794 | 15 | * | 15 | * |
795 | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
796 | 17 | * Alan Griffiths <alan@octopull.co.uk> | ||
797 | 17 | */ | 18 | */ |
798 | 18 | 19 | ||
799 | 19 | #include "src/server/frontend/socket_session.h" | 20 | #include "src/server/frontend/socket_session.h" |
800 | @@ -22,6 +23,8 @@ | |||
801 | 22 | 23 | ||
802 | 23 | #include "mir_test/fake_shared.h" | 24 | #include "mir_test/fake_shared.h" |
803 | 24 | 25 | ||
804 | 26 | #include "mir_protobuf_wire.pb.h" | ||
805 | 27 | |||
806 | 25 | #include <gmock/gmock.h> | 28 | #include <gmock/gmock.h> |
807 | 26 | #include <gtest/gtest.h> | 29 | #include <gtest/gtest.h> |
808 | 27 | 30 | ||
809 | @@ -31,55 +34,76 @@ | |||
810 | 31 | 34 | ||
811 | 32 | namespace | 35 | namespace |
812 | 33 | { | 36 | { |
814 | 34 | struct MockReceiver : public mfd::MessageReceiver | 37 | struct StubReceiver : public mfd::MessageReceiver |
815 | 35 | { | 38 | { |
818 | 36 | MOCK_METHOD3(async_receive_msg, void(std::function<void(boost::system::error_code const&, size_t)> const&, | 39 | void async_receive_msg( |
819 | 37 | boost::asio::streambuf&, size_t)); | 40 | std::function<void(boost::system::error_code const&, size_t)> const& callback, |
820 | 41 | boost::asio::streambuf& stream, | ||
821 | 42 | size_t size) | ||
822 | 43 | { | ||
823 | 44 | read_size = size; | ||
824 | 45 | pstream = &stream; | ||
825 | 46 | callback_function = callback; | ||
826 | 47 | } | ||
827 | 48 | |||
828 | 49 | void fake_receive_msg(char* buffer, size_t size) | ||
829 | 50 | { | ||
830 | 51 | using namespace testing; | ||
831 | 52 | ASSERT_NE(nullptr, callback_function); | ||
832 | 53 | ASSERT_THAT(pstream, NotNull()); | ||
833 | 54 | ASSERT_THAT(read_size, Eq(size)); | ||
834 | 55 | |||
835 | 56 | pstream->sputn(buffer, size); | ||
836 | 57 | pstream->commit(size); | ||
837 | 58 | |||
838 | 59 | boost::system::error_code code; | ||
839 | 60 | callback_function(code, size); | ||
840 | 61 | } | ||
841 | 62 | |||
842 | 63 | private: | ||
843 | 64 | std::function<void(boost::system::error_code const&, size_t)> callback_function; | ||
844 | 65 | boost::asio::streambuf* pstream = nullptr; | ||
845 | 66 | size_t read_size = 0; | ||
846 | 67 | |||
847 | 38 | MOCK_METHOD0(client_pid, pid_t()); | 68 | MOCK_METHOD0(client_pid, pid_t()); |
848 | 39 | }; | 69 | }; |
849 | 40 | 70 | ||
850 | 41 | struct MockProcessor : public mfd::MessageProcessor | 71 | struct MockProcessor : public mfd::MessageProcessor |
851 | 42 | { | 72 | { |
853 | 43 | MOCK_METHOD1(process_message, bool(std::istream&)); | 73 | MOCK_METHOD1(dispatch, bool(mir::protobuf::wire::Invocation const& invocation)); |
854 | 44 | }; | 74 | }; |
855 | 45 | } | 75 | } |
856 | 46 | struct SocketSessionTest : public ::testing::Test | 76 | struct SocketSessionTest : public ::testing::Test |
857 | 47 | { | 77 | { |
858 | 48 | testing::NiceMock<MockProcessor> mock_processor; | 78 | testing::NiceMock<MockProcessor> mock_processor; |
860 | 49 | testing::NiceMock<MockReceiver> mock_receiver; | 79 | StubReceiver stub_receiver; |
861 | 50 | }; | 80 | }; |
862 | 51 | 81 | ||
864 | 52 | TEST_F(SocketSessionTest, basic_msg) | 82 | TEST_F(SocketSessionTest, basic_msg_is_received_and_dispatched) |
865 | 53 | { | 83 | { |
866 | 84 | int const header_size = 2; | ||
867 | 85 | char buffer[512]; | ||
868 | 86 | mir::protobuf::wire::Invocation invocation; | ||
869 | 87 | invocation.set_id(1); | ||
870 | 88 | invocation.set_method_name(""); | ||
871 | 89 | invocation.set_parameters(buffer, 0); | ||
872 | 90 | invocation.set_protocol_version(1); | ||
873 | 91 | auto const body_size = invocation.ByteSize(); | ||
874 | 92 | |||
875 | 54 | using namespace testing; | 93 | using namespace testing; |
876 | 55 | 94 | ||
877 | 56 | std::shared_ptr<mfd::ConnectedSessions<mfd::SocketSession>> null_sessions; | 95 | std::shared_ptr<mfd::ConnectedSessions<mfd::SocketSession>> null_sessions; |
888 | 57 | std::function<void(boost::system::error_code const&, size_t)> header_read, body_read; | 96 | |
889 | 58 | 97 | mfd::SocketSession session(mt::fake_shared(stub_receiver), 0, null_sessions, mt::fake_shared(mock_processor)); | |
890 | 59 | size_t header_size = 2; | 98 | |
891 | 60 | EXPECT_CALL(mock_receiver, async_receive_msg(_,_, header_size)) | 99 | EXPECT_CALL(mock_processor, dispatch(_)).Times(1).WillOnce(Return(true)); |
892 | 61 | .Times(1) | 100 | |
883 | 62 | .WillOnce(SaveArg<0>(&header_read)); | ||
884 | 63 | |||
885 | 64 | mfd::SocketSession session(mt::fake_shared(mock_receiver), 0, null_sessions, mt::fake_shared(mock_processor)); | ||
886 | 65 | |||
887 | 66 | //trigger wait for header | ||
893 | 67 | session.read_next_message(); | 101 | session.read_next_message(); |
911 | 68 | testing::Mock::VerifyAndClearExpectations(&mock_receiver); | 102 | |
912 | 69 | 103 | buffer[0] = body_size / 0x100; | |
913 | 70 | //trigger body read | 104 | buffer[1] = body_size % 0x100; |
914 | 71 | EXPECT_CALL(mock_receiver, async_receive_msg(_,_,_)) | 105 | stub_receiver.fake_receive_msg(buffer, header_size); |
915 | 72 | .Times(1) | 106 | |
916 | 73 | .WillOnce(SaveArg<0>(&body_read)); | 107 | invocation.SerializeToArray(buffer, sizeof buffer); |
917 | 74 | 108 | stub_receiver.fake_receive_msg(buffer, body_size); | |
901 | 75 | boost::system::error_code code; | ||
902 | 76 | header_read(code, 2); | ||
903 | 77 | |||
904 | 78 | testing::Mock::VerifyAndClearExpectations(&mock_receiver); | ||
905 | 79 | |||
906 | 80 | //trigger message process | ||
907 | 81 | EXPECT_CALL(mock_processor, process_message(_)) | ||
908 | 82 | .Times(1) | ||
909 | 83 | .WillOnce(Return(true)); | ||
910 | 84 | body_read(code, 9); | ||
918 | 85 | } | 109 | } |
PASSED: Continuous integration, rev:1344 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- ci/688/ jenkins. qa.ubuntu. com/job/ mir-android- trusty- i386-build/ 675 jenkins. qa.ubuntu. com/job/ mir-clang- trusty- amd64-build/ 671 jenkins. qa.ubuntu. com/job/ mir-mediumtests -trusty- touch/277 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- trusty- amd64-ci/ 418 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- trusty- amd64-ci/ 418/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- trusty- armhf-ci/ 422 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- trusty- armhf-ci/ 422/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- trusty- armhf/277 jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- trusty- armhf/277/ artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-mediumtests -runner- mako/293 s-jenkins. ubuntu- ci:8080/ job/touch- flash-device/ 3208
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: s-jenkins. ubuntu- ci:8080/ job/mir- team-mir- development- branch- ci/688/ rebuild
http://