-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathchannels.cpp
More file actions
64 lines (51 loc) · 1.89 KB
/
channels.cpp
File metadata and controls
64 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* The Universal Data-exchange API.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#include <villas/api/requests/universal.hpp>
#include <villas/api/response.hpp>
#include <villas/utils.hpp>
namespace villas {
namespace node {
namespace api {
namespace universal {
class SignalsRequest : public UniversalRequest {
public:
using UniversalRequest::UniversalRequest;
Response *execute() override {
if (method != Session::Method::GET)
throw Error::invalidMethod(this);
if (body != nullptr)
throw Error::badRequest(nullptr,
"This endpoint does not accept any body data");
auto *json_sigs = json_array();
for (size_t i = 0; i < std::min(api_node->getOutputSignals()->size(),
api_node->write.channels.size());
i++) {
auto sig = api_node->getOutputSignals()->at(i);
auto ch = api_node->write.channels.at(i);
auto *json_sig = ch->toJson(sig);
json_array_append(json_sigs, json_sig);
}
for (size_t i = 0; i < std::min(api_node->getInputSignals()->size(),
api_node->read.channels.size());
i++) {
auto sig = api_node->getInputSignals()->at(i);
auto ch = api_node->read.channels.at(i);
auto *json_sig = ch->toJson(sig);
json_array_append(json_sigs, json_sig);
}
return new JsonResponse(session, HTTP_STATUS_OK, json_sigs);
}
};
// Register API requests
static char n[] = "universal/channels";
static char r[] = "/universal/(" RE_NODE_NAME ")/channels";
static char d[] = "Get channels of universal data-exchange API node";
static RequestPlugin<SignalsRequest, n, r, d> p;
} // namespace universal
} // namespace api
} // namespace node
} // namespace villas