Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: mojo/public/bindings/sample/generated/sample_service.cc

Issue 66353002: Mojo: RemotePtr<S> + bindings changes for Peer attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + fix error in sample_service.h Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/bindings/sample/generated/sample_service.h" 5 #include "mojo/public/bindings/sample/generated/sample_service.h"
6 6
7 #include "mojo/public/bindings/lib/message_builder.h" 7 #include "mojo/public/bindings/lib/message_builder.h"
8 #include "mojo/public/bindings/sample/generated/sample_service_internal.h" 8 #include "mojo/public/bindings/sample/generated/sample_service_internal.h"
9 9
10 namespace sample { 10 namespace sample {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 44
45 mojo::internal::StructHeader _header_; 45 mojo::internal::StructHeader _header_;
46 mojo::internal::StructPointer<Foo> foo_; 46 mojo::internal::StructPointer<Foo> foo_;
47 uint8_t baz_ : 1; 47 uint8_t baz_ : 1;
48 uint8_t _pad0_[3]; 48 uint8_t _pad0_[3];
49 mojo::Handle port_; 49 mojo::Handle port_;
50 }; 50 };
51 MOJO_COMPILE_ASSERT(sizeof(Service_Frobinate_Params) == 24, 51 MOJO_COMPILE_ASSERT(sizeof(Service_Frobinate_Params) == 24,
52 bad_sizeof_Service_Frobinate_Params); 52 bad_sizeof_Service_Frobinate_Params);
53
54 const uint32_t kServiceClient_DidFrobinate_Name = 0;
55
56 class ServiceClient_DidFrobinate_Params {
57 public:
58 static ServiceClient_DidFrobinate_Params* New(mojo::Buffer* buf) {
59 return new (buf->Allocate(sizeof(ServiceClient_DidFrobinate_Params)))
60 ServiceClient_DidFrobinate_Params();
61 }
62
63 void set_result(int32_t result) { result_ = result; }
64
65 int32_t result() const { return result_; }
66
67 private:
68 friend class mojo::internal::ObjectTraits<ServiceClient_DidFrobinate_Params>;
69
70 ServiceClient_DidFrobinate_Params() {
71 _header_.num_bytes = sizeof(*this);
72 _header_.num_fields = 3;
73 }
74
75 mojo::internal::StructHeader _header_;
76 int32_t result_;
77 uint8_t _pad0_[4];
78 };
79 MOJO_COMPILE_ASSERT(sizeof(ServiceClient_DidFrobinate_Params) == 16,
80 bad_sizeof_ServiceClient_DidFrobinate_Params);
81
53 #if defined(__clang__) 82 #if defined(__clang__)
54 #pragma clang diagnostic pop 83 #pragma clang diagnostic pop
55 #endif 84 #endif
56 #pragma pack(pop) 85 #pragma pack(pop)
57 86
58 } // namespace 87 } // namespace
59 88
60 // static 89 // static
61 Bar* Bar::New(mojo::Buffer* buf) { 90 Bar* Bar::New(mojo::Buffer* buf) {
62 return new (buf->Allocate(sizeof(Bar))) Bar(); 91 return new (buf->Allocate(sizeof(Bar))) Bar();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (!mojo::internal::DecodePointersAndHandles(params, *message)) 156 if (!mojo::internal::DecodePointersAndHandles(params, *message))
128 return false; 157 return false;
129 158
130 Frobinate(params->foo(), params->baz(), params->port()); 159 Frobinate(params->foo(), params->baz(), params->port());
131 break; 160 break;
132 } 161 }
133 } 162 }
134 return true; 163 return true;
135 } 164 }
136 165
166 ServiceClientProxy::ServiceClientProxy(mojo::MessageReceiver* receiver)
167 : receiver_(receiver) {
168 }
169
170 void ServiceClientProxy::DidFrobinate(int32_t result) {
171 size_t payload_size =
172 mojo::internal::Align(sizeof(ServiceClient_DidFrobinate_Params));
173
174
175 mojo::MessageBuilder builder(kServiceClient_DidFrobinate_Name, payload_size);
176
177 ServiceClient_DidFrobinate_Params* params =
178 ServiceClient_DidFrobinate_Params::New(builder.buffer());
179
180 params->set_result(result);
181
182 mojo::Message message;
183 mojo::internal::EncodePointersAndHandles(params, &message.handles);
184
185 message.data = builder.Finish();
186
187 receiver_->Accept(&message);
188 }
189
190
191 bool ServiceClientStub::Accept(mojo::Message* message) {
192 switch (message->data->header.name) {
193 case kServiceClient_DidFrobinate_Name: {
194 ServiceClient_DidFrobinate_Params* params =
195 reinterpret_cast<ServiceClient_DidFrobinate_Params*>(
196 message->data->payload);
197
198 if (!mojo::internal::DecodePointersAndHandles(params, *message))
199 return false;
200 DidFrobinate(params->result());
201 break;
202 }
203
204 }
205 return true;
206 }
207
137 } // namespace sample 208 } // namespace sample
138 209
139 namespace mojo { 210 namespace mojo {
140 namespace internal { 211 namespace internal {
141 212
142 // static 213 // static
143 size_t ObjectTraits<sample::Bar>::ComputeSizeOf( 214 size_t ObjectTraits<sample::Bar>::ComputeSizeOf(
144 const sample::Bar* bar) { 215 const sample::Bar* bar) {
145 return sizeof(*bar); 216 return sizeof(*bar);
146 } 217 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (params->_header_.num_fields >= 3) { 313 if (params->_header_.num_fields >= 3) {
243 if (!DecodeHandle(&params->port_, message.handles)) 314 if (!DecodeHandle(&params->port_, message.handles))
244 return false; 315 return false;
245 } 316 }
246 317
247 // TODO: validate 318 // TODO: validate
248 return true; 319 return true;
249 } 320 }
250 }; 321 };
251 322
323 template <>
324 class ObjectTraits<sample::ServiceClient_DidFrobinate_Params> {
325 public:
326 static void EncodePointersAndHandles(
327 sample::ServiceClient_DidFrobinate_Params* params,
328 std::vector<Handle>* handles) {
329 }
330
331 static bool DecodePointersAndHandles(
332 sample::ServiceClient_DidFrobinate_Params* params,
333 const Message& message) {
334 return true;
335 }
336 };
337
252 } // namespace internal 338 } // namespace internal
253 } // namespace mojo 339 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/sample/generated/sample_service.h ('k') | mojo/public/bindings/sample/sample_service.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698