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