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

Side by Side Diff: mojo/public/bindings/sample/generated/sample_service_internal.h

Issue 23913008: C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix use of size_t Created 7 years, 2 months 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
(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 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_
6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_
7
8 #include <string.h>
9
10 #include "mojo/public/bindings/lib/bindings_internal.h"
11 #include "mojo/public/bindings/sample/generated/sample_service.h"
12
13 namespace sample {
14 namespace internal {
15
16 const uint32_t kService_Frobinate_Name = 1;
17
18 class Service_Frobinate_Params {
19 public:
20 static Service_Frobinate_Params* New(mojo::Buffer* buf) {
21 return new (buf->Allocate(sizeof(Service_Frobinate_Params)))
22 Service_Frobinate_Params();
23 }
24
25 void set_foo(Foo* foo) { d_.foo.ptr = foo; }
26 void set_baz(bool baz) { d_.baz = baz; }
27 void set_port(mojo::Handle port) { d_.port = port; }
28
29 const Foo* foo() const { return d_.foo.ptr; }
30 bool baz() const { return d_.baz; }
31 mojo::Handle port() const {
32 // NOTE: port is an optional field!
33 return header_.num_fields >= 3 ? d_.port : mojo::kInvalidHandle;
34 }
35
36 private:
37 friend class mojo::internal::ObjectTraits<Service_Frobinate_Params>;
38
39 Service_Frobinate_Params() {
40 header_.num_bytes = sizeof(*this);
41 header_.num_fields = 3;
42 }
43 ~Service_Frobinate_Params(); // NOT IMPLEMENTED
44
45 mojo::internal::StructHeader header_;
46 struct Data {
47 mojo::internal::StructPointer<Foo> foo;
48 uint32_t baz : 1;
49 mojo::Handle port;
50 } d_;
51 };
52
53 } // namespace internal
54 } // namespace sample
55
56 namespace mojo {
57 namespace internal {
58
59 template <>
60 class ObjectTraits<sample::Bar> {
61 public:
62 static sample::Bar* Clone(const sample::Bar* bar, Buffer* buf) {
63 sample::Bar* clone = sample::Bar::New(buf);
64 memcpy(clone, bar, sizeof(*bar));
65 return clone;
66 }
67
68 static void EncodePointersAndHandles(sample::Bar* bar,
69 std::vector<mojo::Handle>* handles) {
70 }
71
72 static bool DecodePointersAndHandles(sample::Bar* bar,
73 const mojo::Message& message) {
74 return true;
75 }
76 };
77
78 template <>
79 class ObjectTraits<sample::Foo> {
80 public:
81 static sample::Foo* Clone(const sample::Foo* foo, Buffer* buf) {
82 sample::Foo* clone = sample::Foo::New(buf);
83 memcpy(clone, foo, sizeof(*foo));
84
85 clone->set_bar(mojo::internal::Clone(foo->bar(), buf));
86 clone->set_data(mojo::internal::Clone(foo->data(), buf));
87 clone->set_extra_bars(mojo::internal::Clone(foo->extra_bars(), buf));
88 clone->set_name(mojo::internal::Clone(foo->name(), buf));
89 clone->set_files(mojo::internal::Clone(foo->files(), buf));
90
91 return clone;
92 }
93
94 static void EncodePointersAndHandles(sample::Foo* foo,
95 std::vector<mojo::Handle>* handles) {
96 Encode(&foo->d_.bar, handles);
97 Encode(&foo->d_.data, handles);
98 Encode(&foo->d_.extra_bars, handles);
99 Encode(&foo->d_.name, handles);
100 Encode(&foo->d_.files, handles);
101 }
102
103 static bool DecodePointersAndHandles(sample::Foo* foo,
104 const mojo::Message& message) {
105 if (!Decode(&foo->d_.bar, message))
106 return false;
107 if (!Decode(&foo->d_.data, message))
108 return false;
109 if (foo->header_.num_fields >= 8) {
110 if (!Decode(&foo->d_.extra_bars, message))
111 return false;
112 }
113 if (foo->header_.num_fields >= 9) {
114 if (!Decode(&foo->d_.name, message))
115 return false;
116 }
117 if (foo->header_.num_fields >= 10) {
118 if (!Decode(&foo->d_.files, message))
119 return false;
120 }
121
122 // TODO: validate
123 return true;
124 }
125 };
126
127 template <>
128 class ObjectTraits<sample::internal::Service_Frobinate_Params> {
129 public:
130 static void EncodePointersAndHandles(
131 sample::internal::Service_Frobinate_Params* params,
132 std::vector<mojo::Handle>* handles) {
133 Encode(&params->d_.foo, handles);
134 EncodeHandle(&params->d_.port, handles);
135 }
136
137 static bool DecodePointersAndHandles(
138 sample::internal::Service_Frobinate_Params* params,
139 const mojo::Message& message) {
140 if (!Decode(&params->d_.foo, message))
141 return false;
142 if (params->header_.num_fields >= 3) {
143 if (!DecodeHandle(&params->d_.port, message.handles))
144 return false;
145 }
146
147 // TODO: validate
148 return true;
149 }
150 };
151
152 } // namespace internal
153 } // namespace mojo
154
155 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698