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{%- macro kythe_annotation(name) %}
34{%- if enable_kythe_annotations %}
35// @generated_from: {{name}}
36{%- endif %}
37{%- endmacro %}
38
39#ifndef {{header_guard}}
40#define {{header_guard}}
41
42#include <stdint.h>
43
44#include <limits>
45#include <type_traits>
46#include <utility>
47
48#include "base/callback.h"
49#include "base/macros.h"
50#include "base/optional.h"
51
52#include "mojo/public/cpp/bindings/mojo_buildflags.h"
53#if BUILDFLAG(MOJO_TRACE_ENABLED)
54#include "base/trace_event/trace_event.h"
55#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
56#include "mojo/public/cpp/bindings/clone_traits.h"
57#include "mojo/public/cpp/bindings/equals_traits.h"
58#include "mojo/public/cpp/bindings/lib/serialization.h"
59#include "mojo/public/cpp/bindings/struct_ptr.h"
60#include "mojo/public/cpp/bindings/struct_traits.h"
61#include "mojo/public/cpp/bindings/union_traits.h"
62#include "{{module.path}}-shared.h"
63#include "{{variant_path}}-forward.h"
64
65{%- for import in imports %}
66{%-   if import|is_full_header_required_for_import %}
67{%-     if variant %}
68#include "{{"%s-%s.h"|format(import.path, variant)}}"
69{%-     else %}
70#include "{{import.path}}.h"
71{%-     endif %}
72{%-   else %}
73{%-     if variant %}
74#include "{{"%s-%s-forward.h"|format(import.path, variant)}}"
75{%-     else %}
76#include "{{import.path}}-forward.h"
77{%-     endif %}
78{%-   endif %}
79{%- endfor %}
80
81{%- if not for_blink %}
82#include <string>
83#include <vector>
84{%- else %}
85{# hash_util.h includes template specializations that should be present for
86   every use of {Inlined}StructPtr. #}
87#include "mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h"
88#include "mojo/public/cpp/bindings/lib/wtf_hash_util.h"
89#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
90#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
91{%- endif %}
92
93{% if not disallow_interfaces and uses_interfaces -%}
94#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
95#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
96#include "mojo/public/cpp/bindings/associated_interface_request.h"
97#include "mojo/public/cpp/bindings/interface_ptr.h"
98#include "mojo/public/cpp/bindings/interface_request.h"
99#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
100#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
101#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
102{%- endif %}
103
104{% if not disallow_native_types and uses_native_types %}
105#include "mojo/public/cpp/bindings/lib/native_enum_serialization.h"
106#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
107{%- endif %}
108
109{%- for header in extra_public_headers %}
110#include "{{header}}"
111{%- endfor %}
112
113{%- if export_header %}
114#include "{{export_header}}"
115{%- endif %}
116
117{% if enable_kythe_annotations -%}
118#ifdef KYTHE_IS_RUNNING
119#pragma kythe_inline_metadata "Metadata comment"
120#endif
121{%- endif %}
122
123{#--- WTF enum hashing #}
124{%- from "enum_macros.tmpl" import enum_hash_blink%}
125{%- if for_blink %}
126{%-   for enum in all_enums %}
127{%-     if not enum|is_native_only_kind %}
128{{enum_hash_blink(enum)}}
129{%-     endif %}
130{%-   endfor %}
131{%- endif %}
132
133// Forward-declare for |AsValueInto| so that we do not have to import the
134// corresponding header.
135namespace base {
136namespace trace_event {
137class TracedValue;
138}  // namespace trace_event
139}  // namespace base
140
141{{namespace_begin()}}
142
143{%- set module_prefix = "%s"|format(namespaces_as_array|join(".")) %}
144
145{#--- Interfaces -#}
146{%  for interface in interfaces %}
147{%    include "interface_declaration.tmpl" %}
148{%- endfor %}
149
150{#--- Interface Proxies -#}
151{%  for interface in interfaces %}
152{%    include "interface_proxy_declaration.tmpl" %}
153{%- endfor %}
154
155{#--- Interface Stubs -#}
156{%  for interface in interfaces %}
157{%    include "interface_stub_declaration.tmpl" %}
158{%- endfor %}
159
160{#--- Interface Request Validators -#}
161{%  for interface in interfaces %}
162{%    include "interface_request_validator_declaration.tmpl" %}
163{%- endfor %}
164
165{#--- Interface Response Validators -#}
166{%  for interface in interfaces if interface|has_callbacks %}
167{%    include "interface_response_validator_declaration.tmpl" %}
168{%- endfor %}
169
170{#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs,
171      so we need to fully define inlined structs ahead of the others. #}
172
173{#--- Inlined structs #}
174{%  for struct in structs %}
175{%    if struct|should_inline and not struct|is_native_only_kind %}
176{%      include "wrapper_class_declaration.tmpl" %}
177{%    endif %}
178{%- endfor %}
179
180{#--- Unions must be declared before non-inlined structs because they can be
181      members of structs. #}
182{#--- Unions #}
183{%  for union in unions %}
184{%    include "wrapper_union_class_declaration.tmpl" %}
185{%- endfor %}
186
187{#--- Non-inlined structs #}
188{%  for struct in structs %}
189{%    if not struct|should_inline and not struct|is_native_only_kind %}
190{%      include "wrapper_class_declaration.tmpl" %}
191{%    endif %}
192{%- endfor %}
193
194{%- for union in unions %}
195{%    include "wrapper_union_class_template_definition.tmpl" %}
196{%- endfor %}
197
198{%- for struct in structs %}
199{%-   if not struct|is_native_only_kind %}
200{%      include "wrapper_class_template_definition.tmpl" %}
201{%-   endif %}
202{%- endfor %}
203
204{{namespace_end()}}
205
206namespace mojo {
207
208{#--- Struct Serialization Helpers -#}
209{%  for struct in structs %}
210{%-   if not struct|is_native_only_kind %}
211{%      include "struct_traits_declaration.tmpl" %}
212{%-   endif %}
213{%- endfor %}
214
215{#--- Union Serialization Helpers -#}
216{%  if unions %}
217{%-   for union in unions %}
218{%      include "union_traits_declaration.tmpl" %}
219{%-   endfor %}
220{%- endif %}
221
222}  // namespace mojo
223
224#endif  // {{header_guard}}
225