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/sample/generated/sample_service_proxy.h" | |
6 | |
7 #include <stdlib.h> | |
8 | |
9 #include "mojo/public/bindings/lib/message.h" | |
10 #include "mojo/public/bindings/lib/message_builder.h" | |
11 #include "mojo/public/bindings/sample/generated/sample_service_serialization.h" | |
12 | |
13 namespace sample { | |
14 | |
15 ServiceProxy::ServiceProxy(mojo::MessageReceiver* receiver) | |
16 : receiver_(receiver) { | |
17 } | |
18 | |
19 void ServiceProxy::Frobinate(const Foo* foo, bool baz, mojo::Handle port) { | |
20 size_t payload_size = | |
21 mojo::internal::Align(sizeof(internal::Service_Frobinate_Params)); | |
22 payload_size += mojo::internal::ComputeSizeOf(foo); | |
23 | |
24 mojo::MessageBuilder builder(internal::kService_Frobinate_Name, payload_size); | |
25 | |
26 // We now go about allocating the anonymous Frobinate_Params struct. It | |
27 // holds the parameters to the Frobinate message. | |
28 // | |
29 // Notice how foo is cloned. This causes a copy of foo to be generated | |
30 // within the same buffer as the Frobinate_Params struct. That's what we | |
31 // need in order to generate a contiguous blob of message data. | |
32 | |
33 internal::Service_Frobinate_Params* params = | |
34 internal::Service_Frobinate_Params::New(builder.buffer()); | |
35 params->set_foo(mojo::internal::Clone(foo, builder.buffer())); | |
36 params->set_baz(baz); | |
37 params->set_port(port); | |
38 | |
39 // NOTE: If foo happened to be a graph with cycles, then Clone would not | |
40 // have returned. | |
41 | |
42 // Next step is to encode pointers and handles so that messages become | |
43 // hermetic. Pointers become offsets and handles becomes indices into the | |
44 // handles array. | |
45 mojo::Message message; | |
46 mojo::internal::EncodePointersAndHandles(params, &message.handles); | |
47 | |
48 // Finally, we get the generated message data, and forward it to the | |
49 // receiver. | |
50 message.data = builder.Finish(); | |
51 | |
52 receiver_->Accept(&message); | |
53 } | |
54 | |
55 } // namespace sample | |
OLD | NEW |