OLD | NEW |
1 {%- import "struct_macros.tmpl" as struct_macros %} | 1 {%- import "struct_macros.tmpl" as struct_macros %} |
2 {%- set class_name = struct.name ~ "_Data" %} | 2 {%- set class_name = struct.name ~ "_Data" %} |
3 {%- set method_name = "k%s_%s_Name"|format(interface.name, method.name) %} | 3 {%- set method_name = "k%s_%s_Name"|format(interface.name, method.name) %} |
4 const uint32_t {{method_name}} = {{method.ordinal}}; | 4 const uint32_t {{method_name}} = {{method.ordinal}}; |
5 class {{class_name}} { | 5 class {{class_name}} { |
6 public: | 6 public: |
7 static {{class_name}}* New(mojo::Buffer* buf) { | 7 static {{class_name}}* New(mojo::Buffer* buf) { |
8 return new (buf->Allocate(sizeof({{class_name}}))) | 8 return new (buf->Allocate(sizeof({{class_name}}))) |
9 {{class_name}}(); | 9 {{class_name}}(); |
10 } | 10 } |
11 | 11 |
12 {#--- Setters -#} | 12 {#--- Setters -#} |
13 {{ struct_macros.setters(struct) }} | 13 {{ struct_macros.setters(struct) }} |
14 | 14 |
15 {#--- Getters -#} | 15 {#--- Getters -#} |
16 {{ struct_macros.getters(struct) }} | 16 {{ struct_macros.getters(struct) }} |
17 | 17 |
| 18 void CloseHandles() { |
| 19 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} |
| 20 if ({{pf.field.name}}_.ptr) |
| 21 {{pf.field.name}}_.ptr->CloseHandles(); |
| 22 {%- endfor %} |
| 23 } |
| 24 |
| 25 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) { |
| 26 {{ struct_macros.encodes(struct)|indent(4) }} |
| 27 } |
| 28 |
| 29 bool DecodePointersAndHandles(mojo::Message* message) { |
| 30 {{ struct_macros.decodes(struct)|indent(4) }} |
| 31 return true; |
| 32 } |
| 33 |
18 private: | 34 private: |
19 friend class mojo::internal::ObjectTraits<{{class_name}}>; | |
20 | |
21 {{class_name}}() { | 35 {{class_name}}() { |
22 _header_.num_bytes = sizeof(*this); | 36 _header_.num_bytes = sizeof(*this); |
23 _header_.num_fields = 3; | 37 _header_.num_fields = 3; |
24 } | 38 } |
25 | 39 |
26 mojo::internal::StructHeader _header_; | 40 mojo::internal::StructHeader _header_; |
27 {{ struct_macros.fields(struct) }} | 41 {{ struct_macros.fields(struct) }} |
28 }; | 42 }; |
29 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, | 43 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, |
30 bad_sizeof_{{class_name}}); | 44 bad_sizeof_{{class_name}}); |
OLD | NEW |