summaryrefslogtreecommitdiffstats
path: root/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl
blob: b22f85309100b574778a75b0eff353c9a5e781ee (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
// 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 %}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4056)
#pragma warning(disable:4065)
#pragma warning(disable:4756)
#endif

#include "{{variant_path}}.h"

#include <math.h>
#include <stdint.h>
#include <utility>

#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
#include "mojo/public/cpp/bindings/lib/map_data_internal.h"
#include "mojo/public/cpp/bindings/lib/message_builder.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"

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

{#--- Constants #}
{%- for constant in module.constants %}
{%-   if not constant.kind|is_integral_kind %}
const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_value}};
{%-   endif %}
{%- endfor %}

namespace internal {
namespace {

#pragma pack(push, 1)

{#--- Interface parameter definitions #}
{%- for interface in interfaces %}
{%-   for method in interface.methods %}
{%-     set method_name = "k%s_%s_Name"|format(interface.name, method.name) %}
const uint32_t {{method_name}} = {{method.ordinal}};
{%      set struct = method.param_struct %}
{%      include "struct_declaration.tmpl" %}
{%-     include "struct_definition.tmpl" %}
{%-     if method.response_parameters != None %}
{%-       set struct = method.response_param_struct %}
{%        include "struct_declaration.tmpl" %}
{%-       include "struct_definition.tmpl" %}
{%-     endif %}
{%-   endfor %}
{%- endfor %}

#pragma pack(pop)

}  // namespace

{#--- Struct definitions #}
{%  for struct in structs %}
{%-   include "struct_definition.tmpl" %}
{%- endfor %}

{#--- Union definitions #}
{%  for union in unions %}
{%-   include "union_definition.tmpl" %}
{%- endfor %}

}  // namespace internal

{#--- Struct Constants #}
{%- for struct in structs %}
{%-   for constant in struct.constants %}
{%-     if constant.kind|is_integral_kind %}
MOJO_STATIC_CONST_MEMBER_DEFINITION const {{constant.kind|cpp_pod_type}} {{struct.name}}::{{constant.name}};
{%-     else %}
MOJO_STATIC_CONST_MEMBER_DEFINITION const {{constant.kind|cpp_pod_type}} {{struct.name}}::{{constant.name}} = {{constant|constant_value}};
{%-     endif %}
{%-   endfor %}
{%- endfor %}

{#--- Struct builder definitions #}
{%- for struct in structs %}
{%-   include "wrapper_class_definition.tmpl" %}
{%- endfor %}

{#--- Union builder definitions #}
{%- for union in unions %}
{%-   include "wrapper_union_class_definition.tmpl" %}
{%- endfor %}

{#--- Interface definitions #}
{%- for interface in interfaces %}
{%-   include "interface_definition.tmpl" %}
{%- endfor %}

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

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

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

#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif