| OLD | NEW |
| (Empty) |
| 1 {%- import "struct_macros.tmpl" as struct_macros %} | |
| 2 {%- import "interface_macros.tmpl" as interface_macros -%} | |
| 3 {%- set header_guard = "%s_COMMON_H_"| | |
| 4 format(module.path|upper|replace("/","_")|replace(".","_")) -%} | |
| 5 | |
| 6 // NOTE: This file was generated by the Mojo bindings generator. | |
| 7 #ifndef {{header_guard}} | |
| 8 #define {{header_guard}} | |
| 9 | |
| 10 #include <stdint.h> | |
| 11 #include <iosfwd> | |
| 12 | |
| 13 #include "mojo/public/cpp/bindings/array.h" | |
| 14 #include "mojo/public/cpp/bindings/callback.h" | |
| 15 #include "mojo/public/cpp/bindings/interface_handle.h" | |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | |
| 17 #include "mojo/public/cpp/bindings/map.h" | |
| 18 #include "mojo/public/cpp/bindings/message_validator.h" | |
| 19 #include "mojo/public/cpp/bindings/string.h" | |
| 20 #include "mojo/public/cpp/bindings/struct_ptr.h" | |
| 21 #include "mojo/public/cpp/system/buffer.h" | |
| 22 #include "mojo/public/cpp/system/data_pipe.h" | |
| 23 #include "mojo/public/cpp/system/handle.h" | |
| 24 #include "mojo/public/cpp/system/message_pipe.h" | |
| 25 #include "{{module.path}}-internal.h" | |
| 26 | |
| 27 {%- for import in imports %} | |
| 28 #include "{{import.module.path}}-common.h" | |
| 29 {%- endfor %} | |
| 30 | |
| 31 {%- for namespace in namespaces_as_array %} | |
| 32 namespace {{namespace}} { | |
| 33 {%- endfor %} | |
| 34 | |
| 35 // --- Interface Forward Declarations --- | |
| 36 {%- for interface in interfaces %} | |
| 37 class {{interface.name}}; | |
| 38 class {{interface.name}}RequestValidator; | |
| 39 {%- if interface|has_callbacks %} | |
| 40 class {{interface.name}}ResponseValidator; | |
| 41 {%- endif %} | |
| 42 class {{interface.name}}_Synchronous; | |
| 43 {%- endfor %} | |
| 44 | |
| 45 // --- Struct Forward Declarations --- | |
| 46 {%- for struct in structs %} | |
| 47 {{ struct_macros.structptr_forward_decl(struct) }} | |
| 48 {%- endfor %} | |
| 49 | |
| 50 // --- Union Forward Declarations --- | |
| 51 {%- for union in unions %} | |
| 52 class {{union.name}}; | |
| 53 {%- if union|should_inline_union %} | |
| 54 typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; | |
| 55 {%- else %} | |
| 56 typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; | |
| 57 {%- endif %} | |
| 58 {%- endfor %} | |
| 59 | |
| 60 // --- Enums Declarations --- | |
| 61 {%- from "enum_macros.tmpl" import enum_decl -%} | |
| 62 {%- from "enum_macros.tmpl" import global_enum_operators_decl -%} | |
| 63 {%- for enum in enums %} | |
| 64 {{enum_decl(enum)}} | |
| 65 {{global_enum_operators_decl(enum)}} | |
| 66 {%- endfor %} | |
| 67 | |
| 68 // --- Constants --- | |
| 69 {%- for constant in module.constants %} | |
| 70 {#- To be consistent with constants defined inside interfaces, only make | |
| 71 integral types compile-time constants. #} | |
| 72 {%- if constant.kind|is_integral_kind %} | |
| 73 const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_val
ue}}; | |
| 74 {%- else %} | |
| 75 extern const {{constant.kind|cpp_pod_type}} {{constant.name}}; | |
| 76 {%- endif %} | |
| 77 {%- endfor %} | |
| 78 | |
| 79 // --- Interface declarations --- | |
| 80 {%- for interface in interfaces %} | |
| 81 namespace internal { | |
| 82 class {{interface.name}}_Base { | |
| 83 public: | |
| 84 {%- if interface.service_name %} | |
| 85 static const char Name_[]; | |
| 86 {%- endif %} | |
| 87 static const uint32_t Version_ = {{interface.version}}; | |
| 88 | |
| 89 using RequestValidator_ = {{interface.name}}RequestValidator; | |
| 90 {%- if interface|has_callbacks %} | |
| 91 using ResponseValidator_ = {{interface.name}}ResponseValidator; | |
| 92 {%- else %} | |
| 93 using ResponseValidator_ = mojo::internal::PassThroughValidator; | |
| 94 {%- endif %} | |
| 95 using Synchronous_ = {{interface.name}}_Synchronous; | |
| 96 | |
| 97 {#--- Methods #} | |
| 98 enum class MessageOrdinals : uint32_t { | |
| 99 {%- for method in interface.methods %} | |
| 100 {{method.name}} = {{method.ordinal}}, | |
| 101 {%- endfor %} | |
| 102 }; | |
| 103 | |
| 104 {#--- Enums #} | |
| 105 {# TODO(vardhan): In order to get around circular dependency issues, make these | |
| 106 enums global and typedef them here. #} | |
| 107 {%- from "enum_macros.tmpl" import enum_decl -%} | |
| 108 {%- for enum in interface.enums %} | |
| 109 {{enum_decl(enum, is_static=true)|indent(2)}} | |
| 110 {%- endfor %} | |
| 111 | |
| 112 {#--- Constants #} | |
| 113 {%- for constant in interface.constants %} | |
| 114 {%- if constant.kind|is_integral_kind %} | |
| 115 static const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|con
stant_value}}; | |
| 116 {%- else %} | |
| 117 static const {{constant.kind|cpp_pod_type}} {{constant.name}}; | |
| 118 {%- endif %} | |
| 119 {%- endfor %} | |
| 120 | |
| 121 virtual ~{{interface.name}}_Base() {} | |
| 122 }; | |
| 123 | |
| 124 } // namespace internal | |
| 125 | |
| 126 // Async interface declaration | |
| 127 {% include "interface_declaration.tmpl" %} | |
| 128 {%- endfor %} | |
| 129 | |
| 130 {%- for namespace in namespaces_as_array|reverse %} | |
| 131 } // namespace {{namespace}} | |
| 132 {%- endfor %} | |
| 133 | |
| 134 // --- Internal Template Specializations --- | |
| 135 | |
| 136 namespace mojo { | |
| 137 namespace internal { | |
| 138 | |
| 139 {%- for struct in structs %} | |
| 140 {%- set namespace = namespaces_as_array|join("::") %} | |
| 141 {%- set struct_name = struct|get_name_for_kind %} | |
| 142 template <> | |
| 143 struct WrapperTraits<{{namespace}}::{{struct_name}}Ptr, true, false> { | |
| 144 using DataType = {{namespace}}::internal::{{struct_name}}_Data*; | |
| 145 }; | |
| 146 {%- endfor %} | |
| 147 | |
| 148 } // internal | |
| 149 } // mojo | |
| 150 | |
| 151 {#---------------- #} | |
| 152 {#--- Declarations #} | |
| 153 {#---------------- #} | |
| 154 {%- for namespace in namespaces_as_array %} | |
| 155 namespace {{namespace}} { | |
| 156 {%- endfor %} | |
| 157 | |
| 158 // --- Interface Request Validators --- | |
| 159 {%- for interface in interfaces %} | |
| 160 {% include "interface_request_validator_declaration.tmpl" %} | |
| 161 {%- endfor %} | |
| 162 | |
| 163 // --- Interface Response Validators --- | |
| 164 {%- for interface in interfaces if interface|has_callbacks %} | |
| 165 {% include "interface_response_validator_declaration.tmpl" %} | |
| 166 {%- endfor %} | |
| 167 | |
| 168 // --- Interface enum operators --- | |
| 169 {%- from "enum_macros.tmpl" import global_enum_operators_decl -%} | |
| 170 {%- for interface in interfaces %} | |
| 171 {%- for enum in interface.enums %} | |
| 172 {{global_enum_operators_decl(enum, | |
| 173 class_name="internal::%s_Base"|format(interface.name))}} | |
| 174 {%- endfor %} | |
| 175 {%- endfor %} | |
| 176 | |
| 177 // --- Unions --- | |
| 178 // Unions must be declared first because they can be members of structs. | |
| 179 {%- for union in unions %} | |
| 180 {% include "wrapper_union_class_declaration.tmpl" %} | |
| 181 {%- endfor %} | |
| 182 | |
| 183 {#--- NOTE: Non-inlined structs may have pointers to inlined structs, so we #} | |
| 184 {#--- need to fully define inlined structs ahead of the others. #} | |
| 185 | |
| 186 // --- Inlined structs --- | |
| 187 {%- for struct in structs %} | |
| 188 {%- if struct|should_inline %} | |
| 189 {% include "wrapper_class_declaration.tmpl" %} | |
| 190 {%- endif %} | |
| 191 {%- endfor %} | |
| 192 | |
| 193 // --- Non-inlined structs --- | |
| 194 {%- for struct in structs %} | |
| 195 {%- if not struct|should_inline %} | |
| 196 {% include "wrapper_class_declaration.tmpl" %} | |
| 197 {%- endif %} | |
| 198 {%- endfor %} | |
| 199 | |
| 200 // --- Struct serialization helpers --- | |
| 201 {%- if structs %} | |
| 202 {%- for struct in structs %} | |
| 203 {% include "struct_serialization_declaration.tmpl" %} | |
| 204 {%- endfor %} | |
| 205 {%- endif %} | |
| 206 | |
| 207 // --- Union serialization helpers --- | |
| 208 {%- if unions %} | |
| 209 {%- for union in unions %} | |
| 210 {% include "union_serialization_declaration.tmpl" %} | |
| 211 {%- endfor %} | |
| 212 {%- endif %} | |
| 213 | |
| 214 // --- Request and response parameter structs for Interface methods --- | |
| 215 {%- for interface in interfaces %} | |
| 216 {{interface_macros.declare_param_structs_for_interface(interface)}} | |
| 217 {%- endfor %} | |
| 218 | |
| 219 {%- for namespace in namespaces_as_array|reverse %} | |
| 220 } // namespace {{namespace}} | |
| 221 {%- endfor %} | |
| 222 | |
| 223 #endif // {{header_guard}} | |
| OLD | NEW |