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

Side by Side Diff: third_party/inspector_protocol/templates/TypeBuilder_cpp.template

Issue 2522583002: Roll third_party/inspector_protocol to 4ad35c45aca9834b67ec2cb152c816ea1b7ceb48 (Closed)
Patch Set: removed redundant new line Created 4 years 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
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 #include {{format_include(config.protocol.package, domain.domain)}} 7 #include {{format_include(config.protocol.package, domain.domain)}}
8 8
9 #include {{format_include(config.protocol.package, "Protocol")}} 9 #include {{format_include(config.protocol.package, "Protocol")}}
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 {% endfor %} 137 {% endfor %}
138 } // namespace {{param.name | to_title_case}}Enum 138 } // namespace {{param.name | to_title_case}}Enum
139 } // namespace {{command.name | to_title_case }} 139 } // namespace {{command.name | to_title_case }}
140 } // namespace API 140 } // namespace API
141 {% endif %} 141 {% endif %}
142 {% endif %} 142 {% endif %}
143 {% endfor %} 143 {% endfor %}
144 {% endfor %} 144 {% endfor %}
145 145
146 // ------------- Frontend notifications. 146 // ------------- Frontend notifications.
147
148 namespace {
149
150 class Notification : public Serializable {
dgozman 2016/11/21 22:29:16 This should not be in template - it will be genera
kozy 2016/11/22 01:25:38 Done.
151 public:
152 static std::unique_ptr<Notification> create(const String& method, std::uniqu e_ptr<Serializable> params = nullptr)
153 {
154 return std::unique_ptr<Notification>(new Notification(method, std::move( params)));
155 }
156
157 std::unique_ptr<protocol::Value> serializeValue() const override
158 {
159 std::unique_ptr<DictionaryValue> result = DictionaryValue::create();
160 result->setString("method", m_method);
161 std::unique_ptr<DictionaryValue> params;
162 if (!m_params)
163 params = DictionaryValue::create();
dgozman 2016/11/21 22:29:16 4 spaces
kozy 2016/11/22 01:25:38 Done.
164 else
165 params = std::unique_ptr<DictionaryValue>(static_cast<DictionaryValue* >(m_params->serializeValue().release()));
166 result->setObject("params", std::move(params));
167 return result;
168 }
169
170 protected:
171 Notification(const String& method, std::unique_ptr<Serializable> params)
172 : m_method(method)
173 , m_params(std::move(params))
174 {
175 }
176
177 private:
178 String m_method;
179 std::unique_ptr<Serializable> m_params;
180 };
181
182 } // namespace
183
147 {% for event in domain.events %} 184 {% for event in domain.events %}
148 {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif %} 185 {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif %}
149 186
150 void Frontend::{{event.name | to_method_case}}( 187 void Frontend::{{event.name | to_method_case}}(
151 {%- for parameter in event.parameters %} 188 {%- for parameter in event.parameters %}
152 {% if "optional" in parameter -%} 189 {% if "optional" in parameter -%}
153 Maybe<{{resolve_type(parameter).raw_type}}> 190 Maybe<{{resolve_type(parameter).raw_type}}>
154 {%- else -%} 191 {%- else -%}
155 {{resolve_type(parameter).pass_type}} 192 {{resolve_type(parameter).pass_type}}
156 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} 193 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
157 {% endfor -%}) 194 {% endfor -%})
158 { 195 {
159 std::unique_ptr<protocol::DictionaryValue> jsonMessage = DictionaryValue::cr eate(); 196 if (!m_frontendChannel)
160 jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}"); 197 return;
161 std::unique_ptr<protocol::DictionaryValue> paramsObject = DictionaryValue::c reate(); 198 {% if event.parameters %}
162 {% for parameter in event.parameters %} 199 std::unique_ptr<{{event.name | to_title_case}}Notification> messageData = {{ event.name | to_title_case}}Notification::{{"create" | to_method_case}}()
163 {% if "optional" in parameter %} 200 {% for parameter in event.parameters %}
201 {% if not "optional" in parameter %}
202 .{{"set" | to_method_case}}{{parameter.name | to_title_case}}({{resolve_ type(parameter).to_pass_type % parameter.name}})
203 {% endif %}
204 {% endfor %}
205 .{{ "build" | to_method_case }}();
206 {% for parameter in event.parameters %}
207 {% if "optional" in parameter %}
164 if ({{parameter.name}}.isJust()) 208 if ({{parameter.name}}.isJust())
165 paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_ type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust())); 209 messageData->{{"set" | to_method_case}}{{parameter.name | to_title_case} }(std::move({{parameter.name}}).takeJust());
210 {% endif %}
211 {% endfor %}
212 m_frontendChannel->sendProtocolNotification(Notification::create("{{domain.d omain}}.{{event.name}}", std::move(messageData)));
166 {% else %} 213 {% else %}
167 paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type (parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % param eter.name}})); 214 m_frontendChannel->sendProtocolNotification(Notification::create("{{domain.d omain}}.{{event.name}}"));
168 {% endif %} 215 {% endif %}
169 {% endfor %}
170 jsonMessage->setObject("params", std::move(paramsObject));
171 if (m_frontendChannel)
172 m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()) ;
173 } 216 }
174 {% endfor %} 217 {% endfor %}
175 218
176 void Frontend::flush() 219 void Frontend::flush()
177 { 220 {
178 m_frontendChannel->flushProtocolNotifications(); 221 m_frontendChannel->flushProtocolNotifications();
179 } 222 }
180 223
224 namespace {
225
226 class RawNotification : public Serializable {
227 public:
228 explicit RawNotification(const String& notification)
229 : m_notification(notification)
230 {
231 }
232
233 std::unique_ptr<protocol::Value> serializeValue() const override {
234 return SerializedValue::create(m_notification);
235 }
236
237 private:
238 String m_notification;
239 };
240
241 } // namespace
242
181 void Frontend::sendRawNotification(const String& notification) 243 void Frontend::sendRawNotification(const String& notification)
182 { 244 {
183 m_frontendChannel->sendProtocolNotification(notification); 245 m_frontendChannel->sendProtocolNotification(std::unique_ptr<Serializable>(ne w RawNotification(notification)));
184 } 246 }
185 247
186 // --------------------- Dispatcher. 248 // --------------------- Dispatcher.
187 249
188 class DispatcherImpl : public protocol::DispatcherBase { 250 class DispatcherImpl : public protocol::DispatcherBase {
189 public: 251 public:
190 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fall ThroughForNotFound) 252 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fall ThroughForNotFound)
191 : DispatcherBase(frontendChannel) 253 : DispatcherBase(frontendChannel)
192 , m_backend(backend) 254 , m_backend(backend)
193 , m_fallThroughForNotFound(fallThroughForNotFound) { 255 , m_fallThroughForNotFound(fallThroughForNotFound) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // static 431 // static
370 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) 432 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
371 { 433 {
372 dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::D ispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fa llThroughForNotFound()))); 434 dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::D ispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fa llThroughForNotFound())));
373 } 435 }
374 436
375 } // {{domain.domain}} 437 } // {{domain.domain}}
376 {% for namespace in config.protocol.namespace %} 438 {% for namespace in config.protocol.namespace %}
377 } // namespace {{namespace}} 439 } // namespace {{namespace}}
378 {% endfor %} 440 {% endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698