Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | 5 #ifndef MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ |
| 6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | 6 #define MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ |
| 7 | 7 |
| 8 #include "mojo/public/bindings/lib/bindings.h" | 8 #include "mojo/public/bindings/lib/bindings.h" |
| 9 #include "mojo/public/bindings/lib/message.h" | |
|
DaveMoore
2013/11/06 15:54:02
Where would the name "sample_service" come from? T
| |
| 9 | 10 |
| 10 namespace sample { | 11 namespace sample { |
| 11 class Foo; | 12 |
| 13 #pragma pack(push, 1) | |
| 14 | |
| 15 class Bar { | |
| 16 public: | |
| 17 static Bar* New(mojo::Buffer* buf); | |
| 18 | |
| 19 void set_alpha(uint8_t alpha) { alpha_ = alpha; } | |
| 20 void set_beta(uint8_t beta) { beta_ = beta; } | |
| 21 void set_gamma(uint8_t gamma) { gamma_ = gamma; } | |
| 22 | |
| 23 uint8_t alpha() const { return alpha_; } | |
| 24 uint8_t beta() const { return beta_; } | |
| 25 uint8_t gamma() const { return gamma_; } | |
| 26 | |
| 27 private: | |
| 28 friend class mojo::internal::ObjectTraits<Bar>; | |
| 29 | |
| 30 Bar(); | |
| 31 ~Bar(); // NOT IMPLEMENTED | |
| 32 | |
| 33 mojo::internal::StructHeader _header_; | |
| 34 uint8_t alpha_; | |
| 35 uint8_t beta_; | |
| 36 uint8_t gamma_; | |
| 37 uint8_t _pad0_[5]; | |
| 38 }; | |
| 39 MOJO_COMPILE_ASSERT(sizeof(Bar) == 16, bad_sizeof_Bar); | |
| 40 | |
| 41 #pragma pack(pop) | |
| 42 | |
| 43 #pragma pack(push, 1) | |
| 44 | |
| 45 class Foo { | |
| 46 public: | |
| 47 static Foo* New(mojo::Buffer* buf); | |
| 48 | |
| 49 void set_x(int32_t x) { x_ = x; } | |
| 50 void set_y(int32_t y) { y_ = y; } | |
| 51 void set_a(bool a) { a_ = a; } | |
| 52 void set_b(bool b) { b_ = b; } | |
| 53 void set_c(bool c) { c_ = c; } | |
| 54 void set_bar(Bar* bar) { bar_.ptr = bar; } | |
| 55 void set_data(mojo::Array<uint8_t>* data) { data_.ptr = data; } | |
| 56 void set_extra_bars(mojo::Array<Bar*>* extra_bars) { | |
| 57 extra_bars_.ptr = extra_bars; | |
| 58 } | |
| 59 void set_name(mojo::String* name) { | |
| 60 name_.ptr = name; | |
| 61 } | |
| 62 void set_files(mojo::Array<mojo::Handle>* files) { | |
| 63 files_.ptr = files; | |
| 64 } | |
| 65 | |
| 66 int32_t x() const { return x_; } | |
| 67 int32_t y() const { return y_; } | |
| 68 bool a() const { return a_; } | |
| 69 bool b() const { return b_; } | |
| 70 bool c() const { return c_; } | |
| 71 const Bar* bar() const { return bar_.ptr; } | |
| 72 const mojo::Array<uint8_t>* data() const { return data_.ptr; } | |
| 73 const mojo::Array<Bar*>* extra_bars() const { | |
| 74 // NOTE: extra_bars is an optional field! | |
| 75 return _header_.num_fields >= 8 ? 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 ? 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 ? files_.ptr : NULL; | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 friend class mojo::internal::ObjectTraits<Foo>; | |
| 88 | |
| 89 Foo(); | |
| 90 ~Foo(); // NOT IMPLEMENTED | |
| 91 | |
| 92 mojo::internal::StructHeader _header_; | |
| 93 int32_t x_; | |
| 94 int32_t y_; | |
| 95 uint8_t a_ : 1; | |
| 96 uint8_t b_ : 1; | |
| 97 uint8_t c_ : 1; | |
| 98 uint8_t _pad0_[7]; | |
| 99 mojo::internal::StructPointer<Bar> bar_; | |
| 100 mojo::internal::ArrayPointer<uint8_t> data_; | |
| 101 mojo::internal::ArrayPointer<Bar*> extra_bars_; | |
| 102 mojo::internal::StringPointer name_; | |
| 103 mojo::internal::ArrayPointer<mojo::Handle> files_; | |
| 104 }; | |
| 105 MOJO_COMPILE_ASSERT(sizeof(Foo) == 64, bad_sizeof_Foo); | |
| 106 | |
| 107 #pragma pack(pop) | |
| 12 | 108 |
| 13 class Service { | 109 class Service { |
| 14 public: | 110 public: |
| 15 virtual void Frobinate(const Foo* foo, bool baz, mojo::Handle port) = 0; | 111 virtual void Frobinate(const Foo* foo, bool baz, mojo::Handle port) = 0; |
| 16 }; | 112 }; |
| 17 | 113 |
| 114 class ServiceProxy : public Service { | |
| 115 public: | |
| 116 explicit ServiceProxy(mojo::MessageReceiver* receiver); | |
| 117 | |
| 118 virtual void Frobinate(const Foo* Foo, bool baz, mojo::Handle port) | |
| 119 MOJO_OVERRIDE; | |
| 120 | |
| 121 private: | |
| 122 mojo::MessageReceiver* receiver_; | |
| 123 }; | |
| 124 | |
| 125 class ServiceStub : public Service, public mojo::MessageReceiver { | |
| 126 public: | |
| 127 virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE; | |
| 128 }; | |
| 129 | |
| 18 } // namespace sample | 130 } // namespace sample |
| 19 | 131 |
| 20 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ | 132 #endif // MOJO_GENERATED_BINDINGS_SAMPLE_SERVICE_H_ |
| OLD | NEW |