Mir

Merge lp:~albaguirre/mir/fix-1465883 into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 2674
Proposed branch: lp:~albaguirre/mir/fix-1465883
Merge into: lp:mir
Diff against target: 1413 lines (+308/-238)
12 files modified
src/client/buffer_stream.cpp (+38/-37)
src/client/buffer_stream.h (+3/-3)
src/client/make_protobuf_object.h (+42/-0)
src/client/mir_connection.cpp (+56/-49)
src/client/mir_connection.h (+8/-6)
src/client/mir_prompt_session.cpp (+21/-15)
src/client/mir_prompt_session.h (+5/-5)
src/client/mir_screencast.cpp (+24/-21)
src/client/mir_screencast.h (+4/-2)
src/client/mir_surface.cpp (+83/-76)
src/client/mir_surface.h (+6/-7)
src/client/rpc/mir_protobuf_rpc_channel.cpp (+18/-17)
To merge this branch: bzr merge lp:~albaguirre/mir/fix-1465883
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Chris Halse Rogers Approve
Daniel van Vugt Needs Fixing
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+262160@code.launchpad.net

Commit message

Avoid allocating mir::protobuf objects on the stack

When an addition is made to a protobuf message, a stack allocation of such object may differ from what the destructor of that message is expecting as the destructor is defined by libmirprotobuf and the allocation may have been made from an older definition of the message (by an older mirclient library for example) which can lead to stack corruption.

Ideally, the mirprotobuf library would have versioned symbols and have the ability to be loaded in parallel to a previous version but that's not currently possible.

As an alternative, avoid allocating mir defined protobuf objects on the stack and instead use the xxx::default_instance().New() factory methods which are defined in the mirprotobuf library.

Description of the change

Avoid allocating mir::protobuf objects on the stack

When an addition is made to a protobuf message, a stack allocation of such object may differ from what the destructor of that message is expecting as the destructor is defined by libmirprotobuf and the allocation may have been made from an older definition of the message (by an older mirclient library for example) which can lead to stack corruption.

Ideally, the mirprotobuf library would have versioned symbols and have the ability to be loaded in parallel to a previous version but that's not currently possible.

As an alternative, avoid allocating mir defined protobuf objects on the stack and instead use the xxx::default_instance().New() factory methods which are defined in the mirprotobuf library.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Slightly scary no one figured this out earlier.

A worse way to think of the bug is: If a new field is added to a message then any existing code will try to construct that message on the stack using its old (smaller) size while Protobuf itself fills out the new fields (which we didn't allow for in the stack allocation). Hence stack corruption.

The solution presented here however fails to work in all cases of ABI breaks such as when a member is removed from the middle of the object. Not likely, but there is a better option...

The issue is really that we're breaking MIRPROTOBUF_ABI but have never thought to bump it. If it was bumped any any change to message sizes/structure then everyone would always be linked to a version that is safe for them. And bumping MIRPROTOBUF_ABI would mean we could keep our nice fast stack variables.

review: Needs Information
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

So I think Disapprove/Needs fixing. A simple bump of MIRPROTOBUF_ABI will solve it more reliably and give us more efficient code. Unless anyone can prove there's a protobuf issue preventing us from doing that.

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

It's also worth noting you don't need versioned symbols at all if your major ABI number is changing instead.

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

There *is* a protobuf issue preventing us from doing that; see for example the failures on input-methods-can-... when I bumped protobuf ABI (eg: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-runner-mako/5597/console )

The issue is that protobuf will abort() if it's loaded twice, and bumping mirprotobuf ABI ensures that it's loaded twice. Otherwise we wouldn't be building libmirprotobuf.so at all, and would be statically linking it as nature intended.

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

So, urgh. Yeah, this is better than what we've got.

Is there any obvious way to test that we don't stack-create protobuf objects? It'd be nice to have a test, but I can't think of one.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> So I think Disapprove/Needs fixing. A simple bump of MIRPROTOBUF_ABI will
> solve it more reliably and give us more efficient code. Unless anyone can
> prove there's a protobuf issue preventing us from doing that.

It really isn't that simple: protobuf has a number of issues in this area. Essentially, we can only have one protobuf instantiation in process.

We've "got away" with it while the client ABI has remained at 8 (as only the latest limbirprotobuf gets loaded). Now we're proposing 9 we need to keep the same limbirprotobuf version.

Alexandros has tried to upstream some fixes to protobuf, and Kevin and Chris have recently run into problems.

AFAICS the approach proposed here is the least bad of the feasible options.

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

@Daniel,

As others have said, yes there are protobuf issues preventing loading two versions in the same process (for more comments see Chris branch https://code.launchpad.net/~raof/mir/input-methods-can-specify-foreign-parents/+merge/258001)

Loading two versions of protobuf in the same process is more common than is apparent at first glance, because the mesa client platform module links against libmirclient.

Indeed, just by probing the modules, a client that links against libmirclient8, will end up loading libmirprotobuf.so.1 since the module will load libmirclient9 (which is linked to libmirprotobuf.so.1)

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

"The solution presented here however fails to work in all cases of ABI breaks such as when a member is removed from the middle of the object. Not likely, but there is a better option..."

This is true, we still need to tread carefully when modifying protobuf message definitions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/buffer_stream.cpp'
--- src/client/buffer_stream.cpp 2015-06-03 19:17:55 +0000
+++ src/client/buffer_stream.cpp 2015-06-16 23:39:42 +0000
@@ -19,6 +19,7 @@
19#define MIR_LOG_COMPONENT "MirBufferStream"19#define MIR_LOG_COMPONENT "MirBufferStream"
2020
21#include "buffer_stream.h"21#include "buffer_stream.h"
22#include "make_protobuf_object.h"
2223
23#include "mir_connection.h"24#include "mir_connection.h"
24#include "mir/frontend/client_constants.h"25#include "mir/frontend/client_constants.h"
@@ -97,11 +98,11 @@
97 display_server(server),98 display_server(server),
98 mode(mode),99 mode(mode),
99 client_platform(client_platform),100 client_platform(client_platform),
100 protobuf_bs(protobuf_bs),101 protobuf_bs{mcl::make_protobuf_object<mir::protobuf::BufferStream>(protobuf_bs)},
101 buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size},102 buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size},
102 swap_interval_(1),103 swap_interval_(1),
103 perf_report(perf_report)104 perf_report(perf_report),
104 105 protobuf_void{mcl::make_protobuf_object<mir::protobuf::Void>()}
105{106{
106 created(nullptr, nullptr);107 created(nullptr, nullptr);
107 perf_report->name_surface(surface_name.c_str());108 perf_report->name_surface(surface_name.c_str());
@@ -119,21 +120,23 @@
119 display_server(server),120 display_server(server),
120 mode(BufferStreamMode::Producer),121 mode(BufferStreamMode::Producer),
121 client_platform(client_platform),122 client_platform(client_platform),
123 protobuf_bs{mcl::make_protobuf_object<mir::protobuf::BufferStream>()},
122 buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size},124 buffer_depository{client_platform->create_buffer_factory(), mir::frontend::client_buffer_cache_size},
123 swap_interval_(1),125 swap_interval_(1),
124 perf_report(perf_report)126 perf_report(perf_report),
127 protobuf_void{mcl::make_protobuf_object<mir::protobuf::Void>()}
125{128{
126 perf_report->name_surface(std::to_string(reinterpret_cast<long int>(this)).c_str());129 perf_report->name_surface(std::to_string(reinterpret_cast<long int>(this)).c_str());
127130
128 create_wait_handle.expect_result();131 create_wait_handle.expect_result();
129 try132 try
130 {133 {
131 server.create_buffer_stream(0, &parameters, &protobuf_bs, gp::NewCallback(this, &mcl::BufferStream::created, callback,134 server.create_buffer_stream(0, &parameters, protobuf_bs.get(), gp::NewCallback(this, &mcl::BufferStream::created, callback,
132 context));135 context));
133 }136 }
134 catch (std::exception const& ex)137 catch (std::exception const& ex)
135 {138 {
136 protobuf_bs.set_error(std::string{"Error invoking create buffer stream: "} +139 protobuf_bs->set_error(std::string{"Error invoking create buffer stream: "} +
137 boost::diagnostic_information(ex));140 boost::diagnostic_information(ex));
138 }141 }
139 142
@@ -141,16 +144,16 @@
141144
142void mcl::BufferStream::created(mir_buffer_stream_callback callback, void *context)145void mcl::BufferStream::created(mir_buffer_stream_callback callback, void *context)
143{146{
144 if (!protobuf_bs.has_id() || protobuf_bs.has_error())147 if (!protobuf_bs->has_id() || protobuf_bs->has_error())
145 BOOST_THROW_EXCEPTION(std::runtime_error("Can not create buffer stream: " + std::string(protobuf_bs.error())));148 BOOST_THROW_EXCEPTION(std::runtime_error("Can not create buffer stream: " + std::string(protobuf_bs->error())));
146 if (!protobuf_bs.has_buffer())149 if (!protobuf_bs->has_buffer())
147 BOOST_THROW_EXCEPTION(std::runtime_error("Buffer stream did not come with a buffer"));150 BOOST_THROW_EXCEPTION(std::runtime_error("Buffer stream did not come with a buffer"));
148151
149 process_buffer(protobuf_bs.buffer());152 process_buffer(protobuf_bs->buffer());
150 egl_native_window_ = client_platform->create_egl_native_window(this);153 egl_native_window_ = client_platform->create_egl_native_window(this);
151154
152 if (connection)155 if (connection)
153 connection->on_stream_created(protobuf_bs.id().value(), this);156 connection->on_stream_created(protobuf_bs->id().value(), this);
154157
155 if (callback)158 if (callback)
156 callback(reinterpret_cast<MirBufferStream*>(this), context);159 callback(reinterpret_cast<MirBufferStream*>(this), context);
@@ -180,7 +183,7 @@
180183
181 try184 try
182 {185 {
183 auto pixel_format = static_cast<MirPixelFormat>(protobuf_bs.pixel_format());186 auto pixel_format = static_cast<MirPixelFormat>(protobuf_bs->pixel_format());
184 buffer_depository.deposit_package(buffer_package,187 buffer_depository.deposit_package(buffer_package,
185 buffer.buffer_id(),188 buffer.buffer_id(),
186 cached_buffer_size, pixel_format);189 cached_buffer_size, pixel_format);
@@ -199,40 +202,37 @@
199202
200 secured_region.reset();203 secured_region.reset();
201204
202 mir::protobuf::BufferStreamId buffer_stream_id;205 // TODO: We can fix the strange "ID casting" used below in the second phase
203 buffer_stream_id.set_value(protobuf_bs.id().value());206 // of buffer stream which generalizes and clarifies the server side logic.
204
205// TODO: We can fix the strange "ID casting" used below in the second phase
206// of buffer stream which generalizes and clarifies the server side logic.
207 if (mode == mcl::BufferStreamMode::Producer)207 if (mode == mcl::BufferStreamMode::Producer)
208 {208 {
209 mp::BufferRequest request;209 auto request = mcl::make_protobuf_object<mp::BufferRequest>();
210 request.mutable_id()->set_value(protobuf_bs.id().value());210 request->mutable_id()->set_value(protobuf_bs->id().value());
211 request.mutable_buffer()->set_buffer_id(protobuf_bs.buffer().buffer_id());211 request->mutable_buffer()->set_buffer_id(protobuf_bs->buffer().buffer_id());
212212
213 lock.unlock();213 lock.unlock();
214 next_buffer_wait_handle.expect_result();214 next_buffer_wait_handle.expect_result();
215215
216 display_server.exchange_buffer(216 display_server.exchange_buffer(
217 nullptr,217 nullptr,
218 &request,218 request.get(),
219 protobuf_bs.mutable_buffer(),219 protobuf_bs->mutable_buffer(),
220 google::protobuf::NewCallback(220 google::protobuf::NewCallback(
221 this, &mcl::BufferStream::next_buffer_received,221 this, &mcl::BufferStream::next_buffer_received,
222 done));222 done));
223 }223 }
224 else224 else
225 {225 {
226 mp::ScreencastId screencast_id;226 auto screencast_id = mcl::make_protobuf_object<mp::ScreencastId>();
227 screencast_id.set_value(protobuf_bs.id().value());227 screencast_id->set_value(protobuf_bs->id().value());
228228
229 lock.unlock();229 lock.unlock();
230 next_buffer_wait_handle.expect_result();230 next_buffer_wait_handle.expect_result();
231231
232 display_server.screencast_buffer(232 display_server.screencast_buffer(
233 nullptr,233 nullptr,
234 &screencast_id,234 screencast_id.get(),
235 protobuf_bs.mutable_buffer(),235 protobuf_bs->mutable_buffer(),
236 google::protobuf::NewCallback(236 google::protobuf::NewCallback(
237 this, &mcl::BufferStream::next_buffer_received,237 this, &mcl::BufferStream::next_buffer_received,
238 done));238 done));
@@ -270,7 +270,7 @@
270void mcl::BufferStream::next_buffer_received(270void mcl::BufferStream::next_buffer_received(
271 std::function<void()> done) 271 std::function<void()> done)
272{272{
273 process_buffer(protobuf_bs.buffer());273 process_buffer(protobuf_bs->buffer());
274274
275 done();275 done();
276276
@@ -285,8 +285,8 @@
285 "",285 "",
286 cached_buffer_size.width.as_int(),286 cached_buffer_size.width.as_int(),
287 cached_buffer_size.height.as_int(),287 cached_buffer_size.height.as_int(),
288 static_cast<MirPixelFormat>(protobuf_bs.pixel_format()),288 static_cast<MirPixelFormat>(protobuf_bs->pixel_format()),
289 static_cast<MirBufferUsage>(protobuf_bs.buffer_usage()),289 static_cast<MirBufferUsage>(protobuf_bs->buffer_usage()),
290 mir_display_output_id_invalid};290 mir_display_output_id_invalid};
291}291}
292292
@@ -318,20 +318,21 @@
318 BOOST_THROW_EXCEPTION(std::logic_error("Attempt to set swap interval on screencast is invalid"));318 BOOST_THROW_EXCEPTION(std::logic_error("Attempt to set swap interval on screencast is invalid"));
319 }319 }
320320
321 mp::SurfaceSetting setting, result;321 auto setting = mcl::make_protobuf_object<mp::SurfaceSetting>();
322 setting.mutable_surfaceid()->set_value(protobuf_bs.id().value());322 auto result = mcl::make_protobuf_object<mp::SurfaceSetting>();
323 setting.set_attrib(attrib);323 setting->mutable_surfaceid()->set_value(protobuf_bs->id().value());
324 setting.set_ivalue(value);324 setting->set_attrib(attrib);
325 setting->set_ivalue(value);
325 lock.unlock();326 lock.unlock();
326327
327 configure_wait_handle.expect_result();328 configure_wait_handle.expect_result();
328 display_server.configure_surface(0, &setting, &result,329 display_server.configure_surface(0, setting.get(), result.get(),
329 google::protobuf::NewCallback(this, &mcl::BufferStream::on_configured));330 google::protobuf::NewCallback(this, &mcl::BufferStream::on_configured));
330331
331 configure_wait_handle.wait_for_all();332 configure_wait_handle.wait_for_all();
332333
333 lock.lock();334 lock.lock();
334 swap_interval_ = result.ivalue();335 swap_interval_ = result->ivalue();
335}336}
336337
337uint32_t mcl::BufferStream::get_current_buffer_id()338uint32_t mcl::BufferStream::get_current_buffer_id()
@@ -381,13 +382,13 @@
381{382{
382 std::unique_lock<decltype(mutex)> lock(mutex);383 std::unique_lock<decltype(mutex)> lock(mutex);
383 384
384 return mf::BufferStreamId(protobuf_bs.id().value());385 return mf::BufferStreamId(protobuf_bs->id().value());
385}386}
386387
387bool mcl::BufferStream::valid() const388bool mcl::BufferStream::valid() const
388{389{
389 std::unique_lock<decltype(mutex)> lock(mutex);390 std::unique_lock<decltype(mutex)> lock(mutex);
390 return protobuf_bs.has_id() && !protobuf_bs.has_error();391 return protobuf_bs->has_id() && !protobuf_bs->has_error();
391}392}
392393
393void mcl::BufferStream::set_buffer_cache_size(unsigned int cache_size)394void mcl::BufferStream::set_buffer_cache_size(unsigned int cache_size)
394395
=== modified file 'src/client/buffer_stream.h'
--- src/client/buffer_stream.h 2015-06-03 19:17:55 +0000
+++ src/client/buffer_stream.h 2015-06-16 23:39:42 +0000
@@ -62,7 +62,7 @@
62 mir::protobuf::DisplayServer& server,62 mir::protobuf::DisplayServer& server,
63 BufferStreamMode mode,63 BufferStreamMode mode,
64 std::shared_ptr<ClientPlatform> const& native_window_factory,64 std::shared_ptr<ClientPlatform> const& native_window_factory,
65 protobuf::BufferStream const& protobuf_bs,65 mir::protobuf::BufferStream const& protobuf_bs,
66 std::shared_ptr<PerfReport> const& perf_report,66 std::shared_ptr<PerfReport> const& perf_report,
67 std::string const& surface_name);67 std::string const& surface_name);
68 // For surfaceless buffer streams68 // For surfaceless buffer streams
@@ -124,7 +124,7 @@
124 BufferStreamMode const mode;124 BufferStreamMode const mode;
125 std::shared_ptr<ClientPlatform> const client_platform;125 std::shared_ptr<ClientPlatform> const client_platform;
126126
127 mir::protobuf::BufferStream protobuf_bs;127 std::unique_ptr<mir::protobuf::BufferStream> protobuf_bs;
128 mir::client::ClientBufferDepository buffer_depository;128 mir::client::ClientBufferDepository buffer_depository;
129 129
130 int swap_interval_;130 int swap_interval_;
@@ -137,7 +137,7 @@
137 MirWaitHandle release_wait_handle;137 MirWaitHandle release_wait_handle;
138 MirWaitHandle next_buffer_wait_handle;138 MirWaitHandle next_buffer_wait_handle;
139 MirWaitHandle configure_wait_handle;139 MirWaitHandle configure_wait_handle;
140 mir::protobuf::Void protobuf_void;140 std::unique_ptr<mir::protobuf::Void> protobuf_void;
141 141
142 std::shared_ptr<MemoryRegion> secured_region;142 std::shared_ptr<MemoryRegion> secured_region;
143 143
144144
=== added file 'src/client/make_protobuf_object.h'
--- src/client/make_protobuf_object.h 1970-01-01 00:00:00 +0000
+++ src/client/make_protobuf_object.h 2015-06-16 23:39:42 +0000
@@ -0,0 +1,42 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
17 */
18
19#ifndef MIR_CLIENT_MAKE_PROTOBUF_OBJECT_
20#define MIR_CLIENT_MAKE_PROTOBUF_OBJECT_
21
22namespace mir
23{
24namespace client
25{
26template <typename ProtobufType>
27auto make_protobuf_object()
28{
29 return std::unique_ptr<ProtobufType>{ProtobufType::default_instance().New()};
30}
31
32template <typename ProtobufType>
33auto make_protobuf_object(ProtobufType const& from)
34{
35 auto object = make_protobuf_object<ProtobufType>();
36 object->CopyFrom(from);
37 return object;
38}
39}
40}
41
42#endif
043
=== modified file 'src/client/mir_connection.cpp'
--- src/client/mir_connection.cpp 2015-06-03 17:01:43 +0000
+++ src/client/mir_connection.cpp 2015-06-16 23:39:42 +0000
@@ -20,6 +20,7 @@
20#include "mir_surface.h"20#include "mir_surface.h"
21#include "mir_prompt_session.h"21#include "mir_prompt_session.h"
22#include "default_client_buffer_stream_factory.h"22#include "default_client_buffer_stream_factory.h"
23#include "make_protobuf_object.h"
23#include "mir_toolkit/mir_platform_message.h"24#include "mir_toolkit/mir_platform_message.h"
24#include "mir/client_platform.h"25#include "mir/client_platform.h"
25#include "mir/client_platform_factory.h"26#include "mir/client_platform_factory.h"
@@ -107,7 +108,13 @@
107 server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL),108 server(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL),
108 debug(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL),109 debug(channel.get(), ::google::protobuf::Service::STUB_DOESNT_OWN_CHANNEL),
109 logger(conf.the_logger()),110 logger(conf.the_logger()),
111 void_response{mcl::make_protobuf_object<mir::protobuf::Void>()},
112 connect_result{mcl::make_protobuf_object<mir::protobuf::Connection>()},
110 connect_done{false},113 connect_done{false},
114 ignored{mcl::make_protobuf_object<mir::protobuf::Void>()},
115 connect_parameters{mcl::make_protobuf_object<mir::protobuf::ConnectParameters>()},
116 platform_operation_reply{mcl::make_protobuf_object<mir::protobuf::PlatformOperationMessage>()},
117 display_configuration_response{mcl::make_protobuf_object<mir::protobuf::DisplayConfiguration>()},
111 client_platform_factory(conf.the_client_platform_factory()),118 client_platform_factory(conf.the_client_platform_factory()),
112 input_platform(conf.the_input_platform()),119 input_platform(conf.the_input_platform()),
113 display_configuration(conf.the_display_configuration()),120 display_configuration(conf.the_display_configuration()),
@@ -116,7 +123,7 @@
116 event_handler_register(conf.the_event_handler_register()),123 event_handler_register(conf.the_event_handler_register()),
117 eventloop{new md::ThreadedDispatcher{"RPC Thread", std::dynamic_pointer_cast<md::Dispatchable>(channel)}}124 eventloop{new md::ThreadedDispatcher{"RPC Thread", std::dynamic_pointer_cast<md::Dispatchable>(channel)}}
118{125{
119 connect_result.set_error("connect not called");126 connect_result->set_error("connect not called");
120 {127 {
121 std::lock_guard<std::mutex> lock(connection_guard);128 std::lock_guard<std::mutex> lock(connection_guard);
122 next_valid = valid_connections;129 next_valid = valid_connections;
@@ -131,9 +138,9 @@
131 connect_wait_handle.wait_for_pending(std::chrono::milliseconds(500));138 connect_wait_handle.wait_for_pending(std::chrono::milliseconds(500));
132139
133 std::lock_guard<decltype(mutex)> lock(mutex);140 std::lock_guard<decltype(mutex)> lock(mutex);
134 if (connect_result.has_platform())141 if (connect_result && connect_result->has_platform())
135 {142 {
136 auto const& platform = connect_result.platform();143 auto const& platform = connect_result->platform();
137 for (int i = 0, end = platform.fd_size(); i != end; ++i)144 for (int i = 0, end = platform.fd_size(); i != end; ++i)
138 close(platform.fd(i));145 close(platform.fd(i));
139 }146 }
@@ -154,9 +161,9 @@
154{161{
155 std::lock_guard<decltype(mutex)> lock(mutex);162 std::lock_guard<decltype(mutex)> lock(mutex);
156163
157 if (connect_result.has_error())164 if (connect_result && connect_result->has_error())
158 {165 {
159 return connect_result.error().c_str();166 return connect_result->error().c_str();
160 }167 }
161168
162 return error_message.c_str();169 return error_message.c_str();
@@ -220,8 +227,8 @@
220227
221 SurfaceRelease surf_release{surface, new_wait_handle, callback, context};228 SurfaceRelease surf_release{surface, new_wait_handle, callback, context};
222229
223 mir::protobuf::SurfaceId message;230 auto message = mcl::make_protobuf_object<mir::protobuf::SurfaceId>();
224 message.set_value(surface->id());231 message->set_value(surface->id());
225232
226 {233 {
227 std::lock_guard<decltype(release_wait_handle_guard)> rel_lock(release_wait_handle_guard);234 std::lock_guard<decltype(release_wait_handle_guard)> rel_lock(release_wait_handle_guard);
@@ -229,7 +236,7 @@
229 }236 }
230237
231 new_wait_handle->expect_result();238 new_wait_handle->expect_result();
232 server.release_surface(0, &message, &void_response,239 server.release_surface(0, message.get(), void_response.get(),
233 gp::NewCallback(this, &MirConnection::released, surf_release));240 gp::NewCallback(this, &MirConnection::released, surf_release));
234241
235242
@@ -248,9 +255,9 @@
248 {255 {
249 std::lock_guard<decltype(mutex)> lock(mutex);256 std::lock_guard<decltype(mutex)> lock(mutex);
250257
251 if (!connect_result.has_platform() || !connect_result.has_display_configuration())258 if (!connect_result->has_platform() || !connect_result->has_display_configuration())
252 {259 {
253 if (!connect_result.has_error())260 if (!connect_result->has_error())
254 {261 {
255 // We're handling an error scenario that means we're not sync'd262 // We're handling an error scenario that means we're not sync'd
256 // with the client code - a callback isn't safe (or needed)263 // with the client code - a callback isn't safe (or needed)
@@ -283,12 +290,12 @@
283 buffer_stream_factory = std::make_shared<mcl::DefaultClientBufferStreamFactory>(290 buffer_stream_factory = std::make_shared<mcl::DefaultClientBufferStreamFactory>(
284 platform, the_logger());291 platform, the_logger());
285 native_display = platform->create_egl_native_display();292 native_display = platform->create_egl_native_display();
286 display_configuration->set_configuration(connect_result.display_configuration());293 display_configuration->set_configuration(connect_result->display_configuration());
287 lifecycle_control->set_lifecycle_event_handler(default_lifecycle_event_handler);294 lifecycle_control->set_lifecycle_event_handler(default_lifecycle_event_handler);
288 }295 }
289 catch (std::exception const& e)296 catch (std::exception const& e)
290 {297 {
291 connect_result.set_error(std::string{"Failed to process connect response: "} +298 connect_result->set_error(std::string{"Failed to process connect response: "} +
292 boost::diagnostic_information(e));299 boost::diagnostic_information(e));
293 }300 }
294301
@@ -304,14 +311,14 @@
304 {311 {
305 std::lock_guard<decltype(mutex)> lock(mutex);312 std::lock_guard<decltype(mutex)> lock(mutex);
306313
307 connect_parameters.set_application_name(app_name);314 connect_parameters->set_application_name(app_name);
308 connect_wait_handle.expect_result();315 connect_wait_handle.expect_result();
309 }316 }
310317
311 server.connect(318 server.connect(
312 0,319 0,
313 &connect_parameters,320 connect_parameters.get(),
314 &connect_result,321 connect_result.get(),
315 google::protobuf::NewCallback(322 google::protobuf::NewCallback(
316 this, &MirConnection::connected, callback, context));323 this, &MirConnection::connected, callback, context));
317 return &connect_wait_handle;324 return &connect_wait_handle;
@@ -339,7 +346,7 @@
339 disconnecting = true;346 disconnecting = true;
340 }347 }
341 disconnect_wait_handle.expect_result();348 disconnect_wait_handle.expect_result();
342 server.disconnect(0, &ignored, &ignored,349 server.disconnect(0, ignored.get(), ignored.get(),
343 google::protobuf::NewCallback(this, &MirConnection::done_disconnect));350 google::protobuf::NewCallback(this, &MirConnection::done_disconnect));
344351
345 return &disconnect_wait_handle;352 return &disconnect_wait_handle;
@@ -348,19 +355,19 @@
348void MirConnection::done_platform_operation(355void MirConnection::done_platform_operation(
349 mir_platform_operation_callback callback, void* context)356 mir_platform_operation_callback callback, void* context)
350{357{
351 auto reply = mir_platform_message_create(platform_operation_reply.opcode());358 auto reply = mir_platform_message_create(platform_operation_reply->opcode());
352359
353 set_error_message(platform_operation_reply.error());360 set_error_message(platform_operation_reply->error());
354361
355 mir_platform_message_set_data(362 mir_platform_message_set_data(
356 reply,363 reply,
357 platform_operation_reply.data().data(),364 platform_operation_reply->data().data(),
358 platform_operation_reply.data().size());365 platform_operation_reply->data().size());
359366
360 mir_platform_message_set_fds(367 mir_platform_message_set_fds(
361 reply,368 reply,
362 platform_operation_reply.fd().data(),369 platform_operation_reply->fd().data(),
363 platform_operation_reply.fd().size());370 platform_operation_reply->fd().size());
364371
365 callback(this, reply, context);372 callback(this, reply, context);
366373
@@ -379,21 +386,21 @@
379 return nullptr;386 return nullptr;
380 }387 }
381388
382 mir::protobuf::PlatformOperationMessage protobuf_request;389 auto protobuf_request = mcl::make_protobuf_object<mir::protobuf::PlatformOperationMessage>();
383390
384 protobuf_request.set_opcode(mir_platform_message_get_opcode(request));391 protobuf_request->set_opcode(mir_platform_message_get_opcode(request));
385 auto const request_data = mir_platform_message_get_data(request);392 auto const request_data = mir_platform_message_get_data(request);
386 auto const request_fds = mir_platform_message_get_fds(request);393 auto const request_fds = mir_platform_message_get_fds(request);
387394
388 protobuf_request.set_data(request_data.data, request_data.size);395 protobuf_request->set_data(request_data.data, request_data.size);
389 for (size_t i = 0; i != request_fds.num_fds; ++i)396 for (size_t i = 0; i != request_fds.num_fds; ++i)
390 protobuf_request.add_fd(request_fds.fds[i]);397 protobuf_request->add_fd(request_fds.fds[i]);
391398
392 platform_operation_wait_handle.expect_result();399 platform_operation_wait_handle.expect_result();
393 server.platform_operation(400 server.platform_operation(
394 0,401 0,
395 &protobuf_request,402 protobuf_request.get(),
396 &platform_operation_reply,403 platform_operation_reply.get(),
397 google::protobuf::NewCallback(this, &MirConnection::done_platform_operation,404 google::protobuf::NewCallback(this, &MirConnection::done_platform_operation,
398 callback, context));405 callback, context));
399406
@@ -411,7 +418,7 @@
411 {418 {
412 lock.unlock();419 lock.unlock();
413 std::lock_guard<decltype(connection->mutex)> lock(connection->mutex);420 std::lock_guard<decltype(connection->mutex)> lock(connection->mutex);
414 return !connection->connect_result.has_error();421 return !connection->connect_result->has_error();
415 }422 }
416 }423 }
417 }424 }
@@ -427,9 +434,9 @@
427{434{
428 // connect_result is write-once: once it's valid, we don't need to lock435 // connect_result is write-once: once it's valid, we don't need to lock
429 // to use it.436 // to use it.
430 if (connect_done && !connect_result.has_error() && connect_result.has_platform())437 if (connect_done && !connect_result->has_error() && connect_result->has_platform())
431 {438 {
432 auto const& platform = connect_result.platform();439 auto const& platform = connect_result->platform();
433440
434 platform_package.data_items = platform.data_size();441 platform_package.data_items = platform.data_size();
435 for (int i = 0; i != platform.data_size(); ++i)442 for (int i = 0; i != platform.data_size(); ++i)
@@ -460,15 +467,15 @@
460 valid_formats = 0;467 valid_formats = 0;
461468
462 std::lock_guard<decltype(mutex)> lock(mutex);469 std::lock_guard<decltype(mutex)> lock(mutex);
463 if (!connect_result.has_error())470 if (!connect_result->has_error())
464 {471 {
465 valid_formats = std::min(472 valid_formats = std::min(
466 static_cast<unsigned int>(connect_result.surface_pixel_format_size()),473 static_cast<unsigned int>(connect_result->surface_pixel_format_size()),
467 formats_size);474 formats_size);
468475
469 for (auto i = 0u; i < valid_formats; i++)476 for (auto i = 0u; i < valid_formats; i++)
470 {477 {
471 formats[i] = static_cast<MirPixelFormat>(connect_result.surface_pixel_format(i));478 formats[i] = static_cast<MirPixelFormat>(connect_result->surface_pixel_format(i));
472 }479 }
473 }480 }
474}481}
@@ -488,13 +495,13 @@
488 mir_buffer_stream_callback callback,495 mir_buffer_stream_callback callback,
489 void *context)496 void *context)
490{497{
491 mir::protobuf::BufferStreamParameters params;498 auto params = mcl::make_protobuf_object<mir::protobuf::BufferStreamParameters>();
492 params.set_width(width);499 params->set_width(width);
493 params.set_height(height);500 params->set_height(height);
494 params.set_pixel_format(format);501 params->set_pixel_format(format);
495 params.set_buffer_usage(buffer_usage);502 params->set_buffer_usage(buffer_usage);
496503
497 return buffer_stream_factory->make_producer_stream(this, server, params, callback, context);504 return buffer_stream_factory->make_producer_stream(this, server, *params, callback, context);
498}505}
499506
500std::shared_ptr<mir::client::ClientBufferStream> MirConnection::make_consumer_stream(507std::shared_ptr<mir::client::ClientBufferStream> MirConnection::make_consumer_stream(
@@ -559,10 +566,10 @@
559{566{
560 std::lock_guard<decltype(mutex)> lock(mutex);567 std::lock_guard<decltype(mutex)> lock(mutex);
561568
562 set_error_message(display_configuration_response.error());569 set_error_message(display_configuration_response->error());
563570
564 if (!display_configuration_response.has_error())571 if (!display_configuration_response->has_error())
565 display_configuration->set_configuration(display_configuration_response);572 display_configuration->set_configuration(*display_configuration_response);
566573
567 return configure_display_wait_handle.result_received();574 return configure_display_wait_handle.result_received();
568}575}
@@ -574,14 +581,14 @@
574 return NULL;581 return NULL;
575 }582 }
576583
577 mir::protobuf::DisplayConfiguration request;584 auto request = mcl::make_protobuf_object<mir::protobuf::DisplayConfiguration>();
578 {585 {
579 std::lock_guard<decltype(mutex)> lock(mutex);586 std::lock_guard<decltype(mutex)> lock(mutex);
580587
581 for (auto i=0u; i < config->num_outputs; i++)588 for (auto i=0u; i < config->num_outputs; i++)
582 {589 {
583 auto output = config->outputs[i];590 auto output = config->outputs[i];
584 auto display_request = request.add_display_output();591 auto display_request = request->add_display_output();
585 display_request->set_output_id(output.output_id);592 display_request->set_output_id(output.output_id);
586 display_request->set_used(output.used);593 display_request->set_used(output.used);
587 display_request->set_current_mode(output.current_mode);594 display_request->set_current_mode(output.current_mode);
@@ -594,7 +601,7 @@
594 }601 }
595602
596 configure_display_wait_handle.expect_result();603 configure_display_wait_handle.expect_result();
597 server.configure_display(0, &request, &display_configuration_response,604 server.configure_display(0, request.get(), display_configuration_response.get(),
598 google::protobuf::NewCallback(this, &MirConnection::done_display_configure));605 google::protobuf::NewCallback(this, &MirConnection::done_display_configure));
599606
600 return &configure_display_wait_handle;607 return &configure_display_wait_handle;
@@ -619,8 +626,8 @@
619626
620 StreamRelease stream_release{stream, new_wait_handle, callback, context};627 StreamRelease stream_release{stream, new_wait_handle, callback, context};
621628
622 mir::protobuf::BufferStreamId buffer_stream_id;629 auto buffer_stream_id = mcl::make_protobuf_object<mir::protobuf::BufferStreamId>();
623 buffer_stream_id.set_value(stream->rpc_id().as_value());630 buffer_stream_id->set_value(stream->rpc_id().as_value());
624631
625 {632 {
626 std::lock_guard<decltype(release_wait_handle_guard)> rel_lock(release_wait_handle_guard);633 std::lock_guard<decltype(release_wait_handle_guard)> rel_lock(release_wait_handle_guard);
@@ -629,7 +636,7 @@
629636
630 new_wait_handle->expect_result();637 new_wait_handle->expect_result();
631 server.release_buffer_stream(638 server.release_buffer_stream(
632 nullptr, &buffer_stream_id, &void_response,639 nullptr, buffer_stream_id.get(), void_response.get(),
633 google::protobuf::NewCallback(this, &MirConnection::released, stream_release));640 google::protobuf::NewCallback(this, &MirConnection::released, stream_release));
634 return new_wait_handle;641 return new_wait_handle;
635}642}
636643
=== modified file 'src/client/mir_connection.h'
--- src/client/mir_connection.h 2015-06-03 17:01:43 +0000
+++ src/client/mir_connection.h 2015-06-16 23:39:42 +0000
@@ -35,6 +35,8 @@
3535
36#include "mir_wait_handle.h"36#include "mir_wait_handle.h"
3737
38#include <memory>
39
38namespace mir40namespace mir
39{41{
40class SharedLibrary;42class SharedLibrary;
@@ -172,13 +174,13 @@
172 mir::protobuf::DisplayServer::Stub server;174 mir::protobuf::DisplayServer::Stub server;
173 mir::protobuf::Debug::Stub debug;175 mir::protobuf::Debug::Stub debug;
174 std::shared_ptr<mir::logging::Logger> const logger;176 std::shared_ptr<mir::logging::Logger> const logger;
175 mir::protobuf::Void void_response;177 std::unique_ptr<mir::protobuf::Void> void_response;
176 mir::protobuf::Connection connect_result;178 std::unique_ptr<mir::protobuf::Connection> connect_result;
177 std::atomic<bool> connect_done;179 std::atomic<bool> connect_done;
178 mir::protobuf::Void ignored;180 std::unique_ptr<mir::protobuf::Void> ignored;
179 mir::protobuf::ConnectParameters connect_parameters;181 std::unique_ptr<mir::protobuf::ConnectParameters> connect_parameters;
180 mir::protobuf::PlatformOperationMessage platform_operation_reply;182 std::unique_ptr<mir::protobuf::PlatformOperationMessage> platform_operation_reply;
181 mir::protobuf::DisplayConfiguration display_configuration_response;183 std::unique_ptr<mir::protobuf::DisplayConfiguration> display_configuration_response;
182 std::atomic<bool> disconnecting{false};184 std::atomic<bool> disconnecting{false};
183185
184 std::shared_ptr<mir::client::ClientPlatformFactory> const client_platform_factory;186 std::shared_ptr<mir::client::ClientPlatformFactory> const client_platform_factory;
185187
=== modified file 'src/client/mir_prompt_session.cpp'
--- src/client/mir_prompt_session.cpp 2015-03-31 02:35:42 +0000
+++ src/client/mir_prompt_session.cpp 2015-06-16 23:39:42 +0000
@@ -18,6 +18,7 @@
1818
19#include "mir_prompt_session.h"19#include "mir_prompt_session.h"
20#include "event_handler_register.h"20#include "event_handler_register.h"
21#include "make_protobuf_object.h"
2122
22namespace mp = mir::protobuf;23namespace mp = mir::protobuf;
23namespace mcl = mir::client;24namespace mcl = mir::client;
@@ -26,6 +27,10 @@
26 mp::DisplayServer& server,27 mp::DisplayServer& server,
27 std::shared_ptr<mcl::EventHandlerRegister> const& event_handler_register) :28 std::shared_ptr<mcl::EventHandlerRegister> const& event_handler_register) :
28 server(server),29 server(server),
30 parameters(mcl::make_protobuf_object<mir::protobuf::PromptSessionParameters>()),
31 add_result(mcl::make_protobuf_object<mir::protobuf::Void>()),
32 protobuf_void(mcl::make_protobuf_object<mir::protobuf::Void>()),
33 socket_fd_response(mcl::make_protobuf_object<mir::protobuf::SocketFD>()),
29 event_handler_register(event_handler_register),34 event_handler_register(event_handler_register),
30 event_handler_register_id{event_handler_register->register_event_handler(35 event_handler_register_id{event_handler_register->register_event_handler(
31 [this](MirEvent const& event)36 [this](MirEvent const& event)
@@ -34,6 +39,7 @@
34 set_state(mir_prompt_session_event_get_state(mir_event_get_prompt_session_event(&event)));39 set_state(mir_prompt_session_event_get_state(mir_event_get_prompt_session_event(&event)));
35 })},40 })},
36 state(mir_prompt_session_state_stopped),41 state(mir_prompt_session_state_stopped),
42 session(mcl::make_protobuf_object<mir::protobuf::Void>()),
37 handle_prompt_session_state_change{[](MirPromptSessionState){}}43 handle_prompt_session_state_change{[](MirPromptSessionState){}}
38{44{
39}45}
@@ -64,14 +70,14 @@
64{70{
65 {71 {
66 std::lock_guard<decltype(mutex)> lock(mutex);72 std::lock_guard<decltype(mutex)> lock(mutex);
67 parameters.set_application_pid(application_pid);73 parameters->set_application_pid(application_pid);
68 }74 }
6975
70 start_wait_handle.expect_result();76 start_wait_handle.expect_result();
71 server.start_prompt_session(77 server.start_prompt_session(
72 0,78 0,
73 &parameters,79 parameters.get(),
74 &session,80 session.get(),
75 google::protobuf::NewCallback(this, &MirPromptSession::done_start,81 google::protobuf::NewCallback(this, &MirPromptSession::done_start,
76 callback, context));82 callback, context));
7783
@@ -84,8 +90,8 @@
8490
85 server.stop_prompt_session(91 server.stop_prompt_session(
86 0,92 0,
87 &protobuf_void,93 protobuf_void.get(),
88 &protobuf_void,94 protobuf_void.get(),
89 google::protobuf::NewCallback(this, &MirPromptSession::done_stop,95 google::protobuf::NewCallback(this, &MirPromptSession::done_stop,
90 callback, context));96 callback, context));
9197
@@ -110,7 +116,7 @@
110 {116 {
111 std::lock_guard<decltype(session_mutex)> lock(session_mutex);117 std::lock_guard<decltype(session_mutex)> lock(session_mutex);
112118
113 state = session.has_error() ? mir_prompt_session_state_stopped : mir_prompt_session_state_started;119 state = session->has_error() ? mir_prompt_session_state_stopped : mir_prompt_session_state_started;
114 }120 }
115121
116 callback(this, context);122 callback(this, context);
@@ -129,10 +135,10 @@
129{135{
130 std::lock_guard<decltype(session_mutex)> lock(session_mutex);136 std::lock_guard<decltype(session_mutex)> lock(session_mutex);
131137
132 if (!session.has_error())138 if (!session->has_error())
133 session.set_error(std::string{});139 session->set_error(std::string{});
134140
135 return session.error().c_str();141 return session->error().c_str();
136}142}
137143
138MirWaitHandle* MirPromptSession::new_fds_for_prompt_providers(144MirWaitHandle* MirPromptSession::new_fds_for_prompt_providers(
@@ -140,15 +146,15 @@
140 mir_client_fd_callback callback,146 mir_client_fd_callback callback,
141 void * context)147 void * context)
142{148{
143 mir::protobuf::SocketFDRequest request;149 auto request = mcl::make_protobuf_object<mir::protobuf::SocketFDRequest>();
144 request.set_number(no_of_fds);150 request->set_number(no_of_fds);
145151
146 fds_for_prompt_providers_wait_handle.expect_result();152 fds_for_prompt_providers_wait_handle.expect_result();
147153
148 server.new_fds_for_prompt_providers(154 server.new_fds_for_prompt_providers(
149 nullptr,155 nullptr,
150 &request,156 request.get(),
151 &socket_fd_response,157 socket_fd_response.get(),
152 google::protobuf::NewCallback(this, &MirPromptSession::done_fds_for_prompt_providers,158 google::protobuf::NewCallback(this, &MirPromptSession::done_fds_for_prompt_providers,
153 callback, context));159 callback, context));
154160
@@ -159,13 +165,13 @@
159 mir_client_fd_callback callback,165 mir_client_fd_callback callback,
160 void* context)166 void* context)
161{167{
162 auto const size = socket_fd_response.fd_size();168 auto const size = socket_fd_response->fd_size();
163169
164 std::vector<int> fds;170 std::vector<int> fds;
165 fds.reserve(size);171 fds.reserve(size);
166172
167 for (auto i = 0; i != size; ++i)173 for (auto i = 0; i != size; ++i)
168 fds.push_back(socket_fd_response.fd(i));174 fds.push_back(socket_fd_response->fd(i));
169175
170 callback(this, size, fds.data(), context);176 callback(this, size, fds.data(), context);
171 fds_for_prompt_providers_wait_handle.result_received();177 fds_for_prompt_providers_wait_handle.result_received();
172178
=== modified file 'src/client/mir_prompt_session.h'
--- src/client/mir_prompt_session.h 2015-01-21 07:34:50 +0000
+++ src/client/mir_prompt_session.h 2015-06-16 23:39:42 +0000
@@ -60,10 +60,10 @@
60private:60private:
61 std::mutex mutable mutex; // Protects parameters, wait_handles & results61 std::mutex mutable mutex; // Protects parameters, wait_handles & results
62 mir::protobuf::DisplayServer& server;62 mir::protobuf::DisplayServer& server;
63 mir::protobuf::PromptSessionParameters parameters;63 std::unique_ptr<mir::protobuf::PromptSessionParameters> parameters;
64 mir::protobuf::Void add_result;64 std::unique_ptr<mir::protobuf::Void> add_result;
65 mir::protobuf::Void protobuf_void;65 std::unique_ptr<mir::protobuf::Void> protobuf_void;
66 mir::protobuf::SocketFD socket_fd_response;66 std::unique_ptr<mir::protobuf::SocketFD> socket_fd_response;
67 std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register;67 std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register;
68 int const event_handler_register_id;68 int const event_handler_register_id;
6969
@@ -73,7 +73,7 @@
73 std::atomic<MirPromptSessionState> state;73 std::atomic<MirPromptSessionState> state;
7474
75 std::mutex mutable session_mutex; // Protects session75 std::mutex mutable session_mutex; // Protects session
76 mir::protobuf::Void session;76 std::unique_ptr<mir::protobuf::Void> session;
7777
78 std::mutex mutable event_handler_mutex; // Need another mutex for callback access to members78 std::mutex mutable event_handler_mutex; // Need another mutex for callback access to members
79 std::function<void(MirPromptSessionState)> handle_prompt_session_state_change;79 std::function<void(MirPromptSessionState)> handle_prompt_session_state_change;
8080
=== modified file 'src/client/mir_screencast.cpp'
--- src/client/mir_screencast.cpp 2015-06-03 17:35:29 +0000
+++ src/client/mir_screencast.cpp 2015-06-16 23:39:42 +0000
@@ -18,6 +18,7 @@
1818
19#include "mir_screencast.h"19#include "mir_screencast.h"
20#include "mir_connection.h"20#include "mir_connection.h"
21#include "make_protobuf_object.h"
21#include "client_buffer_stream.h"22#include "client_buffer_stream.h"
22#include "mir/frontend/client_constants.h"23#include "mir/frontend/client_constants.h"
23#include "mir_toolkit/mir_native_buffer.h"24#include "mir_toolkit/mir_native_buffer.h"
@@ -38,7 +39,9 @@
38 mir_screencast_callback callback, void* context)39 mir_screencast_callback callback, void* context)
39 : server(server),40 : server(server),
40 connection{connection},41 connection{connection},
41 output_size{size}42 output_size{size},
43 protobuf_screencast{mcl::make_protobuf_object<mir::protobuf::Screencast>()},
44 protobuf_void{mcl::make_protobuf_object<mir::protobuf::Void>()}
42{45{
43 if (output_size.width.as_int() == 0 ||46 if (output_size.width.as_int() == 0 ||
44 output_size.height.as_int() == 0 ||47 output_size.height.as_int() == 0 ||
@@ -48,23 +51,23 @@
48 {51 {
49 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid parameters"));52 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid parameters"));
50 }53 }
51 protobuf_screencast.set_error("Not initialized");54 protobuf_screencast->set_error("Not initialized");
5255
53 mir::protobuf::ScreencastParameters parameters;56 auto parameters = mcl::make_protobuf_object<mir::protobuf::ScreencastParameters>();
5457
55 parameters.mutable_region()->set_left(region.top_left.x.as_int());58 parameters->mutable_region()->set_left(region.top_left.x.as_int());
56 parameters.mutable_region()->set_top(region.top_left.y.as_int());59 parameters->mutable_region()->set_top(region.top_left.y.as_int());
57 parameters.mutable_region()->set_width(region.size.width.as_uint32_t());60 parameters->mutable_region()->set_width(region.size.width.as_uint32_t());
58 parameters.mutable_region()->set_height(region.size.height.as_uint32_t());61 parameters->mutable_region()->set_height(region.size.height.as_uint32_t());
59 parameters.set_width(output_size.width.as_uint32_t());62 parameters->set_width(output_size.width.as_uint32_t());
60 parameters.set_height(output_size.height.as_uint32_t());63 parameters->set_height(output_size.height.as_uint32_t());
61 parameters.set_pixel_format(pixel_format);64 parameters->set_pixel_format(pixel_format);
6265
63 create_screencast_wait_handle.expect_result();66 create_screencast_wait_handle.expect_result();
64 server.create_screencast(67 server.create_screencast(
65 nullptr,68 nullptr,
66 &parameters,69 parameters.get(),
67 &protobuf_screencast,70 protobuf_screencast.get(),
68 google::protobuf::NewCallback(71 google::protobuf::NewCallback(
69 this, &MirScreencast::screencast_created,72 this, &MirScreencast::screencast_created,
70 callback, context));73 callback, context));
@@ -77,20 +80,20 @@
7780
78bool MirScreencast::valid()81bool MirScreencast::valid()
79{82{
80 return !protobuf_screencast.has_error();83 return !protobuf_screencast->has_error();
81}84}
8285
83MirWaitHandle* MirScreencast::release(86MirWaitHandle* MirScreencast::release(
84 mir_screencast_callback callback, void* context)87 mir_screencast_callback callback, void* context)
85{88{
86 mir::protobuf::ScreencastId screencast_id;89 auto screencast_id = mcl::make_protobuf_object<mir::protobuf::ScreencastId>();
87 screencast_id.set_value(protobuf_screencast.screencast_id().value());90 screencast_id->set_value(protobuf_screencast->screencast_id().value());
88 91
89 release_wait_handle.expect_result();92 release_wait_handle.expect_result();
90 server.release_screencast(93 server.release_screencast(
91 nullptr,94 nullptr,
92 &screencast_id,95 screencast_id.get(),
93 &protobuf_void,96 protobuf_void.get(),
94 google::protobuf::NewCallback(97 google::protobuf::NewCallback(
95 this, &MirScreencast::released, callback, context));98 this, &MirScreencast::released, callback, context));
9699
@@ -104,10 +107,10 @@
104void MirScreencast::screencast_created(107void MirScreencast::screencast_created(
105 mir_screencast_callback callback, void* context)108 mir_screencast_callback callback, void* context)
106{109{
107 if (!protobuf_screencast.has_error() && connection)110 if (!protobuf_screencast->has_error() && connection)
108 {111 {
109 buffer_stream = connection->make_consumer_stream(112 buffer_stream = connection->make_consumer_stream(
110 protobuf_screencast.buffer_stream(), "MirScreencast");113 protobuf_screencast->buffer_stream(), "MirScreencast");
111 }114 }
112115
113 callback(this, context);116 callback(this, context);
114117
=== modified file 'src/client/mir_screencast.h'
--- src/client/mir_screencast.h 2015-06-03 17:35:29 +0000
+++ src/client/mir_screencast.h 2015-06-16 23:39:42 +0000
@@ -27,6 +27,8 @@
2727
28#include <EGL/eglplatform.h>28#include <EGL/eglplatform.h>
2929
30#include <memory>
31
30namespace mir32namespace mir
31{33{
32namespace protobuf { class DisplayServer; }34namespace protobuf { class DisplayServer; }
@@ -71,8 +73,8 @@
71 mir::geometry::Size const output_size;73 mir::geometry::Size const output_size;
72 std::shared_ptr<mir::client::ClientBufferStream> buffer_stream;74 std::shared_ptr<mir::client::ClientBufferStream> buffer_stream;
7375
74 mir::protobuf::Screencast protobuf_screencast;76 std::unique_ptr<mir::protobuf::Screencast> protobuf_screencast;
75 mir::protobuf::Void protobuf_void;77 std::unique_ptr<mir::protobuf::Void> protobuf_void;
7678
77 MirWaitHandle create_screencast_wait_handle;79 MirWaitHandle create_screencast_wait_handle;
78 MirWaitHandle release_wait_handle;80 MirWaitHandle release_wait_handle;
7981
=== modified file 'src/client/mir_surface.cpp'
--- src/client/mir_surface.cpp 2015-06-16 12:18:54 +0000
+++ src/client/mir_surface.cpp 2015-06-16 23:39:42 +0000
@@ -16,12 +16,13 @@
16 * Authored by: Thomas Guest <thomas.guest@canonical.com>16 * Authored by: Thomas Guest <thomas.guest@canonical.com>
17 */17 */
1818
19#include "mir_surface.h"
20#include "cursor_configuration.h"
21#include "client_buffer_stream_factory.h"
22#include "make_protobuf_object.h"
19#include "mir_toolkit/mir_client_library.h"23#include "mir_toolkit/mir_client_library.h"
20#include "mir/frontend/client_constants.h"24#include "mir/frontend/client_constants.h"
21#include "mir/client_buffer.h"25#include "mir/client_buffer.h"
22#include "mir_surface.h"
23#include "cursor_configuration.h"
24#include "client_buffer_stream_factory.h"
25#include "mir_connection.h"26#include "mir_connection.h"
26#include "client_buffer_stream.h"27#include "client_buffer_stream.h"
27#include "mir/dispatch/threaded_dispatcher.h"28#include "mir/dispatch/threaded_dispatcher.h"
@@ -42,7 +43,7 @@
4243
43#define SERIALIZE_OPTION_IF_SET(option, message) \44#define SERIALIZE_OPTION_IF_SET(option, message) \
44 if (option.is_set()) \45 if (option.is_set()) \
45 message.set_##option(option.value());46 message->set_##option(option.value());
4647
47namespace48namespace
48{49{
@@ -79,9 +80,10 @@
79{80{
80}81}
8182
82mir::protobuf::SurfaceParameters MirSurfaceSpec::serialize() const83std::unique_ptr<mir::protobuf::SurfaceParameters> MirSurfaceSpec::serialize() const
83{84{
84 mir::protobuf::SurfaceParameters message;85 //std::unique_ptr<mp::SurfaceParameters> message{mp::SurfaceParameters::default_instance().New()};
86 auto message = mcl::make_protobuf_object<mp::SurfaceParameters>();
8587
86 SERIALIZE_OPTION_IF_SET(width, message);88 SERIALIZE_OPTION_IF_SET(width, message);
87 SERIALIZE_OPTION_IF_SET(height, message);89 SERIALIZE_OPTION_IF_SET(height, message);
@@ -103,26 +105,26 @@
103 // max_aspect is a special case (below)105 // max_aspect is a special case (below)
104106
105 if (parent.is_set() && parent.value() != nullptr)107 if (parent.is_set() && parent.value() != nullptr)
106 message.set_parent_id(parent.value()->id());108 message->set_parent_id(parent.value()->id());
107109
108 if (aux_rect.is_set())110 if (aux_rect.is_set())
109 {111 {
110 message.mutable_aux_rect()->set_left(aux_rect.value().left);112 message->mutable_aux_rect()->set_left(aux_rect.value().left);
111 message.mutable_aux_rect()->set_top(aux_rect.value().top);113 message->mutable_aux_rect()->set_top(aux_rect.value().top);
112 message.mutable_aux_rect()->set_width(aux_rect.value().width);114 message->mutable_aux_rect()->set_width(aux_rect.value().width);
113 message.mutable_aux_rect()->set_height(aux_rect.value().height);115 message->mutable_aux_rect()->set_height(aux_rect.value().height);
114 }116 }
115117
116 if (min_aspect.is_set())118 if (min_aspect.is_set())
117 {119 {
118 message.mutable_min_aspect()->set_width(min_aspect.value().width);120 message->mutable_min_aspect()->set_width(min_aspect.value().width);
119 message.mutable_min_aspect()->set_height(min_aspect.value().height);121 message->mutable_min_aspect()->set_height(min_aspect.value().height);
120 }122 }
121123
122 if (max_aspect.is_set())124 if (max_aspect.is_set())
123 {125 {
124 message.mutable_max_aspect()->set_width(max_aspect.value().width);126 message->mutable_max_aspect()->set_width(max_aspect.value().width);
125 message.mutable_max_aspect()->set_height(max_aspect.value().height);127 message->mutable_max_aspect()->set_height(max_aspect.value().height);
126 }128 }
127129
128 return message;130 return message;
@@ -139,8 +141,9 @@
139}141}
140142
141MirSurface::MirSurface(std::string const& error)143MirSurface::MirSurface(std::string const& error)
144 : surface{mcl::make_protobuf_object<mir::protobuf::Surface>()}
142{145{
143 surface.set_error(error);146 surface->set_error(error);
144147
145 std::lock_guard<decltype(handle_mutex)> lock(handle_mutex);148 std::lock_guard<decltype(handle_mutex)> lock(handle_mutex);
146 valid_surfaces.insert(this);149 valid_surfaces.insert(this);
@@ -156,11 +159,16 @@
156 mir_surface_callback callback, void * context)159 mir_surface_callback callback, void * context)
157 : server{&the_server},160 : server{&the_server},
158 debug{debug},161 debug{debug},
162 surface{mcl::make_protobuf_object<mir::protobuf::Surface>()},
163 persistent_id{mcl::make_protobuf_object<mir::protobuf::PersistentSurfaceId>()},
159 name{spec.surface_name.is_set() ? spec.surface_name.value() : ""},164 name{spec.surface_name.is_set() ? spec.surface_name.value() : ""},
165 void_response{mcl::make_protobuf_object<mir::protobuf::Void>()},
166 modify_result{mcl::make_protobuf_object<mir::protobuf::Void>()},
160 connection(allocating_connection),167 connection(allocating_connection),
161 buffer_stream_factory(buffer_stream_factory),168 buffer_stream_factory(buffer_stream_factory),
162 input_platform(input_platform),169 input_platform(input_platform),
163 keymapper(std::make_shared<mircv::XKBMapper>())170 keymapper(std::make_shared<mircv::XKBMapper>()),
171 configure_result{mcl::make_protobuf_object<mir::protobuf::SurfaceSetting>()}
164{172{
165 for (int i = 0; i < mir_surface_attribs; i++)173 for (int i = 0; i < mir_surface_attribs; i++)
166 attrib_cache[i] = -1;174 attrib_cache[i] = -1;
@@ -169,11 +177,11 @@
169 create_wait_handle.expect_result();177 create_wait_handle.expect_result();
170 try 178 try
171 {179 {
172 server->create_surface(0, &message, &surface, gp::NewCallback(this, &MirSurface::created, callback, context));180 server->create_surface(0, message.get(), surface.get(), gp::NewCallback(this, &MirSurface::created, callback, context));
173 }181 }
174 catch (std::exception const& ex)182 catch (std::exception const& ex)
175 {183 {
176 surface.set_error(std::string{"Error invoking create surface: "} +184 surface->set_error(std::string{"Error invoking create surface: "} +
177 boost::diagnostic_information(ex));185 boost::diagnostic_information(ex));
178 }186 }
179187
@@ -192,8 +200,8 @@
192200
193 input_thread.reset();201 input_thread.reset();
194202
195 for (auto i = 0, end = surface.fd_size(); i != end; ++i)203 for (auto i = 0, end = surface->fd_size(); i != end; ++i)
196 close(surface.fd(i));204 close(surface->fd(i));
197}205}
198206
199MirSurfaceParameters MirSurface::get_parameters() const207MirSurfaceParameters MirSurface::get_parameters() const
@@ -207,9 +215,9 @@
207{215{
208 std::lock_guard<decltype(mutex)> lock(mutex);216 std::lock_guard<decltype(mutex)> lock(mutex);
209217
210 if (surface.has_error())218 if (surface->has_error())
211 {219 {
212 return surface.error().c_str();220 return surface->error().c_str();
213 }221 }
214 return error_message.c_str();222 return error_message.c_str();
215}223}
@@ -218,7 +226,7 @@
218{226{
219 std::lock_guard<decltype(mutex)> lock(mutex);227 std::lock_guard<decltype(mutex)> lock(mutex);
220228
221 return surface.id().value();229 return surface->id().value();
222}230}
223231
224bool MirSurface::is_valid(MirSurface* query)232bool MirSurface::is_valid(MirSurface* query)
@@ -226,16 +234,16 @@
226 std::lock_guard<decltype(handle_mutex)> lock(handle_mutex);234 std::lock_guard<decltype(handle_mutex)> lock(handle_mutex);
227235
228 if (valid_surfaces.count(query))236 if (valid_surfaces.count(query))
229 return !query->surface.has_error();237 return !query->surface->has_error();
230238
231 return false;239 return false;
232}240}
233241
234void MirSurface::acquired_persistent_id(mir_surface_id_callback callback, void* context)242void MirSurface::acquired_persistent_id(mir_surface_id_callback callback, void* context)
235{243{
236 if (!persistent_id.has_error())244 if (!persistent_id->has_error())
237 {245 {
238 callback(this, new MirPersistentId{persistent_id.value()}, context);246 callback(this, new MirPersistentId{persistent_id->value()}, context);
239 }247 }
240 else248 else
241 {249 {
@@ -248,20 +256,20 @@
248{256{
249 std::lock_guard<decltype(mutex)> lock{mutex};257 std::lock_guard<decltype(mutex)> lock{mutex};
250258
251 if (persistent_id.has_value())259 if (persistent_id->has_value())
252 {260 {
253 callback(this, new MirPersistentId{persistent_id.value()}, context);261 callback(this, new MirPersistentId{persistent_id->value()}, context);
254 return nullptr;262 return nullptr;
255 }263 }
256264
257 persistent_id_wait_handle.expect_result();265 persistent_id_wait_handle.expect_result();
258 try266 try
259 {267 {
260 server->request_persistent_surface_id(0, &surface.id(), &persistent_id, gp::NewCallback(this, &MirSurface::acquired_persistent_id, callback, context));268 server->request_persistent_surface_id(0, &surface->id(), persistent_id.get(), gp::NewCallback(this, &MirSurface::acquired_persistent_id, callback, context));
261 }269 }
262 catch (std::exception const& ex)270 catch (std::exception const& ex)
263 {271 {
264 surface.set_error(std::string{"Failed to acquire a persistent ID from the server: "} +272 surface->set_error(std::string{"Failed to acquire a persistent ID from the server: "} +
265 boost::diagnostic_information(ex));273 boost::diagnostic_information(ex));
266 }274 }
267 return &persistent_id_wait_handle;275 return &persistent_id_wait_handle;
@@ -283,10 +291,10 @@
283{291{
284 {292 {
285 std::lock_guard<decltype(mutex)> lock(mutex);293 std::lock_guard<decltype(mutex)> lock(mutex);
286 if (!surface.has_id())294 if (!surface->has_id())
287 {295 {
288 if (!surface.has_error())296 if (!surface->has_error())
289 surface.set_error("Error processing surface create response, no ID (disconnected?)");297 surface->set_error("Error processing surface create response, no ID (disconnected?)");
290298
291 callback(this, context);299 callback(this, context);
292 create_wait_handle.result_received();300 create_wait_handle.result_received();
@@ -299,11 +307,11 @@
299 std::lock_guard<decltype(mutex)> lock(mutex);307 std::lock_guard<decltype(mutex)> lock(mutex);
300308
301 buffer_stream = buffer_stream_factory->309 buffer_stream = buffer_stream_factory->
302 make_producer_stream(connection, *server, surface.buffer_stream(), name);310 make_producer_stream(connection, *server, surface->buffer_stream(), name);
303311
304 for(int i = 0; i < surface.attributes_size(); i++)312 for(int i = 0; i < surface->attributes_size(); i++)
305 {313 {
306 auto const& attrib = surface.attributes(i);314 auto const& attrib = surface->attributes(i);
307 attrib_cache[attrib.attrib()] = attrib.ivalue();315 attrib_cache[attrib.attrib()] = attrib.ivalue();
308 }316 }
309 }317 }
@@ -312,7 +320,7 @@
312 }320 }
313 catch (std::exception const& error)321 catch (std::exception const& error)
314 {322 {
315 surface.set_error(std::string{"Error processing Surface creating response:"} +323 surface->set_error(std::string{"Error processing Surface creating response:"} +
316 boost::diagnostic_information(error));324 boost::diagnostic_information(error));
317 }325 }
318326
@@ -331,7 +339,7 @@
331 was_valid = true;339 was_valid = true;
332 valid_surfaces.erase(this);340 valid_surfaces.erase(this);
333 }341 }
334 if (this->surface.has_error())342 if (this->surface->has_error())
335 was_valid = false;343 was_valid = false;
336344
337 MirWaitHandle* wait_handle{nullptr};345 MirWaitHandle* wait_handle{nullptr};
@@ -350,29 +358,28 @@
350358
351MirWaitHandle* MirSurface::configure_cursor(MirCursorConfiguration const* cursor)359MirWaitHandle* MirSurface::configure_cursor(MirCursorConfiguration const* cursor)
352{360{
353 mp::CursorSetting setting;361 auto setting = mcl::make_protobuf_object<mp::CursorSetting>();
354362
355 {363 {
356 std::unique_lock<decltype(mutex)> lock(mutex);364 std::unique_lock<decltype(mutex)> lock(mutex);
357 setting.mutable_surfaceid()->CopyFrom(surface.id());365 setting->mutable_surfaceid()->CopyFrom(surface->id());
358 if (cursor)366 if (cursor)
359 {367 {
360 if (cursor->stream != nullptr)368 if (cursor->stream != nullptr)
361 {369 {
362 setting.mutable_buffer_stream()->set_value(cursor->stream->rpc_id().as_value());370 setting->mutable_buffer_stream()->set_value(cursor->stream->rpc_id().as_value());
363 setting.set_hotspot_x(cursor->hotspot_x);371 setting->set_hotspot_x(cursor->hotspot_x);
364 setting.set_hotspot_y(cursor->hotspot_y);372 setting->set_hotspot_y(cursor->hotspot_y);
365 }373 }
366 else if (cursor->name != mir_disabled_cursor_name)374 else if (cursor->name != mir_disabled_cursor_name)
367 {375 {
368 setting.set_name(cursor->name.c_str());376 setting->set_name(cursor->name.c_str());
369 }377 }
370
371 }378 }
372 }379 }
373 380
374 configure_cursor_wait_handle.expect_result();381 configure_cursor_wait_handle.expect_result();
375 server->configure_cursor(0, &setting, &void_response,382 server->configure_cursor(0, setting.get(), void_response.get(),
376 google::protobuf::NewCallback(this, &MirSurface::on_cursor_configured));383 google::protobuf::NewCallback(this, &MirSurface::on_cursor_configured));
377 384
378 return &configure_cursor_wait_handle;385 return &configure_cursor_wait_handle;
@@ -392,14 +399,14 @@
392399
393 std::unique_lock<decltype(mutex)> lock(mutex);400 std::unique_lock<decltype(mutex)> lock(mutex);
394401
395 mp::SurfaceSetting setting;402 auto setting = mcl::make_protobuf_object<mp::SurfaceSetting>();
396 setting.mutable_surfaceid()->CopyFrom(surface.id());403 setting->mutable_surfaceid()->CopyFrom(surface->id());
397 setting.set_attrib(at);404 setting->set_attrib(at);
398 setting.set_ivalue(value);405 setting->set_ivalue(value);
399 lock.unlock();406 lock.unlock();
400407
401 configure_wait_handle.expect_result();408 configure_wait_handle.expect_result();
402 server->configure_surface(0, &setting, &configure_result,409 server->configure_surface(0, setting.get(), configure_result.get(),
403 google::protobuf::NewCallback(this, &MirSurface::on_configured));410 google::protobuf::NewCallback(this, &MirSurface::on_configured));
404411
405 return &configure_wait_handle;412 return &configure_wait_handle;
@@ -421,12 +428,12 @@
421 return false;428 return false;
422 }429 }
423430
424 mp::CoordinateTranslationRequest request;431 auto request = mcl::make_protobuf_object<mp::CoordinateTranslationRequest>();
425432
426 request.set_x(x);433 request->set_x(x);
427 request.set_y(y);434 request->set_y(y);
428 *request.mutable_surfaceid() = surface.id();435 *request->mutable_surfaceid() = surface->id();
429 mp::CoordinateTranslationResponse response;436 auto response = mcl::make_protobuf_object<mp::CoordinateTranslationResponse>();
430437
431 MirWaitHandle signal;438 MirWaitHandle signal;
432 signal.expect_result();439 signal.expect_result();
@@ -436,27 +443,27 @@
436443
437 debug->translate_surface_to_screen(444 debug->translate_surface_to_screen(
438 nullptr,445 nullptr,
439 &request,446 request.get(),
440 &response,447 response.get(),
441 google::protobuf::NewCallback(&signal_response_received, &signal));448 google::protobuf::NewCallback(&signal_response_received, &signal));
442 }449 }
443450
444 signal.wait_for_one();451 signal.wait_for_one();
445452
446 *screen_x = response.x();453 *screen_x = response->x();
447 *screen_y = response.y();454 *screen_y = response->y();
448 return !response.has_error();455 return !response->has_error();
449}456}
450457
451void MirSurface::on_configured()458void MirSurface::on_configured()
452{459{
453 std::lock_guard<decltype(mutex)> lock(mutex);460 std::lock_guard<decltype(mutex)> lock(mutex);
454461
455 if (configure_result.has_surfaceid() &&462 if (configure_result->has_surfaceid() &&
456 configure_result.surfaceid().value() == surface.id().value() &&463 configure_result->surfaceid().value() == surface->id().value() &&
457 configure_result.has_attrib())464 configure_result->has_attrib())
458 {465 {
459 int a = configure_result.attrib();466 int a = configure_result->attrib();
460467
461 switch (a)468 switch (a)
462 {469 {
@@ -465,10 +472,10 @@
465 case mir_surface_attrib_focus:472 case mir_surface_attrib_focus:
466 case mir_surface_attrib_dpi:473 case mir_surface_attrib_dpi:
467 case mir_surface_attrib_preferred_orientation:474 case mir_surface_attrib_preferred_orientation:
468 if (configure_result.has_ivalue())475 if (configure_result->has_ivalue())
469 attrib_cache[a] = configure_result.ivalue();476 attrib_cache[a] = configure_result->ivalue();
470 else477 else
471 assert(configure_result.has_error());478 assert(configure_result->has_error());
472 break;479 break;
473 default:480 default:
474 assert(false);481 assert(false);
@@ -513,9 +520,9 @@
513 std::placeholders::_1,520 std::placeholders::_1,
514 context);521 context);
515522
516 if (surface.fd_size() > 0 && handle_event_callback)523 if (surface->fd_size() > 0 && handle_event_callback)
517 {524 {
518 auto input_dispatcher = input_platform->create_input_receiver(surface.fd(0),525 auto input_dispatcher = input_platform->create_input_receiver(surface->fd(0),
519 keymapper,526 keymapper,
520 handle_event_callback);527 handle_event_callback);
521 input_thread = std::make_shared<md::ThreadedDispatcher>("Input dispatch", input_dispatcher);528 input_thread = std::make_shared<md::ThreadedDispatcher>("Input dispatch", input_dispatcher);
@@ -587,7 +594,7 @@
587{594{
588 {595 {
589 std::lock_guard<decltype(mutex)> lock(mutex);596 std::lock_guard<decltype(mutex)> lock(mutex);
590 if (modify_result.has_error())597 if (modify_result->has_error())
591 {598 {
592 // TODO return errors like lp:~vanvugt/mir/wait-result599 // TODO return errors like lp:~vanvugt/mir/wait-result
593 }600 }
@@ -597,14 +604,14 @@
597604
598MirWaitHandle* MirSurface::modify(MirSurfaceSpec const& spec)605MirWaitHandle* MirSurface::modify(MirSurfaceSpec const& spec)
599{606{
600 mp::SurfaceModifications mods;607 auto mods = mcl::make_protobuf_object<mp::SurfaceModifications>();
601608
602 {609 {
603 std::unique_lock<decltype(mutex)> lock(mutex);610 std::unique_lock<decltype(mutex)> lock(mutex);
604 mods.mutable_surface_id()->set_value(surface.id().value());611 mods->mutable_surface_id()->set_value(surface->id().value());
605 }612 }
606613
607 auto const surface_specification = mods.mutable_surface_specification();614 auto const surface_specification = mods->mutable_surface_specification();
608615
609 #define COPY_IF_SET(field)\616 #define COPY_IF_SET(field)\
610 if (spec.field.is_set())\617 if (spec.field.is_set())\
@@ -678,7 +685,7 @@
678 }685 }
679686
680 modify_wait_handle.expect_result();687 modify_wait_handle.expect_result();
681 server->modify_surface(0, &mods, &modify_result,688 server->modify_surface(0, mods.get(), modify_result.get(),
682 google::protobuf::NewCallback(this, &MirSurface::on_modified));689 google::protobuf::NewCallback(this, &MirSurface::on_modified));
683690
684 return &modify_wait_handle;691 return &modify_wait_handle;
685692
=== modified file 'src/client/mir_surface.h'
--- src/client/mir_surface.h 2015-06-10 12:01:33 +0000
+++ src/client/mir_surface.h 2015-06-16 23:39:42 +0000
@@ -65,7 +65,7 @@
65 MirSurfaceSpec(MirConnection* connection, int width, int height, MirPixelFormat format);65 MirSurfaceSpec(MirConnection* connection, int width, int height, MirPixelFormat format);
66 MirSurfaceSpec(MirConnection* connection, MirSurfaceParameters const& params);66 MirSurfaceSpec(MirConnection* connection, MirSurfaceParameters const& params);
6767
68 mir::protobuf::SurfaceParameters serialize() const;68 std::unique_ptr<mir::protobuf::SurfaceParameters> serialize() const;
6969
70 struct AspectRatio { unsigned width; unsigned height; };70 struct AspectRatio { unsigned width; unsigned height; };
7171
@@ -178,16 +178,15 @@
178178
179 mir::protobuf::DisplayServer::Stub* server{nullptr};179 mir::protobuf::DisplayServer::Stub* server{nullptr};
180 mir::protobuf::Debug::Stub* debug{nullptr};180 mir::protobuf::Debug::Stub* debug{nullptr};
181 mir::protobuf::Surface surface;181 std::unique_ptr<mir::protobuf::Surface> surface;
182 mir::protobuf::BufferRequest buffer_request;182 std::unique_ptr<mir::protobuf::PersistentSurfaceId> persistent_id;
183 mir::protobuf::PersistentSurfaceId persistent_id;
184 std::string error_message;183 std::string error_message;
185 std::string name;184 std::string name;
186 mir::protobuf::Void void_response;185 std::unique_ptr<mir::protobuf::Void> void_response;
187186
188 void on_modified();187 void on_modified();
189 MirWaitHandle modify_wait_handle;188 MirWaitHandle modify_wait_handle;
190 mir::protobuf::Void modify_result;189 std::unique_ptr<mir::protobuf::Void> modify_result;
191190
192 MirConnection* const connection{nullptr};191 MirConnection* const connection{nullptr};
193192
@@ -201,7 +200,7 @@
201 std::shared_ptr<mir::input::receiver::InputPlatform> const input_platform;200 std::shared_ptr<mir::input::receiver::InputPlatform> const input_platform;
202 std::shared_ptr<mir::input::receiver::XKBMapper> const keymapper;201 std::shared_ptr<mir::input::receiver::XKBMapper> const keymapper;
203202
204 mir::protobuf::SurfaceSetting configure_result;203 std::unique_ptr<mir::protobuf::SurfaceSetting> configure_result;
205204
206 // Cache of latest SurfaceSettings returned from the server205 // Cache of latest SurfaceSettings returned from the server
207 int attrib_cache[mir_surface_attribs];206 int attrib_cache[mir_surface_attribs];
208207
=== modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp'
--- src/client/rpc/mir_protobuf_rpc_channel.cpp 2015-06-03 17:16:04 +0000
+++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2015-06-16 23:39:42 +0000
@@ -25,6 +25,7 @@
25#include "../display_configuration.h"25#include "../display_configuration.h"
26#include "../lifecycle_control.h"26#include "../lifecycle_control.h"
27#include "../event_sink.h"27#include "../event_sink.h"
28#include "../make_protobuf_object.h"
28#include "mir/variable_length_array.h"29#include "mir/variable_length_array.h"
29#include "mir/events/event_private.h"30#include "mir/events/event_private.h"
3031
@@ -236,24 +237,24 @@
236237
237void mclr::MirProtobufRpcChannel::process_event_sequence(std::string const& event)238void mclr::MirProtobufRpcChannel::process_event_sequence(std::string const& event)
238{239{
239 mir::protobuf::EventSequence seq;240 auto seq = mcl::make_protobuf_object<mir::protobuf::EventSequence>();
240241
241 seq.ParseFromString(event);242 seq->ParseFromString(event);
242243
243 if (seq.has_display_configuration())244 if (seq->has_display_configuration())
244 {245 {
245 display_configuration->update_configuration(seq.display_configuration());246 display_configuration->update_configuration(seq->display_configuration());
246 }247 }
247248
248 if (seq.has_lifecycle_event())249 if (seq->has_lifecycle_event())
249 {250 {
250 lifecycle_control->call_lifecycle_event_handler(seq.lifecycle_event().new_state());251 lifecycle_control->call_lifecycle_event_handler(seq->lifecycle_event().new_state());
251 }252 }
252253
253 int const nevents = seq.event_size();254 int const nevents = seq->event_size();
254 for (int i = 0; i != nevents; ++i)255 for (int i = 0; i != nevents; ++i)
255 {256 {
256 mir::protobuf::Event const& event = seq.event(i);257 mir::protobuf::Event const& event = seq->event(i);
257 if (event.has_raw())258 if (event.has_raw())
258 {259 {
259 std::string const& raw_event = event.raw();260 std::string const& raw_event = event.raw();
@@ -320,7 +321,7 @@
320 */321 */
321 std::lock_guard<decltype(read_mutex)> lock(read_mutex);322 std::lock_guard<decltype(read_mutex)> lock(read_mutex);
322323
323 auto result = std::make_unique<mir::protobuf::wire::Result>();324 auto result = mcl::make_protobuf_object<mir::protobuf::wire::Result>();
324 try325 try
325 {326 {
326 uint16_t message_size;327 uint16_t message_size;

Subscribers

People subscribed via source and target branches