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{%- from "enum_macros.tmpl" import enum_decl %} 16{%- from "enum_macros.tmpl" import enum_stream_operator %} 17{%- from "enum_macros.tmpl" import is_known_enum_value %} 18{%- from "enum_macros.tmpl" import enum_hash %} 19 20{%- macro namespace_begin() %} 21{%- for namespace in namespaces_as_array %} 22namespace {{namespace}} { 23{%- endfor %} 24{%- if variant %} 25namespace {{variant}} { 26{%- endif %} 27{%- endmacro %} 28 29{%- macro namespace_end() %} 30{%- if variant %} 31} // namespace {{variant}} 32{%- endif %} 33{%- for namespace in namespaces_as_array|reverse %} 34} // namespace {{namespace}} 35{%- endfor %} 36{%- endmacro %} 37 38#ifndef {{header_guard}} 39#define {{header_guard}} 40 41#include <stdint.h> 42 43#include <functional> 44#include <ostream> 45#include <type_traits> 46#include <utility> 47 48#include "base/callback.h" 49#include "base/optional.h" 50#include "base/strings/string_piece.h" 51#include "mojo/public/cpp/bindings/associated_interface_ptr.h" 52#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 53#include "mojo/public/cpp/bindings/associated_interface_request.h" 54#include "mojo/public/cpp/bindings/interface_ptr.h" 55#include "mojo/public/cpp/bindings/interface_request.h" 56#include "mojo/public/cpp/bindings/lib/control_message_handler.h" 57#include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 58#include "mojo/public/cpp/bindings/lib/serialization.h" 59#include "mojo/public/cpp/bindings/map.h" 60#include "mojo/public/cpp/bindings/message_filter.h" 61#include "mojo/public/cpp/bindings/native_enum.h" 62#include "mojo/public/cpp/bindings/native_struct.h" 63#include "mojo/public/cpp/bindings/no_interface.h" 64#include "mojo/public/cpp/bindings/struct_ptr.h" 65#include "mojo/public/cpp/bindings/struct_traits.h" 66#include "{{variant_path}}-internal.h" 67{%- for import in imports %} 68{%- if variant %} 69#include "{{"%s-%s.h"|format(import.module.path, variant)}}" 70{%- else %} 71#include "{{import.module.path}}.h" 72{%- endif %} 73{%- endfor %} 74{%- if not for_blink %} 75#include "mojo/public/cpp/bindings/array.h" 76#include "mojo/public/cpp/bindings/string.h" 77{%- else %} 78#include "mojo/public/cpp/bindings/wtf_array.h" 79#include "mojo/public/cpp/bindings/wtf_map.h" 80#include "third_party/WebKit/Source/wtf/Optional.h" 81#include "third_party/WebKit/Source/wtf/text/WTFString.h" 82{%- endif %} 83 84{%- for header in extra_public_headers %} 85#include "{{header}}" 86{%- endfor %} 87 88{#--- Enums #} 89{%- if enums %} 90{{namespace_begin()}} 91{%- for enum in enums %} 92{%- if enum|is_native_only_kind %} 93using {{enum.name}} = mojo::NativeEnum; 94{%- else %} 95{{enum_decl(enum)}} 96{{enum_stream_operator(enum)}} 97{{is_known_enum_value(enum)}} 98{%- endif %} 99{%- endfor %} 100{{namespace_end()}} 101 102namespace std { 103 104{%- for enum in enums %} 105{%- if not enum|is_native_only_kind %} 106{{enum_hash(enum)}} 107{%- endif %} 108{%- endfor %} 109 110} // namespace std 111{%- endif %} 112 113{{namespace_begin()}} 114 115{#--- Constants #} 116{%- for constant in module.constants %} 117{#- To be consistent with constants defined inside interfaces, only make 118 integral types compile-time constants. #} 119{%- if constant.kind|is_integral_kind %} 120const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_value}}; 121{%- else %} 122extern const {{constant.kind|cpp_pod_type}} {{constant.name}}; 123{%- endif %} 124{%- endfor %} 125 126{#--- Interface Forward Declarations -#} 127{% for interface in interfaces %} 128class {{interface.name}}; 129using {{interface.name}}Ptr = mojo::InterfacePtr<{{interface.name}}>; 130using {{interface.name}}PtrInfo = mojo::InterfacePtrInfo<{{interface.name}}>; 131using {{interface.name}}Request = mojo::InterfaceRequest<{{interface.name}}>; 132using {{interface.name}}AssociatedPtr = 133 mojo::AssociatedInterfacePtr<{{interface.name}}>; 134using {{interface.name}}AssociatedPtrInfo = 135 mojo::AssociatedInterfacePtrInfo<{{interface.name}}>; 136using {{interface.name}}AssociatedRequest = 137 mojo::AssociatedInterfaceRequest<{{interface.name}}>; 138{% endfor %} 139 140{#--- Struct Forward Declarations -#} 141{% for struct in structs %} 142{%- if struct|is_native_only_kind %} 143using {{struct.name}} = mojo::NativeStruct; 144using {{struct.name}}Ptr = mojo::NativeStructPtr; 145{%- else %} 146class {{struct.name}}; 147class {{struct.name}}DataView; 148{%- if struct|should_inline %} 149using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>; 150{%- else %} 151using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>; 152{%- endif %} 153{%- endif %} 154{% endfor %} 155 156{#--- Union Forward Declarations -#} 157{% for union in unions %} 158class {{union.name}}; 159{% if union|should_inline_union %} 160typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; 161{% else %} 162typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; 163{% endif %} 164{%- endfor %} 165 166{#--- Interfaces -#} 167{% for interface in interfaces %} 168{% include "interface_declaration.tmpl" %} 169 170{%- if interface.enums %} 171{{namespace_end()}} 172namespace std { 173 174{%- for enum in interface.enums %} 175{%- if not enum|is_native_only_kind %} 176{{enum_hash(enum)}} 177{%- endif %} 178{%- endfor %} 179 180} // namespace std 181{{namespace_begin()}} 182{%- endif %} 183 184{%- for enum in interface.enums %} 185{%- if not enum|is_native_only_kind %} 186{{enum_stream_operator(enum)}} 187{{is_known_enum_value(enum)}} 188{%- endif %} 189{%- endfor %} 190{%- endfor %} 191 192{#--- Interface Proxies -#} 193{% for interface in interfaces %} 194{% include "interface_proxy_declaration.tmpl" %} 195{%- endfor %} 196 197{#--- Interface Stubs -#} 198{% for interface in interfaces %} 199{% include "interface_stub_declaration.tmpl" %} 200{%- endfor %} 201 202{#--- Interface Request Validators -#} 203{% for interface in interfaces %} 204{% include "interface_request_validator_declaration.tmpl" %} 205{%- endfor %} 206 207{#--- Interface Response Validators -#} 208{% for interface in interfaces if interface|has_callbacks %} 209{% include "interface_response_validator_declaration.tmpl" %} 210{%- endfor %} 211 212{#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs, 213 so we need to fully define inlined structs ahead of the others. #} 214 215{#--- Inlined structs #} 216{% for struct in structs %} 217{% if struct|should_inline and not struct|is_native_only_kind %} 218{% include "wrapper_class_declaration.tmpl" %} 219{% include "struct_data_view_declaration.tmpl" %} 220{% endif %} 221{%- endfor %} 222 223{#--- Unions must be declared before non-inlined structs because they can be 224 members of structs. #} 225{#--- Unions #} 226{% for union in unions %} 227{% include "wrapper_union_class_declaration.tmpl" %} 228{%- endfor %} 229 230{#--- Non-inlined structs #} 231{% for struct in structs %} 232{% if not struct|should_inline and not struct|is_native_only_kind %} 233{% include "wrapper_class_declaration.tmpl" %} 234{% include "struct_data_view_declaration.tmpl" %} 235{% endif %} 236{%- endfor %} 237 238{%- for union in unions %} 239{% include "wrapper_union_class_template_definition.tmpl" %} 240{%- endfor %} 241 242{%- for struct in structs %} 243{%- if not struct|is_native_only_kind %} 244{% include "wrapper_class_template_definition.tmpl" %} 245{%- endif %} 246 247{%- if struct.enums %} 248{{namespace_end()}} 249namespace std { 250 251{%- for enum in struct.enums %} 252{%- if not enum|is_native_only_kind %} 253{{enum_hash(enum)}} 254{%- endif %} 255{%- endfor %} 256 257} // namespace std 258{{namespace_begin()}} 259{%- endif %} 260 261{%- for enum in struct.enums %} 262{%- if not enum|is_native_only_kind %} 263{{enum_stream_operator(enum)}} 264{{is_known_enum_value(enum)}} 265{%- endif %} 266{%- endfor %} 267{%- endfor %} 268 269{{namespace_end()}} 270 271namespace mojo { 272 273{#--- Enum Serialization Helpers -#} 274{%- for enum in enums %} 275{%- if not enum|is_native_only_kind %} 276{% include "enum_serialization_declaration.tmpl" %} 277{%- endif %} 278{%- endfor %} 279 280{%- for struct in structs %} 281{%- for enum in struct.enums %} 282{%- if not enum|is_native_only_kind %} 283{% include "enum_serialization_declaration.tmpl" %} 284{%- endif %} 285{%- endfor %} 286{%- endfor %} 287 288{%- for interface in interfaces %} 289{%- for enum in interface.enums %} 290{%- if not enum|is_native_only_kind %} 291{% include "enum_serialization_declaration.tmpl" %} 292{%- endif %} 293{%- endfor %} 294{%- endfor %} 295 296{#--- Struct Serialization Helpers -#} 297{% for struct in structs %} 298{%- if not struct|is_native_only_kind %} 299{% include "struct_serialization_declaration.tmpl" %} 300{%- endif %} 301{%- endfor %} 302 303{#--- Union Serialization Helpers -#} 304{% if unions %} 305{%- for union in unions %} 306{% include "union_serialization_declaration.tmpl" %} 307{%- endfor %} 308{%- endif %} 309 310} // namespace mojo 311 312#endif // {{header_guard}} 313