| Index: mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
|
| diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
|
| index 472d96b1af0b505c9cd548ff8fb7a7df192c6558..77d246a2618fed6273fa683d371c0804c865c0e3 100644
|
| --- a/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/module-shared.h.tmpl
|
| @@ -6,6 +6,32 @@
|
| 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 const MojomTypeCategory category = MojomTypeCategory::UNION;
|
| +{%- else %}
|
| + using DataAsArrayElement = Pointer<Data>;
|
| + static const 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}}
|
|
|
| @@ -16,17 +42,55 @@
|
| #include <type_traits>
|
| #include <utility>
|
|
|
| +#include "mojo/public/cpp/bindings/array_data_view.h"
|
| #include "mojo/public/cpp/bindings/enum_traits.h"
|
| -#include "mojo/public/cpp/bindings/lib/serialization_forward.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 %}
|
|
|
| -{%- for namespace in namespaces_as_array %}
|
| -namespace {{namespace}} {
|
| -{%- 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%}
|
| @@ -38,9 +102,49 @@ using {{enum.name}} = mojo::NativeEnum;
|
| {%- endif %}
|
| {%- endfor %}
|
|
|
| -{%- for namespace in namespaces_as_array|reverse %}
|
| -} // namespace {{namespace}}
|
| +{#--- 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 {
|
|
|
| @@ -62,7 +166,46 @@ namespace mojo {
|
| {%- 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}}
|
|
|
|
|