1// Copyright 2013 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{%- if variant -%} 6{%- set variant_path = "%s-%s"|format(module.path, variant) -%} 7{%- else -%} 8{%- set variant_path = module.path -%} 9{%- endif -%} 10 11{%- set header_guard = "%s_H_"|format( 12 variant_path|upper|replace("/","_")|replace(".","_")| 13 replace("-", "_")) %} 14 15{%- macro namespace_begin() %} 16{%- for namespace in namespaces_as_array %} 17namespace {{namespace}} { 18{%- endfor %} 19{%- if variant %} 20namespace {{variant}} { 21{%- endif %} 22{%- endmacro %} 23 24{%- macro namespace_end() %} 25{%- if variant %} 26} // namespace {{variant}} 27{%- endif %} 28{%- for namespace in namespaces_as_array|reverse %} 29} // namespace {{namespace}} 30{%- endfor %} 31{%- endmacro %} 32 33#ifndef {{header_guard}} 34#define {{header_guard}} 35 36#include <stdint.h> 37 38#include <limits> 39#include <type_traits> 40#include <utility> 41 42#include "base/callback.h" 43#include "base/macros.h" 44#include "base/optional.h" 45 46#include "mojo/public/cpp/bindings/mojo_buildflags.h" 47#if BUILDFLAG(MOJO_TRACE_ENABLED) 48#include "base/trace_event/trace_event.h" 49#endif 50#include "mojo/public/cpp/bindings/clone_traits.h" 51#include "mojo/public/cpp/bindings/equals_traits.h" 52#include "mojo/public/cpp/bindings/lib/serialization.h" 53#include "mojo/public/cpp/bindings/struct_ptr.h" 54#include "mojo/public/cpp/bindings/struct_traits.h" 55#include "mojo/public/cpp/bindings/union_traits.h" 56#include "{{module.path}}-shared.h" 57{%- for import in imports %} 58{%- if variant %} 59#include "{{"%s-%s.h"|format(import.path, variant)}}" 60{%- else %} 61#include "{{import.path}}.h" 62{%- endif %} 63{%- endfor %} 64{%- if not for_blink %} 65#include <string> 66#include <vector> 67{%- else %} 68{# hash_util.h includes template specializations that should be present for 69 every use of {Inlined}StructPtr. #} 70#include "mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h" 71#include "mojo/public/cpp/bindings/lib/wtf_hash_util.h" 72#include "third_party/blink/renderer/platform/mojo/revocable_interface_ptr.h" 73#include "third_party/blink/renderer/platform/wtf/hash_functions.h" 74#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 75{%- endif %} 76 77{% if not disallow_interfaces -%} 78#include "mojo/public/cpp/bindings/associated_interface_ptr.h" 79#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 80#include "mojo/public/cpp/bindings/associated_interface_request.h" 81#include "mojo/public/cpp/bindings/interface_ptr.h" 82#include "mojo/public/cpp/bindings/interface_request.h" 83#include "mojo/public/cpp/bindings/lib/control_message_handler.h" 84#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h" 85#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" 86{%- if for_blink %} 87#include "third_party/blink/renderer/platform/mojo/revocable_interface_ptr.h" 88{%- endif %} 89{%- endif %} 90 91{% if not disallow_native_types %} 92#include "mojo/public/cpp/bindings/lib/native_enum_serialization.h" 93#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h" 94{%- endif %} 95 96{%- for header in extra_public_headers %} 97#include "{{header}}" 98{%- endfor %} 99 100{%- if export_header %} 101#include "{{export_header}}" 102{%- endif %} 103 104{#--- WTF enum hashing #} 105{%- from "enum_macros.tmpl" import enum_hash_blink%} 106{%- if for_blink %} 107{%- for enum in all_enums %} 108{%- if not enum|is_native_only_kind %} 109{{enum_hash_blink(enum)}} 110{%- endif %} 111{%- endfor %} 112{%- endif %} 113 114{{namespace_begin()}} 115 116{#--- Enums #} 117{%- if variant %} 118{%- for enum in enums %} 119using {{enum.name}} = {{enum.name}}; // Alias for definition in the parent namespace. 120{%- endfor %} 121{%- endif %} 122 123{#--- Constants #} 124{%- for constant in module.constants %} 125{{constant|format_constant_declaration}}; 126{%- endfor %} 127 128{#--- Interface Forward Declarations -#} 129{% for interface in interfaces %} 130class {{interface.name}}; 131using {{interface.name}}Ptr = mojo::InterfacePtr<{{interface.name}}>; 132{%- if for_blink %} 133using Revocable{{interface.name}}Ptr = ::blink::RevocableInterfacePtr<{{interface.name}}>; 134{%- endif %} 135using {{interface.name}}PtrInfo = mojo::InterfacePtrInfo<{{interface.name}}>; 136using ThreadSafe{{interface.name}}Ptr = 137 mojo::ThreadSafeInterfacePtr<{{interface.name}}>; 138using {{interface.name}}Request = mojo::InterfaceRequest<{{interface.name}}>; 139using {{interface.name}}AssociatedPtr = 140 mojo::AssociatedInterfacePtr<{{interface.name}}>; 141using ThreadSafe{{interface.name}}AssociatedPtr = 142 mojo::ThreadSafeAssociatedInterfacePtr<{{interface.name}}>; 143using {{interface.name}}AssociatedPtrInfo = 144 mojo::AssociatedInterfacePtrInfo<{{interface.name}}>; 145using {{interface.name}}AssociatedRequest = 146 mojo::AssociatedInterfaceRequest<{{interface.name}}>; 147{% endfor %} 148 149{#--- Struct Forward Declarations -#} 150{% for struct in structs %} 151{%- if struct|is_native_only_kind %} 152using {{struct.name}} = mojo::native::NativeStruct; 153using {{struct.name}}Ptr = mojo::native::NativeStructPtr; 154{%- else %} 155class {{struct.name}}; 156{%- if struct|should_inline %} 157using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>; 158{%- else %} 159using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>; 160{%- endif %} 161{%- endif %} 162{% endfor %} 163 164{#--- Union Forward Declarations -#} 165{% for union in unions %} 166class {{union.name}}; 167{% if union|should_inline_union %} 168typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; 169{% else %} 170typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; 171{% endif %} 172{%- endfor %} 173 174{#--- Interfaces -#} 175{% for interface in interfaces %} 176{% include "interface_declaration.tmpl" %} 177{%- endfor %} 178 179{#--- Interface Proxies -#} 180{% for interface in interfaces %} 181{% include "interface_proxy_declaration.tmpl" %} 182{%- endfor %} 183 184{#--- Interface Stubs -#} 185{% for interface in interfaces %} 186{% include "interface_stub_declaration.tmpl" %} 187{%- endfor %} 188 189{#--- Interface Request Validators -#} 190{% for interface in interfaces %} 191{% include "interface_request_validator_declaration.tmpl" %} 192{%- endfor %} 193 194{#--- Interface Response Validators -#} 195{% for interface in interfaces if interface|has_callbacks %} 196{% include "interface_response_validator_declaration.tmpl" %} 197{%- endfor %} 198 199{#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs, 200 so we need to fully define inlined structs ahead of the others. #} 201 202{#--- Inlined structs #} 203{% for struct in structs %} 204{% if struct|should_inline and not struct|is_native_only_kind %} 205{% include "wrapper_class_declaration.tmpl" %} 206{% endif %} 207{%- endfor %} 208 209{#--- Unions must be declared before non-inlined structs because they can be 210 members of structs. #} 211{#--- Unions #} 212{% for union in unions %} 213{% include "wrapper_union_class_declaration.tmpl" %} 214{%- endfor %} 215 216{#--- Non-inlined structs #} 217{% for struct in structs %} 218{% if not struct|should_inline and not struct|is_native_only_kind %} 219{% include "wrapper_class_declaration.tmpl" %} 220{% endif %} 221{%- endfor %} 222 223{%- for union in unions %} 224{% include "wrapper_union_class_template_definition.tmpl" %} 225{%- endfor %} 226 227{%- for struct in structs %} 228{%- if not struct|is_native_only_kind %} 229{% include "wrapper_class_template_definition.tmpl" %} 230{%- endif %} 231{%- endfor %} 232 233{{namespace_end()}} 234 235namespace mojo { 236 237{#--- Struct Serialization Helpers -#} 238{% for struct in structs %} 239{%- if not struct|is_native_only_kind %} 240{% include "struct_traits_declaration.tmpl" %} 241{%- endif %} 242{%- endfor %} 243 244{#--- Union Serialization Helpers -#} 245{% if unions %} 246{%- for union in unions %} 247{% include "union_traits_declaration.tmpl" %} 248{%- endfor %} 249{%- endif %} 250 251} // namespace mojo 252 253#endif // {{header_guard}} 254