| 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 namespace blink { | 9 #include "{{config.protocol.package}}/Protocol.h" |
| 10 namespace protocol { | 10 |
| 11 {% for namespace in config.protocol.namespace %} |
| 12 namespace {{namespace}} { |
| 13 {% endfor %} |
| 11 namespace {{domain.domain}} { | 14 namespace {{domain.domain}} { |
| 12 | 15 |
| 13 // ------------- Enum values from types. | 16 // ------------- Enum values from types. |
| 14 | 17 |
| 15 const char Metainfo::domainName[] = "{{domain.domain}}"; | 18 const char Metainfo::domainName[] = "{{domain.domain}}"; |
| 16 const char Metainfo::commandPrefix[] = "{{domain.domain}}."; | 19 const char Metainfo::commandPrefix[] = "{{domain.domain}}."; |
| 17 const char Metainfo::version[] = "{{domain.version}}"; | 20 const char Metainfo::version[] = "{{domain.version}}"; |
| 18 {% for type in domain.types %} | 21 {% for type in domain.types %} |
| 19 {% if "enum" in type %} | 22 {% if "enum" in type %} |
| 20 | 23 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return result; | 89 return result; |
| 87 } | 90 } |
| 88 | 91 |
| 89 std::unique_ptr<{{type.id}}> {{type.id}}::clone() const | 92 std::unique_ptr<{{type.id}}> {{type.id}}::clone() const |
| 90 { | 93 { |
| 91 ErrorSupport errors; | 94 ErrorSupport errors; |
| 92 return parse(serialize().get(), &errors); | 95 return parse(serialize().get(), &errors); |
| 93 } | 96 } |
| 94 {% if type.exported %} | 97 {% if type.exported %} |
| 95 | 98 |
| 96 String16 {{type.id}}::toJSONString() const | 99 {{config.exported.string_out}} {{type.id}}::toJSONString() const |
| 97 { | 100 { |
| 98 return serialize()->toJSONString(); | 101 String json = serialize()->toJSONString(); |
| 102 return {{config.exported.to_string_out % "json"}}; |
| 99 } | 103 } |
| 100 | 104 |
| 101 // static | 105 // static |
| 102 std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromJSONString(const String1
6& json) | 106 std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromJSONString(const {{confi
g.exported.string_in}}& json) |
| 103 { | 107 { |
| 104 ErrorSupport errors; | 108 ErrorSupport errors; |
| 105 std::unique_ptr<Value> value = parseJSON(json); | 109 std::unique_ptr<Value> value = parseJSON(json); |
| 106 if (!value) | 110 if (!value) |
| 107 return nullptr; | 111 return nullptr; |
| 108 return protocol::{{domain.domain}}::{{type.id}}::parse(value.get(), &errors)
; | 112 return protocol::{{domain.domain}}::{{type.id}}::parse(value.get(), &errors)
; |
| 109 } | 113 } |
| 110 {% endif %} | 114 {% endif %} |
| 111 {% endfor %} | 115 {% endfor %} |
| 112 | 116 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 {% else %} | 166 {% else %} |
| 163 paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type
(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % param
eter.name}})); | 167 paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type
(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % param
eter.name}})); |
| 164 {% endif %} | 168 {% endif %} |
| 165 {% endfor %} | 169 {% endfor %} |
| 166 jsonMessage->setObject("params", std::move(paramsObject)); | 170 jsonMessage->setObject("params", std::move(paramsObject)); |
| 167 if (m_frontendChannel) | 171 if (m_frontendChannel) |
| 168 m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString())
; | 172 m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString())
; |
| 169 } | 173 } |
| 170 {% endfor %} | 174 {% endfor %} |
| 171 | 175 |
| 176 void Frontend::flush() |
| 177 { |
| 178 m_frontendChannel->flushProtocolNotifications(); |
| 179 } |
| 180 |
| 172 // --------------------- Dispatcher. | 181 // --------------------- Dispatcher. |
| 173 | 182 |
| 174 class DispatcherImpl : public protocol::DispatcherBase { | 183 class DispatcherImpl : public protocol::DispatcherBase { |
| 175 public: | 184 public: |
| 176 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) | 185 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) |
| 177 : DispatcherBase(frontendChannel) | 186 : DispatcherBase(frontendChannel) |
| 178 , m_backend(backend) { | 187 , m_backend(backend) { |
| 179 {% for command in domain.commands %} | 188 {% for command in domain.commands %} |
| 180 {% if "redirect" in command %}{% continue %}{% endif %} | 189 {% if "redirect" in command %}{% continue %}{% endif %} |
| 181 {% 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 %} |
| 182 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{
{command.name}}; | 191 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{
{command.name}}; |
| 183 {% endfor %} | 192 {% endfor %} |
| 184 } | 193 } |
| 185 ~DispatcherImpl() override { } | 194 ~DispatcherImpl() override { } |
| 186 void dispatch(int callId, const String16& method, std::unique_ptr<protocol::
DictionaryValue> messageObject) override; | 195 void dispatch(int callId, const String& method, std::unique_ptr<protocol::Di
ctionaryValue> messageObject) override; |
| 187 | 196 |
| 188 protected: | 197 protected: |
| 189 using CallHandler = void (DispatcherImpl::*)(int callId, std::unique_ptr<Dic
tionaryValue> messageObject, ErrorSupport* errors); | 198 using CallHandler = void (DispatcherImpl::*)(int callId, std::unique_ptr<Dic
tionaryValue> messageObject, ErrorSupport* errors); |
| 190 using DispatchMap = protocol::HashMap<String16, CallHandler>; | 199 using DispatchMap = protocol::HashMap<String, CallHandler>; |
| 191 DispatchMap m_dispatchMap; | 200 DispatchMap m_dispatchMap; |
| 192 | 201 |
| 193 {% for command in domain.commands %} | 202 {% for command in domain.commands %} |
| 194 {% if "redirect" in command %}{% continue %}{% endif %} | 203 {% if "redirect" in command %}{% continue %}{% endif %} |
| 195 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 204 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} |
| 196 void {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMe
ssageObject, ErrorSupport*); | 205 void {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMe
ssageObject, ErrorSupport*); |
| 197 {% endfor %} | 206 {% endfor %} |
| 198 | 207 |
| 199 Backend* m_backend; | 208 Backend* m_backend; |
| 200 }; | 209 }; |
| 201 | 210 |
| 202 void DispatcherImpl::dispatch(int callId, const String16& method, std::unique_pt
r<protocol::DictionaryValue> messageObject) | 211 void DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<
protocol::DictionaryValue> messageObject) |
| 203 { | 212 { |
| 204 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); | 213 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met
hod); |
| 205 if (it == m_dispatchMap.end()) { | 214 if (it == m_dispatchMap.end()) { |
| 206 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou
nd", nullptr); | 215 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou
nd", nullptr); |
| 207 return; | 216 return; |
| 208 } | 217 } |
| 209 | 218 |
| 210 protocol::ErrorSupport errors; | 219 protocol::ErrorSupport errors; |
| 211 (this->*(it->second))(callId, std::move(messageObject), &errors); | 220 (this->*(it->second))(callId, std::move(messageObject), &errors); |
| 212 } | 221 } |
| 213 | 222 |
| 214 {% for command in domain.commands %} | 223 {% for command in domain.commands %} |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 347 } |
| 339 {% endfor %} | 348 {% endfor %} |
| 340 | 349 |
| 341 // static | 350 // static |
| 342 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) | 351 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) |
| 343 { | 352 { |
| 344 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); | 353 dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherIm
pl(dispatcher->channel(), backend))); |
| 345 } | 354 } |
| 346 | 355 |
| 347 } // {{domain.domain}} | 356 } // {{domain.domain}} |
| 348 } // namespace protocol | 357 {% for namespace in config.protocol.namespace %} |
| 349 } // namespace blink | 358 } // namespace {{namespace}} |
| 359 {% endfor %} |
| OLD | NEW |