OLD | NEW |
1 // This file is generated | 1 // This file is generated |
2 | 2 |
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
6 | 6 |
7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h | 7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h |
8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h | 8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h |
9 | 9 |
10 {% if config.protocol.export_header %} | 10 {% if config.protocol.export_header %} |
11 #include {{format_include(config.protocol.export_header)}} | 11 #include {{format_include(config.protocol.export_header)}} |
12 {% endif %} | 12 {% endif %} |
13 #include "{{config.protocol.package}}/Protocol.h" | 13 #include {{format_include(config.protocol.package, "Protocol")}} |
14 // For each imported domain we generate a ValueConversions struct instead of a f
ull domain definition | 14 // For each imported domain we generate a ValueConversions struct instead of a f
ull domain definition |
15 // and include Domain::API version from there. | 15 // and include Domain::API version from there. |
16 {% for name in domain.dependencies %} | 16 {% for name in domain.dependencies %} |
17 #include "{{config.protocol.package}}/{{name}}.h" | 17 #include {{format_include(config.protocol.package, name)}} |
18 {% endfor %} | 18 {% endfor %} |
19 {% if domain["has_exports"] %} | 19 {% if domain["has_exports"] %} |
20 #include "{{config.exported.package}}/{{domain.domain}}.h" | 20 #include {{format_include(config.exported.package, domain.domain)}} |
21 {% endif %} | 21 {% endif %} |
22 | 22 |
23 {% for namespace in config.protocol.namespace %} | 23 {% for namespace in config.protocol.namespace %} |
24 namespace {{namespace}} { | 24 namespace {{namespace}} { |
25 {% endfor %} | 25 {% endfor %} |
26 namespace {{domain.domain}} { | 26 namespace {{domain.domain}} { |
27 | 27 |
28 // ------------- Forward and enum declarations. | 28 // ------------- Forward and enum declarations. |
29 {% for type in domain.types %} | 29 {% for type in domain.types %} |
30 {% if type.type == "object" %} | 30 {% if type.type == "object" %} |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 {% if "enum" in property %} | 81 {% if "enum" in property %} |
82 | 82 |
83 struct {{config.protocol.export_macro}} {{property.name | to_title_case}}Enu
m { | 83 struct {{config.protocol.export_macro}} {{property.name | to_title_case}}Enu
m { |
84 {% for literal in property.enum %} | 84 {% for literal in property.enum %} |
85 static const char* {{literal | dash_to_camelcase}}; | 85 static const char* {{literal | dash_to_camelcase}}; |
86 {% endfor %} | 86 {% endfor %} |
87 }; // {{property.name | to_title_case}}Enum | 87 }; // {{property.name | to_title_case}}Enum |
88 {% endif %} | 88 {% endif %} |
89 | 89 |
90 {% if property.optional %} | 90 {% if property.optional %} |
91 bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJ
ust(); } | 91 bool {{"has" | to_method_case}}{{property.name | to_title_case}}() { return
m_{{property.name}}.isJust(); } |
92 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas
e}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property
.name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; } | 92 {{resolve_type(property).raw_return_type}} {{"get" | to_method_case}}{{prope
rty.name | to_title_case}}({{resolve_type(property).raw_pass_type}} defaultValue
) { return m_{{property.name}}.isJust() ? m_{{property.name}}.fromJust() : defau
ltValue; } |
93 {% else %} | 93 {% else %} |
94 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas
e}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}};
} | 94 {{resolve_type(property).raw_return_type}} {{"get" | to_method_case}}{{prope
rty.name | to_title_case}}() { return {{resolve_type(property).to_raw_type % ("m
_" + property.name)}}; } |
95 {% endif %} | 95 {% endif %} |
96 void set{{property.name | to_title_case}}({{resolve_type(property).pass_type
}} value) { m_{{property.name}} = {{resolve_type(property).to_rvalue % "value"}}
; } | 96 void {{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_t
ype(property).pass_type}} value) { m_{{property.name}} = {{resolve_type(property
).to_rvalue % "value"}}; } |
97 {% endfor %} | 97 {% endfor %} |
98 | 98 |
99 std::unique_ptr<protocol::DictionaryValue> serialize() const; | 99 std::unique_ptr<protocol::DictionaryValue> serialize() const; |
100 std::unique_ptr<{{type.id}}> clone() const; | 100 std::unique_ptr<{{type.id}}> clone() const; |
101 {% if type.exported %} | 101 {% if type.exported %} |
102 {{config.exported.string_out}} toJSONString() const override; | 102 {{config.exported.string_out}} toJSONString() const override; |
103 {% endif %} | 103 {% endif %} |
104 | 104 |
105 template<int STATE> | 105 template<int STATE> |
106 class {{type.id}}Builder { | 106 class {{type.id}}Builder { |
107 public: | 107 public: |
108 enum { | 108 enum { |
109 NoFieldsSet = 0, | 109 NoFieldsSet = 0, |
110 {% set count = 0 %} | 110 {% set count = 0 %} |
111 {% for property in type.properties %} | 111 {% for property in type.properties %} |
112 {% if not(property.optional) %} | 112 {% if not(property.optional) %} |
113 {% set count = count + 1 %} | 113 {% set count = count + 1 %} |
114 {{property.name | to_title_case}}Set = 1 << {{count}}, | 114 {{property.name | to_title_case}}Set = 1 << {{count}}, |
115 {% endif %} | 115 {% endif %} |
116 {% endfor %} | 116 {% endfor %} |
117 AllFieldsSet = ( | 117 AllFieldsSet = ( |
118 {%- for property in type.properties %} | 118 {%- for property in type.properties %} |
119 {% if not(property.optional) %}{{property.name | to_title_case}}Set | {%en
dif %} | 119 {% if not(property.optional) %}{{property.name | to_title_case}}Set | {%en
dif %} |
120 {% endfor %}0)}; | 120 {% endfor %}0)}; |
121 | 121 |
122 {% for property in type.properties %} | 122 {% for property in type.properties %} |
123 | 123 |
124 {% if property.optional %} | 124 {% if property.optional %} |
125 {{type.id}}Builder<STATE>& set{{property.name | to_title_case}}({{resolv
e_type(property).pass_type}} value) | 125 {{type.id}}Builder<STATE>& {{"set" | to_method_case}}{{property.name | t
o_title_case}}({{resolve_type(property).pass_type}} value) |
126 { | 126 { |
127 m_result->set{{property.name | to_title_case}}({{resolve_type(proper
ty).to_rvalue % "value"}}); | 127 m_result->{{"set" | to_method_case}}{{property.name | to_title_case}
}({{resolve_type(property).to_rvalue % "value"}}); |
128 return *this; | 128 return *this; |
129 } | 129 } |
130 {% else %} | 130 {% else %} |
131 {{type.id}}Builder<STATE | {{property.name | to_title_case}}Set>& set{{p
roperty.name | to_title_case}}({{resolve_type(property).pass_type}} value) | 131 {{type.id}}Builder<STATE | {{property.name | to_title_case}}Set>& {{"set
" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).p
ass_type}} value) |
132 { | 132 { |
133 static_assert(!(STATE & {{property.name | to_title_case}}Set), "prop
erty {{property.name}} should not be set yet"); | 133 static_assert(!(STATE & {{property.name | to_title_case}}Set), "prop
erty {{property.name}} should not be set yet"); |
134 m_result->set{{property.name | to_title_case}}({{resolve_type(proper
ty).to_rvalue % "value"}}); | 134 m_result->{{"set" | to_method_case}}{{property.name | to_title_case}
}({{resolve_type(property).to_rvalue % "value"}}); |
135 return castState<{{property.name | to_title_case}}Set>(); | 135 return castState<{{property.name | to_title_case}}Set>(); |
136 } | 136 } |
137 {% endif %} | 137 {% endif %} |
138 {% endfor %} | 138 {% endfor %} |
139 | 139 |
140 std::unique_ptr<{{type.id}}> build() | 140 std::unique_ptr<{{type.id}}> {{"build" | to_method_case}}() |
141 { | 141 { |
142 static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet")
; | 142 static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet")
; |
143 return std::move(m_result); | 143 return std::move(m_result); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 friend class {{type.id}}; | 147 friend class {{type.id}}; |
148 {{type.id}}Builder() : m_result(new {{type.id}}()) { } | 148 {{type.id}}Builder() : m_result(new {{type.id}}()) { } |
149 | 149 |
150 template<int STEP> {{type.id}}Builder<STATE | STEP>& castState() | 150 template<int STEP> {{type.id}}Builder<STATE | STEP>& castState() |
151 { | 151 { |
152 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this); | 152 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this); |
153 } | 153 } |
154 | 154 |
155 {{type_def.type}} m_result; | 155 {{type_def.type}} m_result; |
156 }; | 156 }; |
157 | 157 |
158 static {{type.id}}Builder<0> create() | 158 static {{type.id}}Builder<0> {{"create" | to_method_case}}() |
159 { | 159 { |
160 return {{type.id}}Builder<0>(); | 160 return {{type.id}}Builder<0>(); |
161 } | 161 } |
162 | 162 |
163 private: | 163 private: |
164 {{type.id}}() | 164 {{type.id}}() |
165 { | 165 { |
166 {% for property in type.properties %} | 166 {% for property in type.properties %} |
167 {% if not(property.optional) and "default_value" in resolve_type(property)
%} | 167 {% if not(property.optional) and "default_value" in resolve_type(property)
%} |
168 m_{{property.name}} = {{resolve_type(property).default_value}}; | 168 m_{{property.name}} = {{resolve_type(property).default_value}}; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 201 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
202 {%- endif -%} | 202 {%- endif -%} |
203 {%- if not loop.last -%}, {% endif -%} | 203 {%- if not loop.last -%}, {% endif -%} |
204 {%- endfor -%} | 204 {%- endfor -%} |
205 ) = 0; | 205 ) = 0; |
206 virtual void sendFailure(const DispatchResponse&) = 0; | 206 virtual void sendFailure(const DispatchResponse&) = 0; |
207 virtual ~{{command.name | to_title_case}}Callback() { } | 207 virtual ~{{command.name | to_title_case}}Callback() { } |
208 }; | 208 }; |
209 {% endif %} | 209 {% endif %} |
210 {%- if not is_async_command(domain.domain, command.name) %} | 210 {%- if not is_async_command(domain.domain, command.name) %} |
211 virtual DispatchResponse {{command.name}}( | 211 virtual DispatchResponse {{command.name | to_method_case}}( |
212 {%- else %} | 212 {%- else %} |
213 virtual void {{command.name}}( | 213 virtual void {{command.name | to_method_case}}( |
214 {%- endif %} | 214 {%- endif %} |
215 {%- for parameter in command.parameters -%} | 215 {%- for parameter in command.parameters -%} |
216 {%- if not loop.first -%}, {% endif -%} | 216 {%- if not loop.first -%}, {% endif -%} |
217 {%- if "optional" in parameter -%} | 217 {%- if "optional" in parameter -%} |
218 Maybe<{{resolve_type(parameter).raw_type}}> in_{{parameter.name}} | 218 Maybe<{{resolve_type(parameter).raw_type}}> in_{{parameter.name}} |
219 {%- else -%} | 219 {%- else -%} |
220 {{resolve_type(parameter).pass_type}} in_{{parameter.name}} | 220 {{resolve_type(parameter).pass_type}} in_{{parameter.name}} |
221 {%- endif -%} | 221 {%- endif -%} |
222 {%- endfor -%} | 222 {%- endfor -%} |
223 {%- if is_async_command(domain.domain, command.name) -%} | 223 {%- if is_async_command(domain.domain, command.name) -%} |
224 {%- if command.parameters -%}, {% endif -%} | 224 {%- if command.parameters -%}, {% endif -%} |
225 std::unique_ptr<{{command.name | to_title_case}}Callback> callback | 225 std::unique_ptr<{{command.name | to_title_case}}Callback> callback |
226 {%- else -%} | 226 {%- else -%} |
227 {%- for parameter in command.returns -%} | 227 {%- for parameter in command.returns -%} |
228 {%- if (not loop.first) or command.parameters -%}, {% endif -%} | 228 {%- if (not loop.first) or command.parameters -%}, {% endif -%} |
229 {%- if "optional" in parameter -%} | 229 {%- if "optional" in parameter -%} |
230 Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}} | 230 Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}} |
231 {%- else -%} | 231 {%- else -%} |
232 {{resolve_type(parameter).type}}* out_{{parameter.name}} | 232 {{resolve_type(parameter).type}}* out_{{parameter.name}} |
233 {%- endif -%} | 233 {%- endif -%} |
234 {%- endfor -%} | 234 {%- endfor -%} |
235 {%- endif -%} | 235 {%- endif -%} |
236 ) = 0; | 236 ) = 0; |
237 {% endfor %} | 237 {% endfor %} |
238 | 238 |
239 {% if generate_disable(domain) %} | 239 {% if generate_disable(domain) %} |
240 virtual DispatchResponse disable() | 240 virtual DispatchResponse {{"disable" | to_method_case}}() |
241 { | 241 { |
242 return DispatchResponse::OK(); | 242 return DispatchResponse::OK(); |
243 } | 243 } |
244 {% endif %} | 244 {% endif %} |
245 }; | 245 }; |
246 | 246 |
247 // ------------- Frontend interface. | 247 // ------------- Frontend interface. |
248 | 248 |
249 class {{config.protocol.export_macro}} Frontend { | 249 class {{config.protocol.export_macro}} Frontend { |
250 public: | 250 public: |
251 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann
el) { } | 251 explicit Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(fron
tendChannel) { } |
252 {% for event in domain.events %} | 252 {% for event in domain.events %} |
253 {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif
%} | 253 {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif
%} |
254 void {{event.name}}( | 254 void {{event.name | to_method_case}}( |
255 {%- for parameter in event.parameters -%} | 255 {%- for parameter in event.parameters -%} |
256 {%- if "optional" in parameter -%} | 256 {%- if "optional" in parameter -%} |
257 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{
{resolve_type(parameter).raw_type}}>() | 257 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{
{resolve_type(parameter).raw_type}}>() |
258 {%- else -%} | 258 {%- else -%} |
259 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 259 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
260 {%- endif -%}{%- if not loop.last -%}, {% endif -%} | 260 {%- endif -%}{%- if not loop.last -%}, {% endif -%} |
261 {%- endfor -%} | 261 {%- endfor -%} |
262 ); | 262 ); |
263 {% endfor %} | 263 {% endfor %} |
264 | 264 |
(...skipping 23 matching lines...) Expand all Loading... |
288 static const char commandPrefix[]; | 288 static const char commandPrefix[]; |
289 static const char version[]; | 289 static const char version[]; |
290 }; | 290 }; |
291 | 291 |
292 } // namespace {{domain.domain}} | 292 } // namespace {{domain.domain}} |
293 {% for namespace in config.protocol.namespace %} | 293 {% for namespace in config.protocol.namespace %} |
294 } // namespace {{namespace}} | 294 } // namespace {{namespace}} |
295 {% endfor %} | 295 {% endfor %} |
296 | 296 |
297 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h) | 297 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h) |
OLD | NEW |