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 #include "{{config.class_export.header}}" | 10 {% if config.protocol.export_header %} |
| 11 #include {{format_include(config.protocol.export_header)}} |
| 12 {% endif %} |
11 #include "{{config.protocol.package}}/Protocol.h" | 13 #include "{{config.protocol.package}}/Protocol.h" |
12 // 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 |
13 // and include Domain::API version from there. | 15 // and include Domain::API version from there. |
14 {% for name in domain.dependencies %} | 16 {% for name in domain.dependencies %} |
15 #include "{{config.protocol.package}}/{{name}}.h" | 17 #include "{{config.protocol.package}}/{{name}}.h" |
16 {% endfor %} | 18 {% endfor %} |
17 {% if domain["has_exports"] %} | 19 {% if domain["has_exports"] %} |
18 #include "{{config.exported.package}}/{{domain.domain}}.h" | 20 #include "{{config.exported.package}}/{{domain.domain}}.h" |
19 {% endif %} | 21 {% endif %} |
20 | 22 |
(...skipping 15 matching lines...) Expand all Loading... |
36 {% elif type.type != "array" %} | 38 {% elif type.type != "array" %} |
37 // {{type.description}} | 39 // {{type.description}} |
38 using {{type.id}} = {{resolve_type(type).type}}; | 40 using {{type.id}} = {{resolve_type(type).type}}; |
39 {% endif %} | 41 {% endif %} |
40 {% endfor %} | 42 {% endfor %} |
41 {% for type in domain.types %} | 43 {% for type in domain.types %} |
42 {% if "enum" in type %} | 44 {% if "enum" in type %} |
43 | 45 |
44 namespace {{type.id}}Enum { | 46 namespace {{type.id}}Enum { |
45 {% for literal in type.enum %} | 47 {% for literal in type.enum %} |
46 {{config.class_export.macro}} extern const char* {{ literal | dash_to_camelcase}
}; | 48 {{config.protocol.export_macro}} extern const char* {{ literal | dash_to_camelca
se}}; |
47 {% endfor %} | 49 {% endfor %} |
48 } // namespace {{type.id}}Enum | 50 } // namespace {{type.id}}Enum |
49 {% endif %} | 51 {% endif %} |
50 {% endfor %} | 52 {% endfor %} |
51 {% for command in join_arrays(domain, ["commands", "events"]) %} | 53 {% for command in join_arrays(domain, ["commands", "events"]) %} |
52 {% for param in join_arrays(command, ["parameters", "returns"]) %} | 54 {% for param in join_arrays(command, ["parameters", "returns"]) %} |
53 {% if "enum" in param %} | 55 {% if "enum" in param %} |
54 | 56 |
55 namespace {{command.name | to_title_case}} { | 57 namespace {{command.name | to_title_case}} { |
56 namespace {{param.name | to_title_case}}Enum { | 58 namespace {{param.name | to_title_case}}Enum { |
57 {% for literal in param.enum %} | 59 {% for literal in param.enum %} |
58 {{config.class_export.macro}} extern const char* {{literal | dash_to_camelcase}}
; | 60 {{config.protocol.export_macro}} extern const char* {{literal | dash_to_camelcas
e}}; |
59 {% endfor %} | 61 {% endfor %} |
60 } // {{param.name | to_title_case}}Enum | 62 } // {{param.name | to_title_case}}Enum |
61 } // {{command.name | to_title_case }} | 63 } // {{command.name | to_title_case }} |
62 {% endif %} | 64 {% endif %} |
63 {% endfor %} | 65 {% endfor %} |
64 {% endfor %} | 66 {% endfor %} |
65 | 67 |
66 // ------------- Type and builder declarations. | 68 // ------------- Type and builder declarations. |
67 {% for type in domain.types %} | 69 {% for type in domain.types %} |
68 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} | 70 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} |
69 {% set type_def = type_definition(domain.domain + "." + type.id)%} | 71 {% set type_def = type_definition(domain.domain + "." + type.id)%} |
70 | 72 |
71 // {{type.description}} | 73 // {{type.description}} |
72 class {{config.class_export.macro}} {{type.id}} {% if type.exported %}: public A
PI::{{type.id}} {% endif %}{ | 74 class {{config.protocol.export_macro}} {{type.id}} {% if type.exported %}: publi
c API::{{type.id}} {% endif %}{ |
73 PROTOCOL_DISALLOW_COPY({{type.id}}); | 75 PROTOCOL_DISALLOW_COPY({{type.id}}); |
74 public: | 76 public: |
75 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo
rt* errors); | 77 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo
rt* errors); |
76 | 78 |
77 ~{{type.id}}() { } | 79 ~{{type.id}}() { } |
78 {% for property in type.properties %} | 80 {% for property in type.properties %} |
79 {% if "enum" in property %} | 81 {% if "enum" in property %} |
80 | 82 |
81 struct {{config.class_export.macro}} {{property.name | to_title_case}}Enum { | 83 struct {{config.protocol.export_macro}} {{property.name | to_title_case}}Enu
m { |
82 {% for literal in property.enum %} | 84 {% for literal in property.enum %} |
83 static const char* {{literal | dash_to_camelcase}}; | 85 static const char* {{literal | dash_to_camelcase}}; |
84 {% endfor %} | 86 {% endfor %} |
85 }; // {{property.name | to_title_case}}Enum | 87 }; // {{property.name | to_title_case}}Enum |
86 {% endif %} | 88 {% endif %} |
87 | 89 |
88 {% if property.optional %} | 90 {% if property.optional %} |
89 bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJ
ust(); } | 91 bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJ
ust(); } |
90 {{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{{property.name | to_title_cas
e}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property
.name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; } |
91 {% else %} | 93 {% else %} |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 {% else %} | 176 {% else %} |
175 {{resolve_type(property).type}} m_{{property.name}}; | 177 {{resolve_type(property).type}} m_{{property.name}}; |
176 {% endif %} | 178 {% endif %} |
177 {% endfor %} | 179 {% endfor %} |
178 }; | 180 }; |
179 | 181 |
180 {% endfor %} | 182 {% endfor %} |
181 | 183 |
182 // ------------- Backend interface. | 184 // ------------- Backend interface. |
183 | 185 |
184 class {{config.class_export.macro}} Backend { | 186 class {{config.protocol.export_macro}} Backend { |
185 public: | 187 public: |
186 {% for command in domain.commands %} | 188 {% for command in domain.commands %} |
187 {% if "redirect" in command %}{% continue %}{% endif %} | 189 {% if "redirect" in command %}{% continue %}{% endif %} |
188 {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}
{% continue %}{% endif %} | 190 {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}
{% continue %}{% endif %} |
189 {% if "async" in command %} | 191 {% if "async" in command %} |
190 class {{config.class_export.macro}} {{command.name | to_title_case}}Callback
: public BackendCallback { | 192 class {{config.protocol.export_macro}} {{command.name | to_title_case}}Callb
ack : public BackendCallback { |
191 public: | 193 public: |
192 virtual void sendSuccess( | 194 virtual void sendSuccess( |
193 {%- for parameter in command.returns -%} | 195 {%- for parameter in command.returns -%} |
194 {%- if "optional" in parameter -%} | 196 {%- if "optional" in parameter -%} |
195 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}
} | 197 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}
} |
196 {%- else -%} | 198 {%- else -%} |
197 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 199 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
198 {%- endif -%} | 200 {%- endif -%} |
199 {%- if not loop.last -%}, {% endif -%} | 201 {%- if not loop.last -%}, {% endif -%} |
200 {%- endfor -%} | 202 {%- endfor -%} |
(...skipping 30 matching lines...) Expand all Loading... |
231 {% if not has_disable(domain.commands) %} | 233 {% if not has_disable(domain.commands) %} |
232 virtual void disable(ErrorString*) { } | 234 virtual void disable(ErrorString*) { } |
233 {% endif %} | 235 {% endif %} |
234 | 236 |
235 protected: | 237 protected: |
236 virtual ~Backend() { } | 238 virtual ~Backend() { } |
237 }; | 239 }; |
238 | 240 |
239 // ------------- Frontend interface. | 241 // ------------- Frontend interface. |
240 | 242 |
241 class {{config.class_export.macro}} Frontend { | 243 class {{config.protocol.export_macro}} Frontend { |
242 public: | 244 public: |
243 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann
el) { } | 245 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann
el) { } |
244 {% for event in domain.events %} | 246 {% for event in domain.events %} |
245 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con
tinue %}{% endif %} | 247 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con
tinue %}{% endif %} |
246 void {{event.name}}( | 248 void {{event.name}}( |
247 {%- for parameter in event.parameters -%} | 249 {%- for parameter in event.parameters -%} |
248 {%- if "optional" in parameter -%} | 250 {%- if "optional" in parameter -%} |
249 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} =
Maybe<{{resolve_type(parameter).raw_type}}>() | 251 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} =
Maybe<{{resolve_type(parameter).raw_type}}>() |
250 {%- else -%} | 252 {%- else -%} |
251 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 253 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
252 {%- endif -%}{%- if not loop.last -%}, {% endif -%} | 254 {%- endif -%}{%- if not loop.last -%}, {% endif -%} |
253 {%- endfor -%} | 255 {%- endfor -%} |
254 ); | 256 ); |
255 {% endfor %} | 257 {% endfor %} |
256 | 258 |
257 void flush(); | 259 void flush(); |
258 private: | 260 private: |
259 FrontendChannel* m_frontendChannel; | 261 FrontendChannel* m_frontendChannel; |
260 }; | 262 }; |
261 | 263 |
262 // ------------- Dispatcher. | 264 // ------------- Dispatcher. |
263 | 265 |
264 class {{config.class_export.macro}} Dispatcher { | 266 class {{config.protocol.export_macro}} Dispatcher { |
265 public: | 267 public: |
266 static void wire(UberDispatcher*, Backend*); | 268 static void wire(UberDispatcher*, Backend*); |
267 | 269 |
268 private: | 270 private: |
269 Dispatcher() { } | 271 Dispatcher() { } |
270 }; | 272 }; |
271 | 273 |
272 // ------------- Metainfo. | 274 // ------------- Metainfo. |
273 | 275 |
274 class {{config.class_export.macro}} Metainfo { | 276 class {{config.protocol.export_macro}} Metainfo { |
275 public: | 277 public: |
276 using BackendClass = Backend; | 278 using BackendClass = Backend; |
277 using FrontendClass = Frontend; | 279 using FrontendClass = Frontend; |
278 using DispatcherClass = Dispatcher; | 280 using DispatcherClass = Dispatcher; |
279 static const char domainName[]; | 281 static const char domainName[]; |
280 static const char commandPrefix[]; | 282 static const char commandPrefix[]; |
281 static const char version[]; | 283 static const char version[]; |
282 }; | 284 }; |
283 | 285 |
284 } // namespace {{domain.domain}} | 286 } // namespace {{domain.domain}} |
285 {% for namespace in config.protocol.namespace %} | 287 {% for namespace in config.protocol.namespace %} |
286 } // namespace {{namespace}} | 288 } // namespace {{namespace}} |
287 {% endfor %} | 289 {% endfor %} |
288 | 290 |
289 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h) | 291 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h) |
OLD | NEW |