| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 {% 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 not generate_event(domain.domain, event.name) %}{% continue %}{% 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 Maybe<{{resolve_type(parameter).raw_type}}> | 153 Maybe<{{resolve_type(parameter).raw_type}}> |
| 154 {%- else -%} | 154 {%- else -%} |
| 155 {{resolve_type(parameter).pass_type}} | 155 {{resolve_type(parameter).pass_type}} |
| 156 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} | 156 {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} |
| 157 {% endfor -%}) | 157 {% endfor -%}) |
| 158 { | 158 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 180 | 180 |
| 181 // --------------------- Dispatcher. | 181 // --------------------- Dispatcher. |
| 182 | 182 |
| 183 class DispatcherImpl : public protocol::DispatcherBase { | 183 class DispatcherImpl : public protocol::DispatcherBase { |
| 184 public: | 184 public: |
| 185 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) | 185 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) |
| 186 : DispatcherBase(frontendChannel) | 186 : DispatcherBase(frontendChannel) |
| 187 , m_backend(backend) { | 187 , m_backend(backend) { |
| 188 {% for command in domain.commands %} | 188 {% for command in domain.commands %} |
| 189 {% if "redirect" in command %}{% continue %}{% endif %} | 189 {% if "redirect" in command %}{% continue %}{% endif %} |
| 190 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 190 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e
ndif %} |
| 191 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{
{command.name}}; | 191 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{
{command.name}}; |
| 192 {% endfor %} | 192 {% endfor %} |
| 193 } | 193 } |
| 194 ~DispatcherImpl() override { } | 194 ~DispatcherImpl() override { } |
| 195 DispatchResponse::Status dispatch(int callId, const String& method, std::uni
que_ptr<protocol::DictionaryValue> messageObject) override; | 195 DispatchResponse::Status dispatch(int callId, const String& method, std::uni
que_ptr<protocol::DictionaryValue> messageObject) override; |
| 196 | 196 |
| 197 protected: | 197 protected: |
| 198 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId,
std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors); | 198 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId,
std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors); |
| 199 using DispatchMap = protocol::HashMap<String, CallHandler>; | 199 using DispatchMap = protocol::HashMap<String, CallHandler>; |
| 200 DispatchMap m_dispatchMap; | 200 DispatchMap m_dispatchMap; |
| 201 | 201 |
| 202 {% for command in domain.commands %} | 202 {% for command in domain.commands %} |
| 203 {% if "redirect" in command %}{% continue %}{% endif %} | 203 {% if "redirect" in command %}{% continue %}{% endif %} |
| 204 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 204 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e
ndif %} |
| 205 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio
naryValue> requestMessageObject, ErrorSupport*); | 205 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio
naryValue> requestMessageObject, ErrorSupport*); |
| 206 {% endfor %} | 206 {% endfor %} |
| 207 | 207 |
| 208 Backend* m_backend; | 208 Backend* m_backend; |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth
od, std::unique_ptr<protocol::DictionaryValue> messageObject) | 211 DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth
od, std::unique_ptr<protocol::DictionaryValue> messageObject) |
| 212 { | 212 { |
| 213 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met
hod); | 213 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met
hod); |
| 214 if (it == m_dispatchMap.end()) { | 214 if (it == m_dispatchMap.end()) { |
| 215 reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + met
hod + "' wasn't found", nullptr); | 215 reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + met
hod + "' wasn't found", nullptr); |
| 216 return DispatchResponse::kError; | 216 return DispatchResponse::kError; |
| 217 } | 217 } |
| 218 | 218 |
| 219 protocol::ErrorSupport errors; | 219 protocol::ErrorSupport errors; |
| 220 return (this->*(it->second))(callId, std::move(messageObject), &errors); | 220 return (this->*(it->second))(callId, std::move(messageObject), &errors); |
| 221 } | 221 } |
| 222 | 222 |
| 223 {% for command in domain.commands %} | 223 {% for command in domain.commands %} |
| 224 {% if "redirect" in command %}{% continue %}{% endif %} | 224 {% if "redirect" in command %}{% continue %}{% endif %} |
| 225 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 225 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e
ndif %} |
| 226 {% if "async" in command %} | 226 {% if is_async_command(domain.domain, command.name) %} |
| 227 | 227 |
| 228 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 { |
| 229 public: | 229 public: |
| 230 {{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) |
| 231 : DispatcherBase::Callback(std::move(backendImpl), callId) { } | 231 : DispatcherBase::Callback(std::move(backendImpl), callId) { } |
| 232 | 232 |
| 233 void sendSuccess( | 233 void sendSuccess( |
| 234 {%- for parameter in command.returns -%} | 234 {%- for parameter in command.returns -%} |
| 235 {%- if "optional" in parameter -%} | 235 {%- if "optional" in parameter -%} |
| 236 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} | 236 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 errors->setName("{{property.name}}"); | 278 errors->setName("{{property.name}}"); |
| 279 {{resolve_type(property).type}} in_{{property.name}} = ValueConversions<{{re
solve_type(property).raw_type}}>::parse({{property.name}}Value, errors); | 279 {{resolve_type(property).type}} in_{{property.name}} = ValueConversions<{{re
solve_type(property).raw_type}}>::parse({{property.name}}Value, errors); |
| 280 {% endif %} | 280 {% endif %} |
| 281 {% endfor %} | 281 {% endfor %} |
| 282 errors->pop(); | 282 errors->pop(); |
| 283 if (errors->hasErrors()) { | 283 if (errors->hasErrors()) { |
| 284 reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidPa
ramsString, errors); | 284 reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidPa
ramsString, errors); |
| 285 return DispatchResponse::kError; | 285 return DispatchResponse::kError; |
| 286 } | 286 } |
| 287 {% endif %} | 287 {% endif %} |
| 288 {% if "returns" in command and not ("async" in command) %} | 288 {% if "returns" in command and not is_async_command(domain.domain, command.n
ame) %} |
| 289 // Declare output parameters. | 289 // Declare output parameters. |
| 290 {% for property in command.returns %} | 290 {% for property in command.returns %} |
| 291 {% if "optional" in property %} | 291 {% if "optional" in property %} |
| 292 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; | 292 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; |
| 293 {% else %} | 293 {% else %} |
| 294 {{resolve_type(property).type}} out_{{property.name}}; | 294 {{resolve_type(property).type}} out_{{property.name}}; |
| 295 {% endif %} | 295 {% endif %} |
| 296 {% endfor %} | 296 {% endfor %} |
| 297 {% endif %} | 297 {% endif %} |
| 298 | 298 |
| 299 {% if not("async" in command) %} | 299 {% if not is_async_command(domain.domain, command.name) %} |
| 300 std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr(); | 300 std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr(); |
| 301 DispatchResponse response = m_backend->{{command.name}}( | 301 DispatchResponse response = m_backend->{{command.name}}( |
| 302 {%- for property in command.parameters -%} | 302 {%- for property in command.parameters -%} |
| 303 {%- if not loop.first -%}, {% endif -%} | 303 {%- if not loop.first -%}, {% endif -%} |
| 304 {%- if "optional" in property -%} | 304 {%- if "optional" in property -%} |
| 305 std::move(in_{{property.name}}) | 305 std::move(in_{{property.name}}) |
| 306 {%- else -%} | 306 {%- else -%} |
| 307 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} | 307 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} |
| 308 {%- endif -%} | 308 {%- endif -%} |
| 309 {%- endfor %} | 309 {%- endfor %} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // static | 355 // static |
| 356 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) | 356 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) |
| 357 { | 357 { |
| 358 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); | 358 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // {{domain.domain}} | 361 } // {{domain.domain}} |
| 362 {% for namespace in config.protocol.namespace %} | 362 {% for namespace in config.protocol.namespace %} |
| 363 } // namespace {{namespace}} | 363 } // namespace {{namespace}} |
| 364 {% endfor %} | 364 {% endfor %} |
| OLD | NEW |