summaryrefslogtreecommitdiffstats
path: root/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
blob: 3d0ce78dff76e9fbc03c9a29097c1a66dd0124c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

{%- if variant -%}
{%-   set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%-   set variant_path = module.path -%}
{%- endif -%}

{%- set header_guard = "%s_H_"|format(
        variant_path|upper|replace("/","_")|replace(".","_")|
            replace("-", "_")) %}

#ifndef {{header_guard}}
#define {{header_guard}}

#include <stdint.h>
#include <ostream>

#include "base/strings/string_piece.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/map.h"
#include "mojo/public/cpp/bindings/message_filter.h"
#include "mojo/public/cpp/bindings/no_interface.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "{{variant_path}}-internal.h"
{%- for import in imports %}
{%-   if variant %}
#include "{{"%s-%s.h"|format(import.module.path, variant)}}"
{%-   else %}
#include "{{import.module.path}}.h"
{%-   endif %}
{%- endfor %}
{%- if not for_blink %}
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/string.h"
{%- else %}
#include "mojo/public/cpp/bindings/wtf_array.h"
#include "third_party/WebKit/Source/wtf/text/WTFString.h"
{%- endif %}

{%- for header in extra_public_headers %}
#include "{{header}}"
{%- endfor %}

{%- for namespace in namespaces_as_array %}
namespace {{namespace}} {
{%- endfor %}
{%- if variant %}
namespace {{variant}} {
{%- endif %}

{#--- Enums #}
{% from "enum_macros.tmpl" import enum_decl -%}
{% from "enum_macros.tmpl" import enum_stream_operator -%}
{% from "enum_macros.tmpl" import is_known_enum_value -%}
{%- for enum in enums %}
  {{enum_decl(enum)}}
  {{enum_stream_operator(enum)}}
  {{is_known_enum_value(enum)}}
{%- endfor %}

{#--- Constants #}
{%- for constant in module.constants %}
{#-   To be consistent with constants defined inside interfaces, only make
      integral types compile-time constants. #}
{%-   if constant.kind|is_integral_kind %}
const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_value}};
{%-   else %}
extern const {{constant.kind|cpp_pod_type}} {{constant.name}};
{%-   endif %}
{%- endfor %}

{#--- Interface Forward Declarations -#}
{%  for interface in interfaces %}
class {{interface.name}};
using {{interface.name}}Ptr = mojo::InterfacePtr<{{interface.name}}>;
using {{interface.name}}PtrInfo = mojo::InterfacePtrInfo<{{interface.name}}>;
using {{interface.name}}Request = mojo::InterfaceRequest<{{interface.name}}>;
using {{interface.name}}AssociatedPtr =
    mojo::AssociatedInterfacePtr<{{interface.name}}>;
using {{interface.name}}AssociatedPtrInfo =
    mojo::AssociatedInterfacePtrInfo<{{interface.name}}>;
using {{interface.name}}AssociatedRequest =
    mojo::AssociatedInterfaceRequest<{{interface.name}}>;
{%  endfor %}

{#--- Struct Forward Declarations -#}
{%  for struct in structs %}
class {{struct.name}};
class {{struct.name}}_Reader;
{%    if struct|should_inline %}
using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>;
{%    else %}
using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>;
{%    endif %}
{%  endfor %}

{#--- Union Forward Declarations -#}
{%  for union in unions %}
class {{union.name}};
{%    if union|should_inline_union %}
typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr;
{%    else %}
typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr;
{%    endif %}
{%- endfor %}

{#--- Interfaces -#}
{%  for interface in interfaces %}
{%    include "interface_declaration.tmpl" %}
{%- endfor %}

{#--- Interface Proxies -#}
{%  for interface in interfaces %}
{%    include "interface_proxy_declaration.tmpl" %}
{%- endfor %}

{#--- Interface Stubs -#}
{%  for interface in interfaces %}
{%    include "interface_stub_declaration.tmpl" %}
{%- endfor %}

{#--- Interface Request Validators -#}
{%  for interface in interfaces %}
{%    include "interface_request_validator_declaration.tmpl" %}
{%- endfor %}

{#--- Interface Response Validators -#}
{%  for interface in interfaces if interface|has_callbacks %}
{%    include "interface_response_validator_declaration.tmpl" %}
{%- endfor %}

{#--- Unions must be declared first because they can be members of structs #}
{#--- Unions #}
{%  for union in unions %}
{%    include "wrapper_union_class_declaration.tmpl" %}
{%- endfor %}

{#--- NOTE: Non-inlined structs may have pointers to inlined structs, so we  #}
{#---       need to fully define inlined structs ahead of the others.        #}

{#--- Inlined structs #}
{%  for struct in structs %}
{%    if struct|should_inline %}
{%      include "wrapper_class_declaration.tmpl" %}
{%    endif %}
{%- endfor %}

{#--- Non-inlined structs #}
{%  for struct in structs %}
{%    if not struct|should_inline %}
{%      include "wrapper_class_declaration.tmpl" %}
{%    endif %}
{%- endfor %}

{#--- Struct Serialization Helpers -#}
{%  if structs %}
{%    for struct in structs %}
{%      include "struct_serialization_declaration.tmpl" %}
{%-   endfor %}
{%- endif %}

{#--- Union Serialization Helpers -#}
{%  if unions %}
{%    for union in unions %}
{%      include "union_serialization_declaration.tmpl" %}
{%-   endfor %}
{%- endif %}

{%- for struct in structs %}
{%-   for enum in struct.enums %}
{{enum_stream_operator(enum)}}
{{is_known_enum_value(enum)}}
{%-   endfor %}
{%- endfor %}

{%- for interface in interfaces %}
{%-   for enum in interface.enums %}
{{enum_stream_operator(enum)}}
{{is_known_enum_value(enum)}}
{%-   endfor %}
{%- endfor %}

{%- if variant %}
}  // namespace {{variant}}
{%- endif %}
{%- for namespace in namespaces_as_array|reverse %}
}  // namespace {{namespace}}
{%- endfor %}

#endif  // {{header_guard}}