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 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | |
6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | |
7 | |
8 #include "mojo/public/bindings/bindings.h" | |
9 | |
10 namespace sample { | |
Ben Goodger (Google)
2013/09/28 21:15:29
this looks much better
| |
11 | |
12 class Bar { | |
13 public: | |
14 Bar() { | |
15 header_.num_bytes = sizeof(*this); | |
16 header_.num_fields = 3; | |
17 } | |
18 | |
19 void set_alpha(uint8_t alpha) { d_.alpha = alpha; } | |
20 void set_beta(uint8_t beta) { d_.beta = beta; } | |
21 void set_gamma(uint8_t gamma) { d_.gamma = gamma; } | |
22 | |
23 uint8_t alpha() const { return d_.alpha; } | |
24 uint8_t beta() const { return d_.beta; } | |
25 uint8_t gamma() const { return d_.gamma; } | |
26 | |
27 private: | |
28 friend class mojo::internal::Traits<Bar>; | |
29 | |
30 mojo::StructHeader header_; | |
31 struct { | |
viettrungluu
2013/10/01 00:51:04
This is nice for debugging, but apart from that ar
| |
32 uint8_t alpha; | |
33 uint8_t beta; | |
34 uint8_t gamma; | |
35 } d_; | |
36 | |
37 ~Bar(); // NOT IMPLEMENTED | |
38 }; | |
39 | |
40 class Foo { | |
41 public: | |
42 Foo() { | |
43 header_.num_bytes = sizeof(*this); | |
44 header_.num_fields = 8; | |
45 } | |
46 | |
47 void set_x(int32_t x) { d_.x = x; } | |
48 void set_y(int32_t y) { d_.y = y; } | |
49 void set_a(bool a) { d_.a = a; } | |
50 void set_b(bool b) { d_.b = b; } | |
51 void set_c(bool c) { d_.c = c; } | |
52 void set_bar(Bar* bar) { d_.bar.ptr = bar; } | |
53 void set_data(mojo::Array<uint8_t>* data) { d_.data.ptr = data; } | |
54 void set_extra_bars(mojo::Array<Bar*>* extra_bars) { | |
55 d_.extra_bars.ptr = extra_bars; | |
56 } | |
57 | |
58 int32_t x() const { return d_.x; } | |
59 int32_t y() const { return d_.y; } | |
60 bool a() const { return d_.a; } | |
61 bool b() const { return d_.b; } | |
62 bool c() const { return d_.c; } | |
63 const Bar* bar() const { return d_.bar.ptr; } | |
viettrungluu
2013/10/01 00:51:04
Would there be value in also have a (non-const) |B
| |
64 const mojo::Array<uint8_t>* data() const { return d_.data.ptr; } | |
65 const mojo::Array<Bar*>* extra_bars() const { | |
66 // NOTE: extra_bars is an optional field! | |
67 return header_.num_fields >= 8 ? d_.extra_bars.ptr : NULL; | |
68 } | |
69 | |
70 private: | |
71 friend class mojo::internal::Traits<Foo>; | |
72 | |
73 mojo::StructHeader header_; | |
74 struct { | |
75 int32_t x; | |
76 int32_t y; | |
77 uint32_t a : 1; | |
78 uint32_t b : 1; | |
79 uint32_t c : 1; | |
80 mojo::StructPointer<Bar> bar; | |
81 mojo::ArrayPointer<uint8_t> data; | |
82 mojo::ArrayPointer<Bar*> extra_bars; | |
83 } d_; | |
84 | |
85 ~Foo(); // NOT IMPLEMENTED | |
86 }; | |
87 | |
88 class Service { | |
89 public: | |
90 virtual void Frobinate(const Foo* foo, bool baz) = 0; | |
91 }; | |
92 | |
93 } // namespace sample | |
94 | |
95 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | |
OLD | NEW |