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: 72 125 57.6 %
Date: 2019-08-17 22:35:23 Branches: 19 50 38.0 %

Line Branch Exec Source
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/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
3
std::unique_ptr<TraceConfig> TraceConfig::fromValue(protocol::Value* value, ErrorSupport* errors)
27
{
28

3
    if (!value || value->type() != protocol::Value::TypeObject) {
29
        errors->addError("object expected");
30
        return nullptr;
31
    }
32
33
3
    std::unique_ptr<TraceConfig> result(new TraceConfig());
34
3
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
35
3
    errors->push();
36
3
    protocol::Value* recordModeValue = object->get("recordMode");
37
3
    if (recordModeValue) {
38
        errors->setName("recordMode");
39
        result->m_recordMode = ValueConversions<String>::fromValue(recordModeValue, errors);
40
    }
41
3
    protocol::Value* includedCategoriesValue = object->get("includedCategories");
42
3
    errors->setName("includedCategories");
43
3
    result->m_includedCategories = ValueConversions<protocol::Array<String>>::fromValue(includedCategoriesValue, errors);
44
3
    errors->pop();
45
3
    if (errors->hasErrors())
46
        return nullptr;
47
3
    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
2
void Frontend::tracingComplete()
113
{
114
2
    if (!m_frontendChannel)
115
2
        return;
116
2
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeTracing.tracingComplete"));
117
}
118
119
void Frontend::flush()
120
{
121
    m_frontendChannel->flushProtocolNotifications();
122
}
123
124
4
void Frontend::sendRawJSONNotification(String notification)
125
{
126
4
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
127
4
}
128
129
void Frontend::sendRawCBORNotification(std::vector<uint8_t> notification)
130
{
131
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
132
}
133
134
// --------------------- Dispatcher.
135
136
class DispatcherImpl : public protocol::DispatcherBase {
137
public:
138
5404
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
139
        : DispatcherBase(frontendChannel)
140
5404
        , m_backend(backend) {
141
5404
        m_dispatchMap["NodeTracing.getCategories"] = &DispatcherImpl::getCategories;
142
5404
        m_dispatchMap["NodeTracing.start"] = &DispatcherImpl::start;
143
5404
        m_dispatchMap["NodeTracing.stop"] = &DispatcherImpl::stop;
144
5404
    }
145
9998
    ~DispatcherImpl() override { }
146
    bool canDispatch(const String& method) override;
147
    void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
148
5404
    std::unordered_map<String, String>& redirects() { return m_redirects; }
149
150
protected:
151
    using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
152
    using DispatchMap = std::unordered_map<String, CallHandler>;
153
    DispatchMap m_dispatchMap;
154
    std::unordered_map<String, String> m_redirects;
155
156
    void getCategories(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
157
    void start(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
158
    void stop(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
159
160
    Backend* m_backend;
161
};
162
163
6
bool DispatcherImpl::canDispatch(const String& method) {
164
6
    return m_dispatchMap.find(method) != m_dispatchMap.end();
165
}
166
167
6
void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
168
{
169
6
    std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
170
    DCHECK(it != m_dispatchMap.end());
171
6
    protocol::ErrorSupport errors;
172
6
    (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
173
6
}
174
175
176
1
void DispatcherImpl::getCategories(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
177
{
178
    // Declare output parameters.
179
1
    std::unique_ptr<protocol::Array<String>> out_categories;
180
181
2
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
182
2
    DispatchResponse response = m_backend->getCategories(&out_categories);
183
1
    if (response.status() == DispatchResponse::kFallThrough) {
184
        channel()->fallThrough(callId, method, message);
185
        return;
186
    }
187
2
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
188
1
    if (response.status() == DispatchResponse::kSuccess) {
189
1
        result->setValue("categories", ValueConversions<protocol::Array<String>>::toValue(out_categories.get()));
190
    }
191
1
    if (weak->get())
192
1
        weak->get()->sendResponse(callId, response, std::move(result));
193
2
    return;
194
}
195
196
3
void DispatcherImpl::start(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
197
{
198
    // Prepare input parameters.
199
3
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
200
3
    errors->push();
201

3
    protocol::Value* traceConfigValue = object ? object->get("traceConfig") : nullptr;
202
3
    errors->setName("traceConfig");
203
3
    std::unique_ptr<protocol::NodeTracing::TraceConfig> in_traceConfig = ValueConversions<protocol::NodeTracing::TraceConfig>::fromValue(traceConfigValue, errors);
204
3
    errors->pop();
205
3
    if (errors->hasErrors()) {
206
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
207
        return;
208
    }
209
210
6
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
211
6
    DispatchResponse response = m_backend->start(std::move(in_traceConfig));
212
3
    if (response.status() == DispatchResponse::kFallThrough) {
213
        channel()->fallThrough(callId, method, message);
214
        return;
215
    }
216
3
    if (weak->get())
217
3
        weak->get()->sendResponse(callId, response);
218
6
    return;
219
}
220
221
2
void DispatcherImpl::stop(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
222
{
223
224
2
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
225
4
    DispatchResponse response = m_backend->stop();
226
2
    if (response.status() == DispatchResponse::kFallThrough) {
227
        channel()->fallThrough(callId, method, message);
228
        return;
229
    }
230
2
    if (weak->get())
231
2
        weak->get()->sendResponse(callId, response);
232
4
    return;
233
}
234
235
// static
236
5404
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
237
{
238
5404
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
239
5404
    uber->setupRedirects(dispatcher->redirects());
240
5404
    uber->registerBackend("NodeTracing", std::move(dispatcher));
241
5404
}
242
243
} // NodeTracing
244
} // namespace node
245
} // namespace inspector
246
} // namespace protocol