Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_h.template

Issue 2282283002: [DevTools] Prepare inspector_protocol build to move. (Closed)
Patch Set: NOTREACHED Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // This file is generated
2
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
5 // found in the LICENSE file.
6
7 #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h
8 #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h
9
10 #include "{{config.class_export.header}}"
11 #include "{{config.protocol.package}}/Protocol.h"
12 // For each imported domain we generate a ValueConversions struct instead of a f ull domain definition
13 // and include Domain::API version from there.
14 {% for name in domain.dependencies %}
15 #include "{{config.protocol.package}}/{{name}}.h"
16 {% endfor %}
17 {% if domain["has_exports"] %}
18 #include "{{config.exported.package}}/{{domain.domain}}.h"
19 {% endif %}
20
21 {% for namespace in config.protocol.namespace %}
22 namespace {{namespace}} {
23 {% endfor %}
24 namespace {{domain.domain}} {
25
26 // ------------- Forward and enum declarations.
27 {% for type in domain.types %}
28 {% if type.type == "object" %}
29 {% if "properties" in type %}
30 // {{type.description}}
31 class {{type.id}};
32 {% else %}
33 // {{type.description}}
34 using {{type.id}} = Object;
35 {% endif %}
36 {% elif type.type != "array" %}
37 // {{type.description}}
38 using {{type.id}} = {{resolve_type(type).type}};
39 {% endif %}
40 {% endfor %}
41 {% for type in domain.types %}
42 {% if "enum" in type %}
43
44 namespace {{type.id}}Enum {
45 {% for literal in type.enum %}
46 {{config.class_export.macro}} extern const char* {{ literal | dash_to_camelcase} };
47 {% endfor %}
48 } // namespace {{type.id}}Enum
49 {% endif %}
50 {% endfor %}
51 {% for command in join_arrays(domain, ["commands", "events"]) %}
52 {% for param in join_arrays(command, ["parameters", "returns"]) %}
53 {% if "enum" in param %}
54
55 namespace {{command.name | to_title_case}} {
56 namespace {{param.name | to_title_case}}Enum {
57 {% for literal in param.enum %}
58 {{config.class_export.macro}} extern const char* {{literal | dash_to_camelcase}} ;
59 {% endfor %}
60 } // {{param.name | to_title_case}}Enum
61 } // {{command.name | to_title_case }}
62 {% endif %}
63 {% endfor %}
64 {% endfor %}
65
66 // ------------- Type and builder declarations.
67 {% for type in domain.types %}
68 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %}
69 {% set type_def = type_definition(domain.domain + "." + type.id)%}
70
71 // {{type.description}}
72 class {{config.class_export.macro}} {{type.id}} {% if type.exported %}: public A PI::{{type.id}} {% endif %}{
73 PROTOCOL_DISALLOW_COPY({{type.id}});
74 public:
75 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo rt* errors);
76
77 ~{{type.id}}() { }
78 {% for property in type.properties %}
79 {% if "enum" in property %}
80
81 struct {{config.class_export.macro}} {{property.name | to_title_case}}Enum {
82 {% for literal in property.enum %}
83 static const char* {{literal | dash_to_camelcase}};
84 {% endfor %}
85 }; // {{property.name | to_title_case}}Enum
86 {% endif %}
87
88 {% if property.optional %}
89 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; }
91 {% else %}
92 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas e}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}}; }
93 {% endif %}
94 void set{{property.name | to_title_case}}({{resolve_type(property).pass_type }} value) { m_{{property.name}} = {{resolve_type(property).to_rvalue % "value"}} ; }
95 {% endfor %}
96
97 std::unique_ptr<protocol::DictionaryValue> serialize() const;
98 std::unique_ptr<{{type.id}}> clone() const;
99 {% if type.exported %}
100 {{config.exported.string_out}} toJSONString() const override;
101 {% endif %}
102
103 template<int STATE>
104 class {{type.id}}Builder {
105 public:
106 enum {
107 NoFieldsSet = 0,
108 {% set count = 0 %}
109 {% for property in type.properties %}
110 {% if not(property.optional) %}
111 {% set count = count + 1 %}
112 {{property.name | to_title_case}}Set = 1 << {{count}},
113 {% endif %}
114 {% endfor %}
115 AllFieldsSet = (
116 {%- for property in type.properties %}
117 {% if not(property.optional) %}{{property.name | to_title_case}}Set | {%en dif %}
118 {% endfor %}0)};
119
120 {% for property in type.properties %}
121
122 {% if property.optional %}
123 {{type.id}}Builder<STATE>& set{{property.name | to_title_case}}({{resolv e_type(property).pass_type}} value)
124 {
125 m_result->set{{property.name | to_title_case}}({{resolve_type(proper ty).to_rvalue % "value"}});
126 return *this;
127 }
128 {% else %}
129 {{type.id}}Builder<STATE | {{property.name | to_title_case}}Set>& set{{p roperty.name | to_title_case}}({{resolve_type(property).pass_type}} value)
130 {
131 static_assert(!(STATE & {{property.name | to_title_case}}Set), "prop erty {{property.name}} should not be set yet");
132 m_result->set{{property.name | to_title_case}}({{resolve_type(proper ty).to_rvalue % "value"}});
133 return castState<{{property.name | to_title_case}}Set>();
134 }
135 {% endif %}
136 {% endfor %}
137
138 std::unique_ptr<{{type.id}}> build()
139 {
140 static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet") ;
141 return std::move(m_result);
142 }
143
144 private:
145 friend class {{type.id}};
146 {{type.id}}Builder() : m_result(new {{type.id}}()) { }
147
148 template<int STEP> {{type.id}}Builder<STATE | STEP>& castState()
149 {
150 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this);
151 }
152
153 {{type_def.type}} m_result;
154 };
155
156 static {{type.id}}Builder<0> create()
157 {
158 return {{type.id}}Builder<0>();
159 }
160
161 private:
162 {{type.id}}()
163 {
164 {% for property in type.properties %}
165 {% if not(property.optional) and "default_value" in resolve_type(property) %}
166 m_{{property.name}} = {{resolve_type(property).default_value}};
167 {%endif %}
168 {% endfor %}
169 }
170
171 {% for property in type.properties %}
172 {% if property.optional %}
173 Maybe<{{resolve_type(property).raw_type}}> m_{{property.name}};
174 {% else %}
175 {{resolve_type(property).type}} m_{{property.name}};
176 {% endif %}
177 {% endfor %}
178 };
179
180 {% endfor %}
181
182 // ------------- Backend interface.
183
184 class {{config.class_export.macro}} Backend {
185 public:
186 {% for command in domain.commands %}
187 {% if "redirect" in command %}{% continue %}{% endif %}
188 {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %} {% continue %}{% endif %}
189 {% if "async" in command %}
190 class {{config.class_export.macro}} {{command.name | to_title_case}}Callback : public BackendCallback {
191 public:
192 virtual void sendSuccess(
193 {%- for parameter in command.returns -%}
194 {%- if "optional" in parameter -%}
195 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name} }
196 {%- else -%}
197 {{resolve_type(parameter).pass_type}} {{parameter.name}}
198 {%- endif -%}
199 {%- if not loop.last -%}, {% endif -%}
200 {%- endfor -%}
201 ) = 0;
202 };
203 {% endif %}
204 virtual void {{command.name}}(
205 {%- if not("async" in command) -%}
206 ErrorString*
207 {%- endif -%}
208 {%- for parameter in command.parameters -%}
209 {%- if (not loop.first) or not("async" in command) -%}, {% endif -%}
210 {%- if "optional" in parameter -%}
211 const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
212 {%- else -%}
213 {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
214 {%- endif -%}
215 {%- endfor -%}
216 {%- if "async" in command -%}
217 {%- if command.parameters -%}, {% endif -%}
218 std::unique_ptr<{{command.name | to_title_case}}Callback> callback
219 {%- else -%}
220 {%- for parameter in command.returns -%}
221 {%- if "optional" in parameter -%}
222 , Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
223 {%- else -%}
224 , {{resolve_type(parameter).type}}* out_{{parameter.name}}
225 {%- endif -%}
226 {%- endfor -%}
227 {%- endif -%}
228 ) = 0;
229 {% endfor %}
230
231 {% if not has_disable(domain.commands) %}
232 virtual void disable(ErrorString*) { }
233 {% endif %}
234
235 protected:
236 virtual ~Backend() { }
237 };
238
239 // ------------- Frontend interface.
240
241 class {{config.class_export.macro}} Frontend {
242 public:
243 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann el) { }
244 {% for event in domain.events %}
245 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con tinue %}{% endif %}
246 void {{event.name}}(
247 {%- for parameter in event.parameters -%}
248 {%- if "optional" in parameter -%}
249 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
250 {%- else -%}
251 {{resolve_type(parameter).pass_type}} {{parameter.name}}
252 {%- endif -%}{%- if not loop.last -%}, {% endif -%}
253 {%- endfor -%}
254 );
255 {% endfor %}
256
257 void flush();
258 private:
259 FrontendChannel* m_frontendChannel;
260 };
261
262 // ------------- Dispatcher.
263
264 class {{config.class_export.macro}} Dispatcher {
265 public:
266 static void wire(UberDispatcher*, Backend*);
267
268 private:
269 Dispatcher() { }
270 };
271
272 // ------------- Metainfo.
273
274 class {{config.class_export.macro}} Metainfo {
275 public:
276 using BackendClass = Backend;
277 using FrontendClass = Frontend;
278 using DispatcherClass = Dispatcher;
279 static const char domainName[];
280 static const char commandPrefix[];
281 static const char version[];
282 };
283
284 } // namespace {{domain.domain}}
285 {% for namespace in config.protocol.namespace %}
286 } // namespace {{namespace}}
287 {% endfor %}
288
289 #endif // !defined({{"_".join(config.protocol.namespace)}}_{{domain.domain}}_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698