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

Side by Side Diff: mojo/public/bindings/sample/generated/sample_service.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_H_
6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_
7
8 #include "mojo/public/bindings/lib/bindings.h"
9
10 namespace sample {
11
12 class Bar {
13 public:
14 static Bar* New(mojo::Buffer* buf) {
15 return new (buf->Allocate(sizeof(Bar))) Bar();
16 }
17
18 void set_alpha(uint8_t alpha) { d_.alpha = alpha; }
19 void set_beta(uint8_t beta) { d_.beta = beta; }
20 void set_gamma(uint8_t gamma) { d_.gamma = gamma; }
21
22 uint8_t alpha() const { return d_.alpha; }
23 uint8_t beta() const { return d_.beta; }
24 uint8_t gamma() const { return d_.gamma; }
25
26 private:
27 friend class mojo::internal::ObjectTraits<Bar>;
28
29 Bar() {
30 header_.num_bytes = sizeof(*this);
31 header_.num_fields = 3;
32 }
33 ~Bar(); // NOT IMPLEMENTED
34
35 mojo::internal::StructHeader header_;
36 struct Data {
37 uint8_t alpha;
38 uint8_t beta;
39 uint8_t gamma;
40 } d_;
41 };
42
43 class Foo {
44 public:
45 static Foo* New(mojo::Buffer* buf) {
46 return new (buf->Allocate(sizeof(Foo))) Foo();
47 }
48
49 void set_x(int32_t x) { d_.x = x; }
50 void set_y(int32_t y) { d_.y = y; }
51 void set_a(bool a) { d_.a = a; }
52 void set_b(bool b) { d_.b = b; }
53 void set_c(bool c) { d_.c = c; }
54 void set_bar(Bar* bar) { d_.bar.ptr = bar; }
55 void set_data(mojo::Array<uint8_t>* data) { d_.data.ptr = data; }
56 void set_extra_bars(mojo::Array<Bar*>* extra_bars) {
57 d_.extra_bars.ptr = extra_bars;
58 }
59 void set_name(mojo::String* name) {
60 d_.name.ptr = name;
61 }
62 void set_files(mojo::Array<mojo::Handle>* files) {
63 d_.files.ptr = files;
64 }
65
66 int32_t x() const { return d_.x; }
67 int32_t y() const { return d_.y; }
68 bool a() const { return d_.a; }
69 bool b() const { return d_.b; }
70 bool c() const { return d_.c; }
71 const Bar* bar() const { return d_.bar.ptr; }
72 const mojo::Array<uint8_t>* data() const { return d_.data.ptr; }
73 const mojo::Array<Bar*>* extra_bars() const {
74 // NOTE: extra_bars is an optional field!
75 return header_.num_fields >= 8 ? d_.extra_bars.ptr : NULL;
76 }
77 const mojo::String* name() const {
78 // NOTE: name is also an optional field!
79 return header_.num_fields >= 9 ? d_.name.ptr : NULL;
80 }
81 const mojo::Array<mojo::Handle>* files() const {
82 // NOTE: files is also an optional field!
83 return header_.num_fields >= 10 ? d_.files.ptr : NULL;
84 }
85
86 private:
87 friend class mojo::internal::ObjectTraits<Foo>;
88
89 Foo() {
90 header_.num_bytes = sizeof(*this);
91 header_.num_fields = 10;
92 }
93 ~Foo(); // NOT IMPLEMENTED
94
95 mojo::internal::StructHeader header_;
96 struct Data {
97 int32_t x;
98 int32_t y;
99 uint32_t a : 1;
100 uint32_t b : 1;
101 uint32_t c : 1;
102 mojo::internal::StructPointer<Bar> bar;
103 mojo::internal::ArrayPointer<uint8_t> data;
104 mojo::internal::ArrayPointer<Bar*> extra_bars;
105 mojo::internal::StringPointer name;
106 mojo::internal::ArrayPointer<mojo::Handle> files;
DaveMoore 2013/10/09 17:14:11 This is pretty fugly. I'm still not convinced that
107 } d_;
108 };
109
110 class Service {
111 public:
112 virtual void Frobinate(const Foo* foo, bool baz, mojo::Handle port) = 0;
113 };
114
115 } // namespace sample
116
117 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698