Line data Source code
1 : // This file is generated
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.2";
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 0 : 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()->serialize();
60 0 : return StringBufferImpl::adopt(json);
61 : }
62 :
63 : // static
64 0 : std::unique_ptr<API::Domain> API::Domain::fromJSONString(const StringView& json)
65 : {
66 0 : ErrorSupport errors;
67 0 : std::unique_ptr<Value> value = StringUtil::parseJSON(json);
68 0 : if (!value)
69 : return nullptr;
70 0 : return protocol::Schema::Domain::fromValue(value.get(), &errors);
71 : }
72 :
73 : // ------------- Enum values from params.
74 :
75 :
76 : // ------------- Frontend notifications.
77 :
78 0 : void Frontend::flush()
79 : {
80 0 : m_frontendChannel->flushProtocolNotifications();
81 0 : }
82 :
83 0 : void Frontend::sendRawNotification(const String& notification)
84 : {
85 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
86 0 : }
87 :
88 : // --------------------- Dispatcher.
89 :
90 : class DispatcherImpl : public protocol::DispatcherBase {
91 : public:
92 3406 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
93 : : DispatcherBase(frontendChannel)
94 : , m_backend(backend)
95 10218 : , m_fallThroughForNotFound(fallThroughForNotFound) {
96 10218 : m_dispatchMap["Schema.getDomains"] = &DispatcherImpl::getDomains;
97 3406 : }
98 10218 : ~DispatcherImpl() override { }
99 : DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
100 : HashMap<String, String>& redirects() { return m_redirects; }
101 :
102 : protected:
103 : using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
104 : using DispatchMap = protocol::HashMap<String, CallHandler>;
105 : DispatchMap m_dispatchMap;
106 : HashMap<String, String> m_redirects;
107 :
108 : DispatchResponse::Status getDomains(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
109 :
110 : Backend* m_backend;
111 : bool m_fallThroughForNotFound;
112 : };
113 :
114 0 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
115 : {
116 : protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
117 0 : if (it == m_dispatchMap.end()) {
118 0 : if (m_fallThroughForNotFound)
119 : return DispatchResponse::kFallThrough;
120 0 : reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
121 0 : return DispatchResponse::kError;
122 : }
123 :
124 0 : protocol::ErrorSupport errors;
125 0 : return (this->*(it->second))(callId, std::move(messageObject), &errors);
126 : }
127 :
128 :
129 0 : DispatchResponse::Status DispatcherImpl::getDomains(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
130 : {
131 : // Declare output parameters.
132 0 : std::unique_ptr<protocol::Array<protocol::Schema::Domain>> out_domains;
133 :
134 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
135 0 : DispatchResponse response = m_backend->getDomains(&out_domains);
136 0 : if (response.status() == DispatchResponse::kFallThrough)
137 : return response.status();
138 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
139 0 : if (response.status() == DispatchResponse::kSuccess) {
140 0 : result->setValue("domains", ValueConversions<protocol::Array<protocol::Schema::Domain>>::toValue(out_domains.get()));
141 : }
142 0 : if (weak->get())
143 0 : weak->get()->sendResponse(callId, response, std::move(result));
144 0 : return response.status();
145 : }
146 :
147 : // static
148 3406 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
149 : {
150 3406 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
151 3406 : uber->setupRedirects(dispatcher->redirects());
152 10218 : uber->registerBackend("Schema", std::move(dispatcher));
153 3406 : }
154 :
155 : } // Schema
156 : } // namespace v8_inspector
157 : } // namespace protocol
|