Line data Source code
1 : // This file is generated by TypeBuilder_cpp.template.
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 : #include "src/inspector/protocol/Schema.h"
8 :
9 : #include "src/inspector/protocol/Protocol.h"
10 :
11 : namespace v8_inspector {
12 : namespace protocol {
13 : namespace Schema {
14 :
15 : // ------------- Enum values from types.
16 :
17 : const char Metainfo::domainName[] = "Schema";
18 : const char Metainfo::commandPrefix[] = "Schema.";
19 : const char Metainfo::version[] = "1.3";
20 :
21 0 : std::unique_ptr<Domain> Domain::fromValue(protocol::Value* value, ErrorSupport* errors)
22 : {
23 0 : if (!value || value->type() != protocol::Value::TypeObject) {
24 0 : errors->addError("object expected");
25 : return nullptr;
26 : }
27 :
28 0 : std::unique_ptr<Domain> result(new Domain());
29 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
30 0 : errors->push();
31 0 : protocol::Value* nameValue = object->get("name");
32 0 : errors->setName("name");
33 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
34 0 : protocol::Value* versionValue = object->get("version");
35 0 : errors->setName("version");
36 0 : result->m_version = ValueConversions<String>::fromValue(versionValue, errors);
37 0 : errors->pop();
38 0 : if (errors->hasErrors())
39 : return nullptr;
40 : return result;
41 : }
42 :
43 0 : std::unique_ptr<protocol::DictionaryValue> Domain::toValue() const
44 : {
45 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
46 0 : result->setValue("name", ValueConversions<String>::toValue(m_name));
47 0 : result->setValue("version", ValueConversions<String>::toValue(m_version));
48 0 : return result;
49 : }
50 :
51 0 : std::unique_ptr<Domain> Domain::clone() const
52 : {
53 0 : ErrorSupport errors;
54 0 : return fromValue(toValue().get(), &errors);
55 : }
56 :
57 0 : std::unique_ptr<StringBuffer> Domain::toJSONString() const
58 : {
59 0 : String json = toValue()->serializeToJSON();
60 0 : return StringBufferImpl::adopt(json);
61 : }
62 :
63 0 : void Domain::writeBinary(std::vector<uint8_t>* out) const
64 : {
65 0 : toValue()->writeBinary(out);
66 0 : }
67 :
68 : // static
69 0 : std::unique_ptr<API::Domain> API::Domain::fromJSONString(const StringView& json)
70 : {
71 0 : ErrorSupport errors;
72 0 : std::unique_ptr<Value> value = StringUtil::parseJSON(json);
73 0 : if (!value)
74 : return nullptr;
75 0 : return protocol::Schema::Domain::fromValue(value.get(), &errors);
76 : }
77 :
78 : // static
79 0 : std::unique_ptr<API::Domain> API::Domain::fromBinary(const uint8_t* data, size_t length)
80 : {
81 0 : ErrorSupport errors;
82 0 : std::unique_ptr<Value> value = Value::parseBinary(data, length);
83 0 : if (!value)
84 : return nullptr;
85 0 : return protocol::Schema::Domain::fromValue(value.get(), &errors);
86 : }
87 :
88 :
89 : // ------------- Enum values from params.
90 :
91 :
92 : // ------------- Frontend notifications.
93 :
94 0 : void Frontend::flush()
95 : {
96 0 : m_frontendChannel->flushProtocolNotifications();
97 0 : }
98 :
99 0 : void Frontend::sendRawNotification(String notification)
100 : {
101 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
102 0 : }
103 :
104 0 : void Frontend::sendRawNotification(std::vector<uint8_t> notification)
105 : {
106 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
107 0 : }
108 :
109 : // --------------------- Dispatcher.
110 :
111 : class DispatcherImpl : public protocol::DispatcherBase {
112 : public:
113 3879 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
114 : : DispatcherBase(frontendChannel)
115 7758 : , m_backend(backend) {
116 11637 : m_dispatchMap["Schema.getDomains"] = &DispatcherImpl::getDomains;
117 3879 : }
118 11637 : ~DispatcherImpl() override { }
119 : bool canDispatch(const String& method) override;
120 : void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
121 3879 : std::unordered_map<String, String>& redirects() { return m_redirects; }
122 :
123 : protected:
124 : using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
125 : using DispatchMap = std::unordered_map<String, CallHandler>;
126 : DispatchMap m_dispatchMap;
127 : std::unordered_map<String, String> m_redirects;
128 :
129 : void getDomains(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
130 :
131 : Backend* m_backend;
132 : };
133 :
134 0 : bool DispatcherImpl::canDispatch(const String& method) {
135 0 : return m_dispatchMap.find(method) != m_dispatchMap.end();
136 : }
137 :
138 0 : void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
139 : {
140 : std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
141 : DCHECK(it != m_dispatchMap.end());
142 0 : protocol::ErrorSupport errors;
143 0 : (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
144 0 : }
145 :
146 :
147 0 : void DispatcherImpl::getDomains(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
148 : {
149 : // Declare output parameters.
150 0 : std::unique_ptr<protocol::Array<protocol::Schema::Domain>> out_domains;
151 :
152 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
153 0 : DispatchResponse response = m_backend->getDomains(&out_domains);
154 0 : if (response.status() == DispatchResponse::kFallThrough) {
155 0 : channel()->fallThrough(callId, method, message);
156 0 : return;
157 : }
158 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
159 0 : if (response.status() == DispatchResponse::kSuccess) {
160 0 : result->setValue("domains", ValueConversions<protocol::Array<protocol::Schema::Domain>>::toValue(out_domains.get()));
161 : }
162 0 : if (weak->get())
163 0 : weak->get()->sendResponse(callId, response, std::move(result));
164 : return;
165 : }
166 :
167 : // static
168 3879 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
169 : {
170 3879 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
171 3879 : uber->setupRedirects(dispatcher->redirects());
172 11637 : uber->registerBackend("Schema", std::move(dispatcher));
173 3879 : }
174 :
175 : } // Schema
176 : } // namespace v8_inspector
177 : } // namespace protocol
|