OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/public/bindings/generated/sample_service_proxy.h" | |
6 | |
7 #include "mojo/public/bindings/generated/sample_service_internal.h" | |
8 | |
9 namespace sample { | |
10 | |
11 ServiceProxy::ServiceProxy(mojo::MessageSender* sender) | |
12 : sender_(sender) { | |
13 } | |
14 | |
15 void ServiceProxy::Frobinate(const Foo* foo, bool baz, mojo::Handle port) { | |
16 mojo::MessageBuffer buf; | |
17 | |
18 // TODO: We should allocate the MessageHeader here to reserve space. | |
19 | |
20 // We now go about allocating the anonymous Frobinate_Params struct. It | |
21 // holds the parameters to the Frobinate message. | |
22 // | |
23 // Notice how foo is cloned. This causes a copy of foo to be generated | |
24 // within the same buffer as the Frobinate_Params struct. That's what we | |
25 // need in order to generate a continguous blob of message data. | |
26 | |
27 internal::Service_Frobinate_Params* params = | |
viettrungluu
2013/10/02 01:17:06
I wonder if in the case that params is small (and
| |
28 buf.New<internal::Service_Frobinate_Params>(); | |
29 params->set_foo(mojo::internal::Clone(foo, &buf)); | |
30 params->set_baz(baz); | |
31 params->set_port(port); | |
32 | |
33 // NOTE: If foo happened to be a graph with cycles, then Clone would not | |
34 // have returned. | |
35 | |
36 // Last step before sending the message is to encode pointers and handles | |
37 // so that messages become hermetic. Pointers become offsets and handles | |
38 // becomes indices into the handles array. | |
39 | |
40 std::vector<mojo::Handle> handles; | |
41 mojo::internal::EncodePointersAndHandles(params, &handles); | |
42 | |
43 mojo::Message message; | |
44 message.name = internal::kService_Frobinate_Name; | |
45 message.data_start = buf.data(); | |
viettrungluu
2013/10/02 01:17:06
... which makes me think that MessageBuffer should
| |
46 message.data_end = buf.data() + buf.size(); | |
47 message.handles.swap(handles); | |
48 | |
49 sender_->Send(message); | |
50 } | |
51 | |
52 } // namespace sample | |
OLD | NEW |