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) { |
| 16 mojo::MessageBuffer buf; |
| 17 |
| 18 // TODO: We should allocate the MessageHeader here to reserve space. |
| 19 //MessageHeader* header = buf.Alloc<MessageHeader>(); |
| 20 |
| 21 // We now go about allocating the anonymous Frobinate_Params struct. It |
| 22 // holds the parameters to the Frobinate message. |
| 23 // |
| 24 // Notice how foo is cloned. This causes a copy of foo to be generated |
| 25 // within the same buffer as the Frobinate_Params struct. That's what we |
| 26 // need in order to generate a continguous blob of message data. |
| 27 |
| 28 internal::Service_Frobinate_Params* params = |
| 29 buf.Alloc<internal::Service_Frobinate_Params>(); |
| 30 params->set_foo(mojo::internal::Clone(foo, &buf)); |
| 31 params->set_baz(baz); |
| 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(); |
| 46 message.data_end = buf.data() + buf.size(); |
| 47 message.handles_start = &handles[0]; |
| 48 message.handles_end = &handles[0] + handles.size(); |
| 49 |
| 50 sender_->Send(message); |
| 51 } |
| 52 |
| 53 } // namespace sample |
OLD | NEW |