-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathnode_capi.cpp
More file actions
190 lines (146 loc) · 4.09 KB
/
node_capi.cpp
File metadata and controls
190 lines (146 loc) · 4.09 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* Node C-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/node.hpp>
extern "C" {
#include <villas/node.h>
}
using namespace villas;
using namespace villas::node;
vnode *node_new(const char *id_str, const char *json_str) {
json_error_t err;
uuid_t id;
uuid_parse(id_str, id);
auto *json = json_loads(json_str, 0, &err);
return (vnode *)NodeFactory::make(json, id);
}
int node_prepare(vnode *n) {
auto *nc = (Node *)n;
return nc->prepare();
}
int node_check(vnode *n) {
auto *nc = (Node *)n;
return nc->check();
}
int node_start(vnode *n) {
auto *nc = (Node *)n;
return nc->start();
}
int node_stop(vnode *n) {
auto *nc = (Node *)n;
return nc->stop();
}
int node_pause(vnode *n) {
auto *nc = (Node *)n;
return nc->pause();
}
int node_resume(vnode *n) {
auto *nc = (Node *)n;
return nc->resume();
}
int node_restart(vnode *n) {
auto *nc = (Node *)n;
return nc->restart();
}
int node_destroy(vnode *n) {
auto *nc = (Node *)n;
nc->~Node();
return 0;
}
const char *node_name(vnode *n) {
auto *nc = (Node *)n;
return nc->getName().c_str();
}
const char *node_name_short(vnode *n) {
auto *nc = (Node *)n;
return nc->getNameShort().c_str();
}
const char *node_name_full(vnode *n) {
auto *nc = (Node *)n;
return nc->getNameFull().c_str();
}
const char *node_details(vnode *n) {
auto *nc = (Node *)n;
return nc->getDetails().c_str();
}
unsigned node_input_signals_max_cnt(vnode *n) {
auto *nc = (Node *)n;
return nc->getInputSignalsMaxCount();
}
unsigned node_output_signals_max_cnt(vnode *n) {
auto *nc = (Node *)n;
return nc->getOutputSignalsMaxCount();
}
int node_reverse(vnode *n) {
auto *nc = (Node *)n;
return nc->reverse();
}
int node_read(vnode *n, vsample **smps, unsigned cnt) {
auto *nc = (Node *)n;
return nc->read((villas::node::Sample **)smps, cnt);
}
int node_write(vnode *n, vsample **smps, unsigned cnt) {
auto *nc = (Node *)n;
return nc->write((villas::node::Sample **)smps, cnt);
}
int node_poll_fds(vnode *n, int fds[]) {
auto *nc = (Node *)n;
auto l = nc->getPollFDs();
for (unsigned i = 0; i < l.size() && i < 16; i++)
fds[i] = l[i];
return l.size();
}
int node_netem_fds(vnode *n, int fds[]) {
auto *nc = (Node *)n;
auto l = nc->getNetemFDs();
for (unsigned i = 0; i < l.size() && i < 16; i++)
fds[i] = l[i];
return l.size();
}
bool node_is_valid_name(const char *name) { return Node::isValidName(name); }
bool node_is_enabled(const vnode *n) {
auto *nc = (Node *)n;
return nc->isEnabled();
}
json_t *node_to_json(const vnode *n) {
auto *nc = (Node *)n;
return nc->toJson();
}
const char *node_to_json_str(vnode *n) {
auto json = node_to_json(n);
return json_dumps(json, 0);
}
vsample *sample_alloc(unsigned len) { return (vsample *)sample_alloc_mem(len); }
unsigned sample_length(vsample *s) {
auto *smp = (Sample *)s;
return smp->length;
}
vsample *sample_pack(uint64_t *seq, struct timespec *ts_origin,
struct timespec *ts_received, unsigned len,
double *values) {
auto *smp = sample_alloc_mem(len);
smp->sequence = *seq;
smp->ts.origin = *ts_origin;
smp->ts.received = *ts_received;
smp->length = len;
smp->flags = (int)SampleFlags::HAS_SEQUENCE | (int)SampleFlags::HAS_DATA |
(int)SampleFlags::HAS_TS_ORIGIN;
memcpy(reinterpret_cast<double *>(smp->data), values, sizeof(double) * len);
return (vsample *)smp;
}
void sample_unpack(vsample *s, uint64_t *seq, struct timespec *ts_origin,
struct timespec *ts_received, int *flags, unsigned *len,
double *values) {
auto *smp = (Sample *)s;
*seq = smp->sequence;
*ts_origin = smp->ts.origin;
*ts_received = smp->ts.received;
*flags = smp->flags;
*len = smp->length;
memcpy(values, (double *)smp->data, sizeof(double) * *len);
}
void sample_decref(vsample *smp) { sample_decref((Sample *)smp); }
int memory_init(int hugepages) { return memory::init(hugepages); }