| // Copyright 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| {%- set header_guard = "%s_SHARED_H_"|format( |
| module.path|upper|replace("/","_")|replace(".","_")| |
| replace("-", "_")) %} |
| |
| {%- macro mojom_type_traits(kind) %} |
| template <> |
| struct MojomTypeTraits<{{kind|get_qualified_name_for_kind}}DataView> { |
| using Data = {{kind|get_qualified_name_for_kind(internal=True)}}; |
| {%- if kind|is_union_kind %} |
| using DataAsArrayElement = Data; |
| static constexpr MojomTypeCategory category = MojomTypeCategory::UNION; |
| {%- else %} |
| using DataAsArrayElement = Pointer<Data>; |
| static constexpr MojomTypeCategory category = MojomTypeCategory::STRUCT; |
| {%- endif %} |
| }; |
| {%- endmacro %} |
| |
| {%- macro namespace_begin() %} |
| {%- for namespace in namespaces_as_array %} |
| namespace {{namespace}} { |
| {%- endfor %} |
| {%- endmacro %} |
| |
| {%- macro namespace_end() %} |
| {%- for namespace in namespaces_as_array|reverse %} |
| } // namespace {{namespace}} |
| {%- endfor %} |
| {%- endmacro %} |
| |
| #ifndef {{header_guard}} |
| #define {{header_guard}} |
| |
| #include <stdint.h> |
| |
| #include <functional> |
| #include <ostream> |
| #include <type_traits> |
| #include <utility> |
| |
| #include "base/compiler_specific.h" |
| #include "mojo/public/cpp/bindings/array_data_view.h" |
| #include "mojo/public/cpp/bindings/enum_traits.h" |
| #include "mojo/public/cpp/bindings/interface_data_view.h" |
| #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| #include "mojo/public/cpp/bindings/lib/serialization.h" |
| #include "mojo/public/cpp/bindings/map_data_view.h" |
| #include "mojo/public/cpp/bindings/native_enum.h" |
| #include "mojo/public/cpp/bindings/native_struct_data_view.h" |
| #include "mojo/public/cpp/bindings/string_data_view.h" |
| #include "{{module.path}}-shared-internal.h" |
| {%- for import in imports %} |
| #include "{{import.module.path}}-shared.h" |
| {%- endfor %} |
| |
| {{namespace_begin()}} |
| |
| {#--- Struct Forward Declarations -#} |
| {%- for struct in structs %} |
| {%- if struct|is_native_only_kind %} |
| using {{struct.name}}DataView = mojo::NativeStructDataView; |
| {%- else %} |
| class {{struct.name}}DataView; |
| {%- endif %} |
| {% endfor %} |
| |
| {#--- Union Forward Declarations -#} |
| {%- for union in unions %} |
| class {{union.name}}DataView; |
| {%- endfor %} |
| |
| {{namespace_end()}} |
| |
| namespace mojo { |
| namespace internal { |
| |
| {%- for struct in structs %} |
| {%- if not struct|is_native_only_kind %} |
| {{mojom_type_traits(struct)}} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- for union in unions %} |
| {{mojom_type_traits(union)}} |
| {%- endfor %} |
| |
| } // namespace internal |
| } // namespace mojo |
| |
| {{namespace_begin()}} |
| |
| {#--- Enums #} |
| {%- from "enum_macros.tmpl" import enum_decl%} |
| {%- for enum in all_enums %} |
| {%- if enum|is_native_only_kind %} |
| using {{enum|get_name_for_kind(flatten_nested_kind=True)}} = mojo::NativeEnum; |
| {%- else %} |
| {{enum_decl(enum)}} |
| {%- endif %} |
| {%- endfor %} |
| |
| {#--- Interfaces #} |
| {%- if interfaces %} |
| // Interface base classes. They are used for type safety check. |
| {%- endif %} |
| {%- for interface in interfaces %} |
| class {{interface.name}}InterfaceBase {}; |
| |
| using {{interface.name}}PtrDataView = |
| mojo::InterfacePtrDataView<{{interface.name}}InterfaceBase>; |
| using {{interface.name}}RequestDataView = |
| mojo::InterfaceRequestDataView<{{interface.name}}InterfaceBase>; |
| using {{interface.name}}AssociatedPtrInfoDataView = |
| mojo::AssociatedInterfacePtrInfoDataView<{{interface.name}}InterfaceBase>; |
| using {{interface.name}}AssociatedRequestDataView = |
| mojo::AssociatedInterfaceRequestDataView<{{interface.name}}InterfaceBase>; |
| |
| {%- endfor %} |
| |
| {#--- Structs #} |
| {%- for struct in structs %} |
| {%- if not struct|is_native_only_kind %} |
| {% include "struct_data_view_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {#--- Interface parameter definitions #} |
| {%- for interface in interfaces %} |
| {%- for method in interface.methods %} |
| {%- set struct = method.param_struct %} |
| {% include "struct_data_view_declaration.tmpl" %} |
| {%- if method.response_parameters != None %} |
| {%- set struct = method.response_param_struct %} |
| {% include "struct_data_view_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| {%- endfor %} |
| |
| {#--- Unions #} |
| {%- for union in unions %} |
| {% include "union_data_view_declaration.tmpl" %} |
| {%- endfor %} |
| |
| {{namespace_end()}} |
| |
| namespace std { |
| |
| {%- from "enum_macros.tmpl" import enum_hash %} |
| {%- for enum in all_enums %} |
| {%- if not enum|is_native_only_kind %} |
| {{enum_hash(enum)}} |
| {%- endif %} |
| {%- endfor %} |
| |
| } // namespace std |
| |
| namespace mojo { |
| |
| {#--- Enum Serialization Helpers -#} |
| {%- for enum in all_enums %} |
| {%- if not enum|is_native_only_kind %} |
| {% include "enum_serialization_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {#--- Struct Serialization Helpers -#} |
| {% for struct in structs %} |
| {%- if not struct|is_native_only_kind %} |
| {% include "struct_serialization_declaration.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {#--- Union Serialization Helpers -#} |
| {% if unions %} |
| {%- for union in unions %} |
| {% include "union_serialization_declaration.tmpl" %} |
| {%- endfor %} |
| {%- endif %} |
| |
| } // namespace mojo |
| |
| {{namespace_begin()}} |
| |
| {%- for struct in structs %} |
| {%- if not struct|is_native_only_kind %} |
| {% include "struct_data_view_definition.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- for interface in interfaces %} |
| {%- for method in interface.methods %} |
| {%- set struct = method.param_struct %} |
| {% include "struct_data_view_definition.tmpl" %} |
| {%- if method.response_parameters != None %} |
| {%- set struct = method.response_param_struct %} |
| {% include "struct_data_view_definition.tmpl" %} |
| {%- endif %} |
| {%- endfor %} |
| {%- endfor %} |
| |
| {%- for union in unions %} |
| {% include "union_data_view_definition.tmpl" %} |
| {%- endfor %} |
| |
| {{namespace_end()}} |
| |
| #endif // {{header_guard}} |
| |