GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/Release/obj/gen/src/node/inspector/protocol/NodeTracing.cpp Lines: 13 121 10.7 %
Date: 2019-02-01 22:03:38 Branches: 1 54 1.9 %

Line Branch Exec Source
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/node/inspector/protocol/NodeTracing.h"
8
9
#include "src/node/inspector/protocol/Protocol.h"
10
11
namespace node {
12
namespace inspector {
13
namespace protocol {
14
namespace NodeTracing {
15
16
// ------------- Enum values from types.
17
18
const char Metainfo::domainName[] = "NodeTracing";
19
const char Metainfo::commandPrefix[] = "NodeTracing.";
20
const char Metainfo::version[] = "1.0";
21
22
const char* TraceConfig::RecordModeEnum::RecordUntilFull = "recordUntilFull";
23
const char* TraceConfig::RecordModeEnum::RecordContinuously = "recordContinuously";
24
const char* TraceConfig::RecordModeEnum::RecordAsMuchAsPossible = "recordAsMuchAsPossible";
25
26
std::unique_ptr<TraceConfig> TraceConfig::fromValue(protocol::Value* value, ErrorSupport* errors)
27
{
28
    if (!value || value->type() != protocol::Value::TypeObject) {
29
        errors->addError("object expected");
30
        return nullptr;
31
    }
32
33
    std::unique_ptr<TraceConfig> result(new TraceConfig());
34
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
35
    errors->push();
36
    protocol::Value* recordModeValue = object->get("recordMode");
37
    if (recordModeValue) {
38
        errors->setName("recordMode");
39
        result->m_recordMode = ValueConversions<String>::fromValue(recordModeValue, errors);
40
    }
41
    protocol::Value* includedCategoriesValue = object->get("includedCategories");
42
    errors->setName("includedCategories");
43
    result->m_includedCategories = ValueConversions<protocol::Array<String>>::fromValue(includedCategoriesValue, errors);
44
    errors->pop();
45
    if (errors->hasErrors())
46
        return nullptr;
47
    return result;
48
}
49
50
std::unique_ptr<protocol::DictionaryValue> TraceConfig::toValue() const
51
{
52
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
53
    if (m_recordMode.isJust())
54
        result->setValue("recordMode", ValueConversions<String>::toValue(m_recordMode.fromJust()));
55
    result->setValue("includedCategories", ValueConversions<protocol::Array<String>>::toValue(m_includedCategories.get()));
56
    return result;
57
}
58
59
std::unique_ptr<TraceConfig> TraceConfig::clone() const
60
{
61
    ErrorSupport errors;
62
    return fromValue(toValue().get(), &errors);
63
}
64
65
std::unique_ptr<DataCollectedNotification> DataCollectedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
66
{
67
    if (!value || value->type() != protocol::Value::TypeObject) {
68
        errors->addError("object expected");
69
        return nullptr;
70
    }
71
72
    std::unique_ptr<DataCollectedNotification> result(new DataCollectedNotification());
73
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
74
    errors->push();
75
    protocol::Value* valueValue = object->get("value");
76
    errors->setName("value");
77
    result->m_value = ValueConversions<protocol::Array<protocol::DictionaryValue>>::fromValue(valueValue, errors);
78
    errors->pop();
79
    if (errors->hasErrors())
80
        return nullptr;
81
    return result;
82
}
83
84
std::unique_ptr<protocol::DictionaryValue> DataCollectedNotification::toValue() const
85
{
86
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
87
    result->setValue("value", ValueConversions<protocol::Array<protocol::DictionaryValue>>::toValue(m_value.get()));
88
    return result;
89
}
90
91
std::unique_ptr<DataCollectedNotification> DataCollectedNotification::clone() const
92
{
93
    ErrorSupport errors;
94
    return fromValue(toValue().get(), &errors);
95
}
96
97
// ------------- Enum values from params.
98
99
100
// ------------- Frontend notifications.
101
102
void Frontend::dataCollected(std::unique_ptr<protocol::Array<protocol::DictionaryValue>> value)
103
{
104
    if (!m_frontendChannel)
105
        return;
106
    std::unique_ptr<DataCollectedNotification> messageData = DataCollectedNotification::create()
107
        .setValue(std::move(value))
108
        .build();
109
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeTracing.dataCollected", std::move(messageData)));
110
}
111
112
void Frontend::tracingComplete()
113
{
114
    if (!m_frontendChannel)
115
        return;
116
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeTracing.tracingComplete"));
117
}
118
119
void Frontend::flush()
120
{
121
    m_frontendChannel->flushProtocolNotifications();
122
}
123
124
void Frontend::sendRawNotification(const String& notification)
125
{
126
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
127
}
128
129
// --------------------- Dispatcher.
130
131
class DispatcherImpl : public protocol::DispatcherBase {
132
public:
133
163
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
134
        : DispatcherBase(frontendChannel)
135
        , m_backend(backend)
136
163
        , m_fallThroughForNotFound(fallThroughForNotFound) {
137
163
        m_dispatchMap["NodeTracing.getCategories"] = &DispatcherImpl::getCategories;
138
163
        m_dispatchMap["NodeTracing.start"] = &DispatcherImpl::start;
139
163
        m_dispatchMap["NodeTracing.stop"] = &DispatcherImpl::stop;
140
163
    }
141
326
    ~DispatcherImpl() override { }
142
    DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
143
163
    HashMap<String, String>& redirects() { return m_redirects; }
144
145
protected:
146
    using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
147
    using DispatchMap = protocol::HashMap<String, CallHandler>;
148
    DispatchMap m_dispatchMap;
149
    HashMap<String, String> m_redirects;
150
151
    DispatchResponse::Status getCategories(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
152
    DispatchResponse::Status start(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
153
    DispatchResponse::Status stop(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
154
155
    Backend* m_backend;
156
    bool m_fallThroughForNotFound;
157
};
158
159
DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
160
{
161
    protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
162
    if (it == m_dispatchMap.end()) {
163
        if (m_fallThroughForNotFound)
164
            return DispatchResponse::kFallThrough;
165
        reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
166
        return DispatchResponse::kError;
167
    }
168
169
    protocol::ErrorSupport errors;
170
    return (this->*(it->second))(callId, std::move(messageObject), &errors);
171
}
172
173
174
DispatchResponse::Status DispatcherImpl::getCategories(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
175
{
176
    // Declare output parameters.
177
    std::unique_ptr<protocol::Array<String>> out_categories;
178
179
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
180
    DispatchResponse response = m_backend->getCategories(&out_categories);
181
    if (response.status() == DispatchResponse::kFallThrough)
182
        return response.status();
183
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
184
    if (response.status() == DispatchResponse::kSuccess) {
185
        result->setValue("categories", ValueConversions<protocol::Array<String>>::toValue(out_categories.get()));
186
    }
187
    if (weak->get())
188
        weak->get()->sendResponse(callId, response, std::move(result));
189
    return response.status();
190
}
191
192
DispatchResponse::Status DispatcherImpl::start(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
193
{
194
    // Prepare input parameters.
195
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
196
    errors->push();
197
    protocol::Value* traceConfigValue = object ? object->get("traceConfig") : nullptr;
198
    errors->setName("traceConfig");
199
    std::unique_ptr<protocol::NodeTracing::TraceConfig> in_traceConfig = ValueConversions<protocol::NodeTracing::TraceConfig>::fromValue(traceConfigValue, errors);
200
    errors->pop();
201
    if (errors->hasErrors()) {
202
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
203
        return DispatchResponse::kError;
204
    }
205
206
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
207
    DispatchResponse response = m_backend->start(std::move(in_traceConfig));
208
    if (response.status() == DispatchResponse::kFallThrough)
209
        return response.status();
210
    if (weak->get())
211
        weak->get()->sendResponse(callId, response);
212
    return response.status();
213
}
214
215
DispatchResponse::Status DispatcherImpl::stop(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
216
{
217
218
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
219
    DispatchResponse response = m_backend->stop();
220
    if (response.status() == DispatchResponse::kFallThrough)
221
        return response.status();
222
    if (weak->get())
223
        weak->get()->sendResponse(callId, response);
224
    return response.status();
225
}
226
227
// static
228
163
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
229
{
230
163
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
231
163
    uber->setupRedirects(dispatcher->redirects());
232
163
    uber->registerBackend("NodeTracing", std::move(dispatcher));
233
163
}
234
235
} // NodeTracing
236
} // namespace node
237
} // namespace inspector
238
} // namespace protocol