| 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 #include "{{config.protocol.package}}/{{domain.domain}}.h" | 7 #include "{{config.protocol.package}}/{{domain.domain}}.h" |
| 8 | 8 |
| 9 #include "{{config.protocol.package}}/Protocol.h" | 9 #include "{{config.protocol.package}}/Protocol.h" |
| 10 | 10 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 {% endfor %} | 143 {% endfor %} |
| 144 {% endfor %} | 144 {% endfor %} |
| 145 | 145 |
| 146 // ------------- Frontend notifications. | 146 // ------------- Frontend notifications. |
| 147 {% for event in domain.events %} | 147 {% for event in domain.events %} |
| 148 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con
tinue %}{% endif %} | 148 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con
tinue %}{% endif %} |
| 149 | 149 |
| 150 void Frontend::{{event.name}}( | 150 void Frontend::{{event.name}}( |
| 151 {%- for parameter in event.parameters %} | 151 {%- for parameter in event.parameters %} |
| 152 {% if "optional" in parameter -%} | 152 {% if "optional" in parameter -%} |
| 153 {%- if new_style(domain) -%} | |
| 154 Maybe<{{resolve_type(parameter).raw_type}}> | 153 Maybe<{{resolve_type(parameter).raw_type}}> |
| 155 {%- else -%} | |
| 156 const Maybe<{{resolve_type(parameter).raw_type}}>& | |
| 157 {%- endif -%} | |
| 158 {%- else -%} | 154 {%- else -%} |
| 159 {{resolve_type(parameter).pass_type}} | 155 {{resolve_type(parameter).pass_type}} |
| 160 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} | 156 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} |
| 161 {% endfor -%}) | 157 {% endfor -%}) |
| 162 { | 158 { |
| 163 std::unique_ptr<protocol::DictionaryValue> jsonMessage = DictionaryValue::cr
eate(); | 159 std::unique_ptr<protocol::DictionaryValue> jsonMessage = DictionaryValue::cr
eate(); |
| 164 jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}"); | 160 jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}"); |
| 165 std::unique_ptr<protocol::DictionaryValue> paramsObject = DictionaryValue::c
reate(); | 161 std::unique_ptr<protocol::DictionaryValue> paramsObject = DictionaryValue::c
reate(); |
| 166 {% for parameter in event.parameters %} | 162 {% for parameter in event.parameters %} |
| 167 {% if "optional" in parameter %} | 163 {% if "optional" in parameter %} |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 {% if "async" in command %} | 226 {% if "async" in command %} |
| 231 | 227 |
| 232 class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.n
ame | to_title_case}}Callback, public DispatcherBase::Callback { | 228 class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.n
ame | to_title_case}}Callback, public DispatcherBase::Callback { |
| 233 public: | 229 public: |
| 234 {{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase:
:WeakPtr> backendImpl, int callId) | 230 {{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase:
:WeakPtr> backendImpl, int callId) |
| 235 : DispatcherBase::Callback(std::move(backendImpl), callId) { } | 231 : DispatcherBase::Callback(std::move(backendImpl), callId) { } |
| 236 | 232 |
| 237 void sendSuccess( | 233 void sendSuccess( |
| 238 {%- for parameter in command.returns -%} | 234 {%- for parameter in command.returns -%} |
| 239 {%- if "optional" in parameter -%} | 235 {%- if "optional" in parameter -%} |
| 240 {%- if new_style(domain) -%} | |
| 241 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} | 236 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} |
| 242 {%- else -%} | |
| 243 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} | |
| 244 {%- endif -%} | |
| 245 {%- else -%} | 237 {%- else -%} |
| 246 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 238 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
| 247 {%- endif -%} | 239 {%- endif -%} |
| 248 {%- if not loop.last -%}, {% endif -%} | 240 {%- if not loop.last -%}, {% endif -%} |
| 249 {%- endfor -%}) override | 241 {%- endfor -%}) override |
| 250 { | 242 { |
| 251 std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValu
e::create(); | 243 std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValu
e::create(); |
| 252 {% for parameter in command.returns %} | 244 {% for parameter in command.returns %} |
| 253 {% if "optional" in parameter %} | 245 {% if "optional" in parameter %} |
| 254 if ({{parameter.name}}.isJust()) | 246 if ({{parameter.name}}.isJust()) |
| 255 resultObject->setValue("{{parameter.name}}", ValueConversions<{{reso
lve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust())); | 247 resultObject->setValue("{{parameter.name}}", ValueConversions<{{reso
lve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust())); |
| 256 {% else %} | 248 {% else %} |
| 257 resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_
type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % p
arameter.name}})); | 249 resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_
type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % p
arameter.name}})); |
| 258 {% endif %} | 250 {% endif %} |
| 259 {% endfor %} | 251 {% endfor %} |
| 260 sendIfActive(std::move(resultObject), DispatchResponse::OK()); | 252 sendIfActive(std::move(resultObject), DispatchResponse::OK()); |
| 261 } | 253 } |
| 262 | 254 |
| 263 {% if new_style(domain) %} | |
| 264 void sendFailure(const DispatchResponse& response) override | 255 void sendFailure(const DispatchResponse& response) override |
| 265 { | 256 { |
| 266 DCHECK(response.status() == DispatchResponse::kError); | 257 DCHECK(response.status() == DispatchResponse::kError); |
| 267 sendIfActive(nullptr, response); | 258 sendIfActive(nullptr, response); |
| 268 } | 259 } |
| 269 {% else %} | |
| 270 void sendFailure(const ErrorString& error) override | |
| 271 { | |
| 272 DCHECK(error.length()); | |
| 273 sendIfActive(nullptr, DispatchResponse::Error(error)); | |
| 274 } | |
| 275 {% endif %} | |
| 276 }; | 260 }; |
| 277 {% endif %} | 261 {% endif %} |
| 278 | 262 |
| 279 DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
e_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors) | 263 DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
e_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors) |
| 280 { | 264 { |
| 281 {% if "parameters" in command %} | 265 {% if "parameters" in command %} |
| 282 // Prepare input parameters. | 266 // Prepare input parameters. |
| 283 protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObje
ct->get("params")); | 267 protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObje
ct->get("params")); |
| 284 errors->push(); | 268 errors->push(); |
| 285 {% for property in command.parameters %} | 269 {% for property in command.parameters %} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 307 {% if "optional" in property %} | 291 {% if "optional" in property %} |
| 308 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; | 292 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; |
| 309 {% else %} | 293 {% else %} |
| 310 {{resolve_type(property).type}} out_{{property.name}}; | 294 {{resolve_type(property).type}} out_{{property.name}}; |
| 311 {% endif %} | 295 {% endif %} |
| 312 {% endfor %} | 296 {% endfor %} |
| 313 {% endif %} | 297 {% endif %} |
| 314 | 298 |
| 315 {% if not("async" in command) %} | 299 {% if not("async" in command) %} |
| 316 std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr(); | 300 std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr(); |
| 317 {% if not new_style(domain) %} | |
| 318 ErrorString error; | |
| 319 m_backend->{{command.name}}(&error | |
| 320 {%- else %} | |
| 321 DispatchResponse response = m_backend->{{command.name}}( | 301 DispatchResponse response = m_backend->{{command.name}}( |
| 322 {%- endif -%} | |
| 323 {%- for property in command.parameters -%} | 302 {%- for property in command.parameters -%} |
| 324 {%- if not loop.first or not new_style(domain) -%}, {% endif -%} | 303 {%- if not loop.first -%}, {% endif -%} |
| 325 {%- if "optional" in property -%} | 304 {%- if "optional" in property -%} |
| 326 {%- if new_style(domain) -%} | |
| 327 std::move(in_{{property.name}}) | 305 std::move(in_{{property.name}}) |
| 328 {%- else -%} | |
| 329 in_{{property.name}} | |
| 330 {%- endif -%} | |
| 331 {%- else -%} | 306 {%- else -%} |
| 332 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} | 307 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} |
| 333 {%- endif -%} | 308 {%- endif -%} |
| 334 {%- endfor %} | 309 {%- endfor %} |
| 335 {%- if "returns" in command %} | 310 {%- if "returns" in command %} |
| 336 {%- for property in command.returns -%} | 311 {%- for property in command.returns -%} |
| 337 {%- if not loop.first or command.parameters or not new_style(domain) -
%}, {% endif -%} | 312 {%- if not loop.first or command.parameters -%}, {% endif -%} |
| 338 &out_{{property.name}} | 313 &out_{{property.name}} |
| 339 {%- endfor %} | 314 {%- endfor %} |
| 340 {% endif %}); | 315 {% endif %}); |
| 341 {% if not new_style(domain) %} | |
| 342 DispatchResponse response = error.length() ? DispatchResponse::Error(error)
: DispatchResponse::OK(); | |
| 343 {% endif %} | |
| 344 {% if "returns" in command %} | 316 {% if "returns" in command %} |
| 345 if (response.status() == DispatchResponse::kFallThrough) | 317 if (response.status() == DispatchResponse::kFallThrough) |
| 346 return response.status(); | 318 return response.status(); |
| 347 std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create(
); | 319 std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create(
); |
| 348 if (response.status() == DispatchResponse::kSuccess) { | 320 if (response.status() == DispatchResponse::kSuccess) { |
| 349 {% for parameter in command.returns %} | 321 {% for parameter in command.returns %} |
| 350 {% if "optional" in parameter %} | 322 {% if "optional" in parameter %} |
| 351 if (out_{{parameter.name}}.isJust()) | 323 if (out_{{parameter.name}}.isJust()) |
| 352 result->setValue("{{parameter.name}}", ValueConversions<{{resolve_ty
pe(parameter).raw_type}}>::serialize(out_{{parameter.name}}.fromJust())); | 324 result->setValue("{{parameter.name}}", ValueConversions<{{resolve_ty
pe(parameter).raw_type}}>::serialize(out_{{parameter.name}}.fromJust())); |
| 353 {% else %} | 325 {% else %} |
| 354 result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(p
arameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % ("out_"
+ parameter.name)}})); | 326 result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(p
arameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % ("out_"
+ parameter.name)}})); |
| 355 {% endif %} | 327 {% endif %} |
| 356 {% endfor %} | 328 {% endfor %} |
| 357 } | 329 } |
| 358 if (weak->get()) | 330 if (weak->get()) |
| 359 weak->get()->sendResponse(callId, response, std::move(result)); | 331 weak->get()->sendResponse(callId, response, std::move(result)); |
| 360 {% else %} | 332 {% else %} |
| 361 if (weak->get()) | 333 if (weak->get()) |
| 362 weak->get()->sendResponse(callId, response); | 334 weak->get()->sendResponse(callId, response); |
| 363 {% endif %} | 335 {% endif %} |
| 364 return response.status(); | 336 return response.status(); |
| 365 {% else %} | 337 {% else %} |
| 366 std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {
{command.name | to_title_case}}CallbackImpl(weakPtr(), callId)); | 338 std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {
{command.name | to_title_case}}CallbackImpl(weakPtr(), callId)); |
| 367 m_backend->{{command.name}}( | 339 m_backend->{{command.name}}( |
| 368 {%- for property in command.parameters -%} | 340 {%- for property in command.parameters -%} |
| 369 {%- if not loop.first -%}, {% endif -%} | 341 {%- if not loop.first -%}, {% endif -%} |
| 370 {%- if "optional" in property -%} | 342 {%- if "optional" in property -%} |
| 371 {%- if new_style(domain) -%} | |
| 372 std::move(in_{{property.name}}) | 343 std::move(in_{{property.name}}) |
| 373 {%- else -%} | |
| 374 in_{{property.name}} | |
| 375 {%- endif -%} | |
| 376 {%- else -%} | 344 {%- else -%} |
| 377 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} | 345 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} |
| 378 {%- endif -%} | 346 {%- endif -%} |
| 379 {%- endfor -%} | 347 {%- endfor -%} |
| 380 {%- if command.parameters -%}, {% endif -%} | 348 {%- if command.parameters -%}, {% endif -%} |
| 381 std::move(callback)); | 349 std::move(callback)); |
| 382 return DispatchResponse::kAsync; | 350 return DispatchResponse::kAsync; |
| 383 {% endif %} | 351 {% endif %} |
| 384 } | 352 } |
| 385 {% endfor %} | 353 {% endfor %} |
| 386 | 354 |
| 387 // static | 355 // static |
| 388 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) | 356 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) |
| 389 { | 357 { |
| 390 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); | 358 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); |
| 391 } | 359 } |
| 392 | 360 |
| 393 } // {{domain.domain}} | 361 } // {{domain.domain}} |
| 394 {% for namespace in config.protocol.namespace %} | 362 {% for namespace in config.protocol.namespace %} |
| 395 } // namespace {{namespace}} | 363 } // namespace {{namespace}} |
| 396 {% endfor %} | 364 {% endfor %} |
| OLD | NEW |