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_internal.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 mojo::MessageBuilder builder; |
| 21 |
| 22 // We now go about allocating the anonymous Frobinate_Params struct. It |
| 23 // holds the parameters to the Frobinate message. |
| 24 // |
| 25 // Notice how foo is cloned. This causes a copy of foo to be generated |
| 26 // within the same buffer as the Frobinate_Params struct. That's what we |
| 27 // need in order to generate a contiguous blob of message data. |
| 28 |
| 29 internal::Service_Frobinate_Params* params = |
| 30 internal::Service_Frobinate_Params::New(builder.buffer()); |
| 31 params->set_foo(mojo::internal::Clone(foo, builder.buffer())); |
| 32 params->set_baz(baz); |
| 33 params->set_port(port); |
| 34 |
| 35 // NOTE: If foo happened to be a graph with cycles, then Clone would not |
| 36 // have returned. |
| 37 |
| 38 // Next step is to encode pointers and handles so that messages become |
| 39 // hermetic. Pointers become offsets and handles becomes indices into the |
| 40 // handles array. |
| 41 mojo::Message message; |
| 42 mojo::internal::EncodePointersAndHandles(params, &message.handles); |
| 43 |
| 44 // Finally, we get the generated message data, and forward it to the |
| 45 // receiver. |
| 46 message.data = builder.Finish(internal::kService_Frobinate_Name); |
| 47 |
| 48 receiver_->Accept(&message); |
| 49 |
| 50 free(message.data); |
| 51 } |
| 52 |
| 53 } // namespace sample |
OLD | NEW |