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/NodeWorker.cpp Lines: 101 203 49.8 %
Date: 2019-05-05 22:32:45 Branches: 22 76 28.9 %

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/NodeWorker.h"
8
9
#include "src/node/inspector/protocol/Protocol.h"
10
11
namespace node {
12
namespace inspector {
13
namespace protocol {
14
namespace NodeWorker {
15
16
// ------------- Enum values from types.
17
18
const char Metainfo::domainName[] = "NodeWorker";
19
const char Metainfo::commandPrefix[] = "NodeWorker.";
20
const char Metainfo::version[] = "1.0";
21
22
std::unique_ptr<WorkerInfo> WorkerInfo::fromValue(protocol::Value* value, ErrorSupport* errors)
23
{
24
    if (!value || value->type() != protocol::Value::TypeObject) {
25
        errors->addError("object expected");
26
        return nullptr;
27
    }
28
29
    std::unique_ptr<WorkerInfo> result(new WorkerInfo());
30
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
31
    errors->push();
32
    protocol::Value* workerIdValue = object->get("workerId");
33
    errors->setName("workerId");
34
    result->m_workerId = ValueConversions<String>::fromValue(workerIdValue, errors);
35
    protocol::Value* typeValue = object->get("type");
36
    errors->setName("type");
37
    result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
38
    protocol::Value* titleValue = object->get("title");
39
    errors->setName("title");
40
    result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
41
    protocol::Value* urlValue = object->get("url");
42
    errors->setName("url");
43
    result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
44
    errors->pop();
45
    if (errors->hasErrors())
46
        return nullptr;
47
    return result;
48
}
49
50
4
std::unique_ptr<protocol::DictionaryValue> WorkerInfo::toValue() const
51
{
52
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
53
4
    result->setValue("workerId", ValueConversions<String>::toValue(m_workerId));
54
4
    result->setValue("type", ValueConversions<String>::toValue(m_type));
55
4
    result->setValue("title", ValueConversions<String>::toValue(m_title));
56
4
    result->setValue("url", ValueConversions<String>::toValue(m_url));
57
4
    return result;
58
}
59
60
std::unique_ptr<WorkerInfo> WorkerInfo::clone() const
61
{
62
    ErrorSupport errors;
63
    return fromValue(toValue().get(), &errors);
64
}
65
66
std::unique_ptr<AttachedToWorkerNotification> AttachedToWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
67
{
68
    if (!value || value->type() != protocol::Value::TypeObject) {
69
        errors->addError("object expected");
70
        return nullptr;
71
    }
72
73
    std::unique_ptr<AttachedToWorkerNotification> result(new AttachedToWorkerNotification());
74
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
75
    errors->push();
76
    protocol::Value* sessionIdValue = object->get("sessionId");
77
    errors->setName("sessionId");
78
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
79
    protocol::Value* workerInfoValue = object->get("workerInfo");
80
    errors->setName("workerInfo");
81
    result->m_workerInfo = ValueConversions<protocol::NodeWorker::WorkerInfo>::fromValue(workerInfoValue, errors);
82
    protocol::Value* waitingForDebuggerValue = object->get("waitingForDebugger");
83
    errors->setName("waitingForDebugger");
84
    result->m_waitingForDebugger = ValueConversions<bool>::fromValue(waitingForDebuggerValue, errors);
85
    errors->pop();
86
    if (errors->hasErrors())
87
        return nullptr;
88
    return result;
89
}
90
91
4
std::unique_ptr<protocol::DictionaryValue> AttachedToWorkerNotification::toValue() const
92
{
93
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
94
4
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
95
4
    result->setValue("workerInfo", ValueConversions<protocol::NodeWorker::WorkerInfo>::toValue(m_workerInfo.get()));
96
4
    result->setValue("waitingForDebugger", ValueConversions<bool>::toValue(m_waitingForDebugger));
97
4
    return result;
98
}
99
100
std::unique_ptr<AttachedToWorkerNotification> AttachedToWorkerNotification::clone() const
101
{
102
    ErrorSupport errors;
103
    return fromValue(toValue().get(), &errors);
104
}
105
106
std::unique_ptr<DetachedFromWorkerNotification> DetachedFromWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
107
{
108
    if (!value || value->type() != protocol::Value::TypeObject) {
109
        errors->addError("object expected");
110
        return nullptr;
111
    }
112
113
    std::unique_ptr<DetachedFromWorkerNotification> result(new DetachedFromWorkerNotification());
114
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
115
    errors->push();
116
    protocol::Value* sessionIdValue = object->get("sessionId");
117
    errors->setName("sessionId");
118
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
119
    errors->pop();
120
    if (errors->hasErrors())
121
        return nullptr;
122
    return result;
123
}
124
125
4
std::unique_ptr<protocol::DictionaryValue> DetachedFromWorkerNotification::toValue() const
126
{
127
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
128
4
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
129
4
    return result;
130
}
131
132
std::unique_ptr<DetachedFromWorkerNotification> DetachedFromWorkerNotification::clone() const
133
{
134
    ErrorSupport errors;
135
    return fromValue(toValue().get(), &errors);
136
}
137
138
std::unique_ptr<ReceivedMessageFromWorkerNotification> ReceivedMessageFromWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
139
{
140
    if (!value || value->type() != protocol::Value::TypeObject) {
141
        errors->addError("object expected");
142
        return nullptr;
143
    }
144
145
    std::unique_ptr<ReceivedMessageFromWorkerNotification> result(new ReceivedMessageFromWorkerNotification());
146
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
147
    errors->push();
148
    protocol::Value* sessionIdValue = object->get("sessionId");
149
    errors->setName("sessionId");
150
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
151
    protocol::Value* messageValue = object->get("message");
152
    errors->setName("message");
153
    result->m_message = ValueConversions<String>::fromValue(messageValue, errors);
154
    errors->pop();
155
    if (errors->hasErrors())
156
        return nullptr;
157
    return result;
158
}
159
160
90
std::unique_ptr<protocol::DictionaryValue> ReceivedMessageFromWorkerNotification::toValue() const
161
{
162
90
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
163
90
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
164
90
    result->setValue("message", ValueConversions<String>::toValue(m_message));
165
90
    return result;
166
}
167
168
std::unique_ptr<ReceivedMessageFromWorkerNotification> ReceivedMessageFromWorkerNotification::clone() const
169
{
170
    ErrorSupport errors;
171
    return fromValue(toValue().get(), &errors);
172
}
173
174
// ------------- Enum values from params.
175
176
177
// ------------- Frontend notifications.
178
179
4
void Frontend::attachedToWorker(const String& sessionId, std::unique_ptr<protocol::NodeWorker::WorkerInfo> workerInfo, bool waitingForDebugger)
180
{
181
4
    if (!m_frontendChannel)
182
4
        return;
183
    std::unique_ptr<AttachedToWorkerNotification> messageData = AttachedToWorkerNotification::create()
184
8
        .setSessionId(sessionId)
185
12
        .setWorkerInfo(std::move(workerInfo))
186
8
        .setWaitingForDebugger(waitingForDebugger)
187
8
        .build();
188
4
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.attachedToWorker", std::move(messageData)));
189
}
190
191
4
void Frontend::detachedFromWorker(const String& sessionId)
192
{
193
4
    if (!m_frontendChannel)
194
4
        return;
195
    std::unique_ptr<DetachedFromWorkerNotification> messageData = DetachedFromWorkerNotification::create()
196
8
        .setSessionId(sessionId)
197
4
        .build();
198
4
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.detachedFromWorker", std::move(messageData)));
199
}
200
201
90
void Frontend::receivedMessageFromWorker(const String& sessionId, const String& message)
202
{
203
90
    if (!m_frontendChannel)
204
90
        return;
205
    std::unique_ptr<ReceivedMessageFromWorkerNotification> messageData = ReceivedMessageFromWorkerNotification::create()
206
180
        .setSessionId(sessionId)
207
90
        .setMessage(message)
208
90
        .build();
209
90
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.receivedMessageFromWorker", std::move(messageData)));
210
}
211
212
void Frontend::flush()
213
{
214
    m_frontendChannel->flushProtocolNotifications();
215
}
216
217
void Frontend::sendRawNotification(String notification)
218
{
219
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
220
}
221
222
void Frontend::sendRawNotification(std::vector<uint8_t> notification)
223
{
224
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
225
}
226
227
// --------------------- Dispatcher.
228
229
class DispatcherImpl : public protocol::DispatcherBase {
230
public:
231
4867
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
232
        : DispatcherBase(frontendChannel)
233
4867
        , m_backend(backend) {
234
4867
        m_dispatchMap["NodeWorker.sendMessageToWorker"] = &DispatcherImpl::sendMessageToWorker;
235
4867
        m_dispatchMap["NodeWorker.enable"] = &DispatcherImpl::enable;
236
4867
        m_dispatchMap["NodeWorker.disable"] = &DispatcherImpl::disable;
237
4867
    }
238
8972
    ~DispatcherImpl() override { }
239
    bool canDispatch(const String& method) override;
240
    void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
241
4867
    std::unordered_map<String, String>& redirects() { return m_redirects; }
242
243
protected:
244
    using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
245
    using DispatchMap = std::unordered_map<String, CallHandler>;
246
    DispatchMap m_dispatchMap;
247
    std::unordered_map<String, String> m_redirects;
248
249
    void sendMessageToWorker(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
250
    void enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
251
    void disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
252
253
    Backend* m_backend;
254
};
255
256
11
bool DispatcherImpl::canDispatch(const String& method) {
257
11
    return m_dispatchMap.find(method) != m_dispatchMap.end();
258
}
259
260
11
void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
261
{
262
11
    std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
263
    DCHECK(it != m_dispatchMap.end());
264
11
    protocol::ErrorSupport errors;
265
11
    (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
266
11
}
267
268
269
6
void DispatcherImpl::sendMessageToWorker(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
270
{
271
    // Prepare input parameters.
272
6
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
273
6
    errors->push();
274

6
    protocol::Value* messageValue = object ? object->get("message") : nullptr;
275
6
    errors->setName("message");
276
6
    String in_message = ValueConversions<String>::fromValue(messageValue, errors);
277

6
    protocol::Value* sessionIdValue = object ? object->get("sessionId") : nullptr;
278
6
    errors->setName("sessionId");
279
12
    String in_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
280
6
    errors->pop();
281
6
    if (errors->hasErrors()) {
282
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
283
        return;
284
    }
285
286
12
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
287
12
    DispatchResponse response = m_backend->sendMessageToWorker(in_message, in_sessionId);
288
6
    if (response.status() == DispatchResponse::kFallThrough) {
289
        channel()->fallThrough(callId, method, message);
290
        return;
291
    }
292
6
    if (weak->get())
293
6
        weak->get()->sendResponse(callId, response);
294
12
    return;
295
}
296
297
3
void DispatcherImpl::enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
298
{
299
    // Prepare input parameters.
300
3
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
301
3
    errors->push();
302

3
    protocol::Value* waitForDebuggerOnStartValue = object ? object->get("waitForDebuggerOnStart") : nullptr;
303
3
    errors->setName("waitForDebuggerOnStart");
304
3
    bool in_waitForDebuggerOnStart = ValueConversions<bool>::fromValue(waitForDebuggerOnStartValue, errors);
305
3
    errors->pop();
306
3
    if (errors->hasErrors()) {
307
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
308
        return;
309
    }
310
311
3
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
312
6
    DispatchResponse response = m_backend->enable(in_waitForDebuggerOnStart);
313
3
    if (response.status() == DispatchResponse::kFallThrough) {
314
        channel()->fallThrough(callId, method, message);
315
        return;
316
    }
317
3
    if (weak->get())
318
3
        weak->get()->sendResponse(callId, response);
319
6
    return;
320
}
321
322
2
void DispatcherImpl::disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
323
{
324
325
2
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
326
4
    DispatchResponse response = m_backend->disable();
327
2
    if (response.status() == DispatchResponse::kFallThrough) {
328
        channel()->fallThrough(callId, method, message);
329
        return;
330
    }
331
2
    if (weak->get())
332
2
        weak->get()->sendResponse(callId, response);
333
4
    return;
334
}
335
336
// static
337
4867
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
338
{
339
4867
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
340
4867
    uber->setupRedirects(dispatcher->redirects());
341
4867
    uber->registerBackend("NodeWorker", std::move(dispatcher));
342
4867
}
343
344
} // NodeWorker
345
} // namespace node
346
} // namespace inspector
347
} // namespace protocol