1// Copyright 2016 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5{%- set header_guard = "%s_SHARED_H_"|format( 6 module.path|upper|replace("/","_")|replace(".","_")| 7 replace("-", "_")) %} 8 9{%- macro mojom_type_traits(kind) %} 10template <> 11struct MojomTypeTraits<{{kind|get_qualified_name_for_kind}}DataView> { 12 using Data = {{kind|get_qualified_name_for_kind(internal=True)}}; 13{%- if kind|is_union_kind %} 14 using DataAsArrayElement = Data; 15 static constexpr MojomTypeCategory category = MojomTypeCategory::UNION; 16{%- else %} 17 using DataAsArrayElement = Pointer<Data>; 18 static constexpr MojomTypeCategory category = MojomTypeCategory::STRUCT; 19{%- endif %} 20}; 21{%- endmacro %} 22 23{%- macro namespace_begin() %} 24{%- for namespace in namespaces_as_array %} 25namespace {{namespace}} { 26{%- endfor %} 27{%- endmacro %} 28 29{%- macro namespace_end() %} 30{%- for namespace in namespaces_as_array|reverse %} 31} // namespace {{namespace}} 32{%- endfor %} 33{%- endmacro %} 34 35#ifndef {{header_guard}} 36#define {{header_guard}} 37 38#include <stdint.h> 39 40#include <functional> 41#include <ostream> 42#include <type_traits> 43#include <utility> 44 45#include "base/compiler_specific.h" 46#include "base/containers/flat_map.h" 47#include "mojo/public/cpp/bindings/array_data_view.h" 48#include "mojo/public/cpp/bindings/enum_traits.h" 49#include "mojo/public/cpp/bindings/interface_data_view.h" 50#include "mojo/public/cpp/bindings/lib/bindings_internal.h" 51#include "mojo/public/cpp/bindings/lib/serialization.h" 52#include "mojo/public/cpp/bindings/map_data_view.h" 53#include "mojo/public/cpp/bindings/string_data_view.h" 54#include "{{module.path}}-shared-internal.h" 55{%- for import in imports %} 56#include "{{import.path}}-shared.h" 57{%- endfor %} 58 59{% if not disallow_interfaces -%} 60#include "mojo/public/cpp/bindings/lib/interface_serialization.h" 61{%- endif %} 62 63{% if not disallow_native_types %} 64#include "mojo/public/cpp/bindings/native_enum.h" 65#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h" 66{%- endif %} 67 68{%- if export_header %} 69#include "{{export_header}}" 70{%- endif %} 71 72{{namespace_begin()}} 73 74{#--- Struct Forward Declarations -#} 75{%- for struct in structs %} 76{%- if struct|is_native_only_kind %} 77using {{struct.name}}DataView = mojo::native::NativeStructDataView; 78{%- else %} 79class {{struct.name}}DataView; 80{%- endif %} 81{% endfor %} 82 83{#--- Union Forward Declarations -#} 84{%- for union in unions %} 85class {{union.name}}DataView; 86{%- endfor %} 87 88{{namespace_end()}} 89 90namespace mojo { 91namespace internal { 92 93{%- for struct in structs %} 94{%- if not struct|is_native_only_kind %} 95{{mojom_type_traits(struct)}} 96{%- endif %} 97{%- endfor %} 98 99{%- for union in unions %} 100{{mojom_type_traits(union)}} 101{%- endfor %} 102 103} // namespace internal 104} // namespace mojo 105 106{{namespace_begin()}} 107 108{#--- Enums #} 109{%- from "enum_macros.tmpl" import enum_decl%} 110{%- for enum in all_enums %} 111{%- if enum|is_native_only_kind %} 112using {{enum|get_name_for_kind(flatten_nested_kind=True)}} = mojo::NativeEnum; 113{%- else %} 114{{enum_decl(enum)}} 115{%- endif %} 116{%- endfor %} 117 118{#--- Interfaces #} 119{%- if interfaces %} 120// Interface base classes. They are used for type safety check. 121{%- endif %} 122{%- for interface in interfaces %} 123class {{interface.name}}InterfaceBase {}; 124 125using {{interface.name}}PtrDataView = 126 mojo::InterfacePtrDataView<{{interface.name}}InterfaceBase>; 127using {{interface.name}}RequestDataView = 128 mojo::InterfaceRequestDataView<{{interface.name}}InterfaceBase>; 129using {{interface.name}}AssociatedPtrInfoDataView = 130 mojo::AssociatedInterfacePtrInfoDataView<{{interface.name}}InterfaceBase>; 131using {{interface.name}}AssociatedRequestDataView = 132 mojo::AssociatedInterfaceRequestDataView<{{interface.name}}InterfaceBase>; 133 134{%- endfor %} 135 136{#--- Structs #} 137{%- for struct in structs %} 138{%- if not struct|is_native_only_kind %} 139{% include "struct_data_view_declaration.tmpl" %} 140{%- endif %} 141{%- endfor %} 142 143{#--- Interface parameter definitions #} 144{%- for interface in interfaces %} 145{%- for method in interface.methods %} 146{%- set struct = method.param_struct %} 147{% include "struct_data_view_declaration.tmpl" %} 148{%- if method.response_parameters != None %} 149{%- set struct = method.response_param_struct %} 150{% include "struct_data_view_declaration.tmpl" %} 151{%- endif %} 152{%- endfor %} 153{%- endfor %} 154 155{#--- Unions #} 156{%- for union in unions %} 157{% include "union_data_view_declaration.tmpl" %} 158{%- endfor %} 159 160{{namespace_end()}} 161 162namespace std { 163 164{%- from "enum_macros.tmpl" import enum_hash %} 165{%- for enum in all_enums %} 166{%- if not enum|is_native_only_kind %} 167{{enum_hash(enum)}} 168{%- endif %} 169{%- endfor %} 170 171} // namespace std 172 173namespace mojo { 174 175{#--- Enum Serialization Helpers -#} 176{%- for enum in all_enums %} 177{%- if not enum|is_native_only_kind %} 178{% include "enum_serialization_declaration.tmpl" %} 179{%- endif %} 180{%- endfor %} 181 182{#--- Struct Serialization Helpers -#} 183{% for struct in structs %} 184{%- if not struct|is_native_only_kind %} 185{% include "struct_serialization_declaration.tmpl" %} 186{%- endif %} 187{%- endfor %} 188 189{#--- Union Serialization Helpers -#} 190{% if unions %} 191{%- for union in unions %} 192{% include "union_serialization_declaration.tmpl" %} 193{%- endfor %} 194{%- endif %} 195 196} // namespace mojo 197 198{{namespace_begin()}} 199 200{%- for struct in structs %} 201{%- if not struct|is_native_only_kind %} 202{% include "struct_data_view_definition.tmpl" %} 203{%- endif %} 204{%- endfor %} 205 206{%- for interface in interfaces %} 207{%- for method in interface.methods %} 208{%- set struct = method.param_struct %} 209{% include "struct_data_view_definition.tmpl" %} 210{%- if method.response_parameters != None %} 211{%- set struct = method.response_param_struct %} 212{% include "struct_data_view_definition.tmpl" %} 213{%- endif %} 214{%- endfor %} 215{%- endfor %} 216 217{%- for union in unions %} 218{% include "union_data_view_definition.tmpl" %} 219{%- endfor %} 220 221{{namespace_end()}} 222 223#endif // {{header_guard}} 224 225