| {%- import "struct_macros.tmpl" as struct_macros %} |
| {%- import "interface_macros.tmpl" as interface_macros -%} |
| {%- set header_guard = "%s_COMMON_H_"| |
| format(module.path|upper|replace("/","_")|replace(".","_")) -%} |
| |
| // NOTE: This file was generated by the Mojo bindings generator. |
| #ifndef {{header_guard}} |
| #define {{header_guard}} |
| |
| #include <stdint.h> |
| #include <iosfwd> |
| |
| #include "mojo/public/cpp/bindings/array.h" |
| #include "mojo/public/cpp/bindings/callback.h" |
| #include "mojo/public/cpp/bindings/interface_handle.h" |
| #include "mojo/public/cpp/bindings/interface_request.h" |
| #include "mojo/public/cpp/bindings/map.h" |
| #include "mojo/public/cpp/bindings/message_validator.h" |
| #include "mojo/public/cpp/bindings/string.h" |
| #include "mojo/public/cpp/bindings/struct_ptr.h" |
| #include "mojo/public/cpp/system/buffer.h" |
| #include "mojo/public/cpp/system/data_pipe.h" |
| #include "mojo/public/cpp/system/handle.h" |
| #include "mojo/public/cpp/system/message_pipe.h" |
| #include "{{module.path}}-internal.h" |
| |
| {%- for import in imports %} |
| #include "{{import.module.path}}-common.h" |
| {%- endfor %} |
| |
| {%- for namespace in namespaces_as_array %} |
| namespace {{namespace}} { |
| {%- endfor %} |
| |
| // --- Interface Forward Declarations --- |
| {%- for interface in interfaces %} |
| class {{interface.name}}; |
| class {{interface.name}}RequestValidator; |
| {%- if interface|has_callbacks %} |
| class {{interface.name}}ResponseValidator; |
| {%- endif %} |
| class {{interface.name}}_Synchronous; |
| {%- endfor %} |
| |
| // --- Struct Forward Declarations --- |
| {%- for struct in structs %} |
| {{ struct_macros.structptr_forward_decl(struct) }} |
| {%- endfor %} |
| |
| // --- Union Forward Declarations --- |
| {%- for union in unions %} |
| class {{union.name}}; |
| {%- if union|should_inline_union %} |
| typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; |
| {%- else %} |
| typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; |
| {%- endif %} |
| {%- endfor %} |
| |
| // --- Enums Declarations --- |
| {%- from "enum_macros.tmpl" import enum_decl -%} |
| {%- from "enum_macros.tmpl" import global_enum_operators_decl -%} |
| {%- for enum in enums %} |
| {{enum_decl(enum)}} |
| {{global_enum_operators_decl(enum)}} |
| {%- endfor %} |
| |
| // --- Constants --- |
| {%- for constant in module.constants %} |
| {#- To be consistent with constants defined inside interfaces, only make |
| integral types compile-time constants. #} |
| {%- if constant.kind|is_integral_kind %} |
| const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_value}}; |
| {%- else %} |
| extern const {{constant.kind|cpp_pod_type}} {{constant.name}}; |
| {%- endif %} |
| {%- endfor %} |
| |
| // --- Interface declarations --- |
| {%- for interface in interfaces %} |
| namespace internal { |
| class {{interface.name}}_Base { |
| public: |
| {%- if interface.service_name %} |
| static const char Name_[]; |
| {%- endif %} |
| static const uint32_t Version_ = {{interface.version}}; |
| |
| using RequestValidator_ = {{interface.name}}RequestValidator; |
| {%- if interface|has_callbacks %} |
| using ResponseValidator_ = {{interface.name}}ResponseValidator; |
| {%- else %} |
| using ResponseValidator_ = mojo::internal::PassThroughValidator; |
| {%- endif %} |
| using Synchronous_ = {{interface.name}}_Synchronous; |
| |
| {#--- Methods #} |
| enum class MessageOrdinals : uint32_t { |
| {%- for method in interface.methods %} |
| {{method.name}} = {{method.ordinal}}, |
| {%- endfor %} |
| }; |
| |
| {#--- Enums #} |
| {# TODO(vardhan): In order to get around circular dependency issues, make these |
| enums global and typedef them here. #} |
| {%- from "enum_macros.tmpl" import enum_decl -%} |
| {%- for enum in interface.enums %} |
| {{enum_decl(enum, is_static=true)|indent(2)}} |
| {%- endfor %} |
| |
| {#--- Constants #} |
| {%- for constant in interface.constants %} |
| {%- if constant.kind|is_integral_kind %} |
| static const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_value}}; |
| {%- else %} |
| static const {{constant.kind|cpp_pod_type}} {{constant.name}}; |
| {%- endif %} |
| {%- endfor %} |
| |
| virtual ~{{interface.name}}_Base() {} |
| }; |
| |
| } // namespace internal |
| |
| // Async interface declaration |
| {% include "interface_declaration.tmpl" %} |
| {%- endfor %} |
| |
| {%- for namespace in namespaces_as_array|reverse %} |
| } // namespace {{namespace}} |
| {%- endfor %} |
| |
| // --- Internal Template Specializations --- |
| |
| namespace mojo { |
| namespace internal { |
| |
| {%- for struct in structs %} |
| {%- set namespace = namespaces_as_array|join("::") %} |
| {%- set struct_name = struct|get_name_for_kind %} |
| template <> |
| struct WrapperTraits<{{namespace}}::{{struct_name}}Ptr, true, false> { |
| using DataType = {{namespace}}::internal::{{struct_name}}_Data*; |
| }; |
| {%- endfor %} |
| |
| } // internal |
| } // mojo |
| |
| {#---------------- #} |
| {#--- Declarations #} |
| {#---------------- #} |
| {%- for namespace in namespaces_as_array %} |
| namespace {{namespace}} { |
| {%- endfor %} |
| |
| // --- Interface Request Validators --- |
| {%- for interface in interfaces %} |
| {% include "interface_request_validator_declaration.tmpl" %} |
| {%- endfor %} |
| |
| // --- Interface Response Validators --- |
| {%- for interface in interfaces if interface|has_callbacks %} |
| {% include "interface_response_validator_declaration.tmpl" %} |
| {%- endfor %} |
| |
| // --- Interface enum operators --- |
| {%- from "enum_macros.tmpl" import global_enum_operators_decl -%} |
| {%- for interface in interfaces %} |
| {%- for enum in interface.enums %} |
| {{global_enum_operators_decl(enum, |
| class_name="internal::%s_Base"|format(interface.name))}} |
| {%- endfor %} |
| {%- endfor %} |
| |
| // --- Unions --- |
| // Unions must be declared first because they can be members of structs. |
| {%- for union in unions %} |
| {% include "wrapper_union_class_declaration.tmpl" %} |
| {%- endfor %} |
| |
| {#--- NOTE: Non-inlined structs may have pointers to inlined structs, so we #} |
| {#--- need to fully define inlined structs ahead of the others. #} |
| |
| // --- Inlined structs --- |
| {%- for struct in structs %} |
| {%- if struct|should_inline %} |
| {% include "wrapper_class_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| // --- Non-inlined structs --- |
| {%- for struct in structs %} |
| {%- if not struct|should_inline %} |
| {% include "wrapper_class_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| // --- Struct serialization helpers --- |
| {%- if structs %} |
| {%- for struct in structs %} |
| {% include "struct_serialization_declaration.tmpl" %} |
| {%- endfor %} |
| {%- endif %} |
| |
| // --- Union serialization helpers --- |
| {%- if unions %} |
| {%- for union in unions %} |
| {% include "union_serialization_declaration.tmpl" %} |
| {%- endfor %} |
| {%- endif %} |
| |
| // --- Request and response parameter structs for Interface methods --- |
| {%- for interface in interfaces %} |
| {{interface_macros.declare_param_structs_for_interface(interface)}} |
| {%- endfor %} |
| |
| {%- for namespace in namespaces_as_array|reverse %} |
| } // namespace {{namespace}} |
| {%- endfor %} |
| |
| #endif // {{header_guard}} |