1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/lib/node_capi.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

191 lines
4.1 KiB
C++
Raw Permalink Normal View History

/* Node C-API.
2022-03-06 21:12:57 -05:00
*
2022-03-15 09:18:01 -04:00
* Author: Steffen Vogel <post@steffenvogel.de>
2022-03-06 21:12:57 -05:00
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2022-07-04 18:20:03 +02:00
* SPDX-License-Identifier: Apache-2.0
*/
2022-03-06 21:12:57 -05:00
#include <villas/node.hpp>
extern "C" {
#include <villas/node.h>
2022-03-06 21:12:57 -05:00
}
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);
2022-03-06 21:12:57 -05:00
}
int node_prepare(vnode *n) {
auto *nc = (Node *)n;
return nc->prepare();
2022-03-06 21:12:57 -05:00
}
int node_check(vnode *n) {
auto *nc = (Node *)n;
return nc->check();
2022-03-06 21:12:57 -05:00
}
int node_start(vnode *n) {
auto *nc = (Node *)n;
return nc->start();
2022-03-06 21:12:57 -05:00
}
int node_stop(vnode *n) {
auto *nc = (Node *)n;
return nc->stop();
2022-03-06 21:12:57 -05:00
}
int node_pause(vnode *n) {
auto *nc = (Node *)n;
return nc->pause();
2022-03-06 21:12:57 -05:00
}
int node_resume(vnode *n) {
auto *nc = (Node *)n;
return nc->resume();
2022-03-06 21:12:57 -05:00
}
int node_restart(vnode *n) {
auto *nc = (Node *)n;
return nc->restart();
2022-03-06 21:12:57 -05:00
}
int node_destroy(vnode *n) {
auto *nc = (Node *)n;
nc->~Node();
return 0;
2022-03-06 21:12:57 -05:00
}
const char *node_name(vnode *n) {
auto *nc = (Node *)n;
return nc->getName().c_str();
2022-03-06 21:12:57 -05:00
}
const char *node_name_short(vnode *n) {
auto *nc = (Node *)n;
return nc->getNameShort().c_str();
2022-03-06 21:12:57 -05:00
}
const char *node_name_full(vnode *n) {
auto *nc = (Node *)n;
return nc->getNameFull().c_str();
2022-03-06 21:12:57 -05:00
}
const char *node_details(vnode *n) {
auto *nc = (Node *)n;
return nc->getDetails().c_str();
2022-03-06 21:12:57 -05:00
}
unsigned node_input_signals_max_cnt(vnode *n) {
auto *nc = (Node *)n;
return nc->getInputSignalsMaxCount();
2022-03-06 21:12:57 -05:00
}
unsigned node_output_signals_max_cnt(vnode *n) {
auto *nc = (Node *)n;
return nc->getOutputSignalsMaxCount();
2022-03-06 21:12:57 -05:00
}
int node_reverse(vnode *n) {
auto *nc = (Node *)n;
return nc->reverse();
2022-03-06 21:12:57 -05:00
}
int node_read(vnode *n, vsample **smps, unsigned cnt) {
auto *nc = (Node *)n;
return nc->read((villas::node::Sample **)smps, cnt);
2022-03-06 21:12:57 -05:00
}
int node_write(vnode *n, vsample **smps, unsigned cnt) {
auto *nc = (Node *)n;
return nc->write((villas::node::Sample **)smps, cnt);
2022-03-06 21:12:57 -05:00
}
int node_poll_fds(vnode *n, int fds[]) {
auto *nc = (Node *)n;
auto l = nc->getPollFDs();
2022-03-06 21:12:57 -05:00
for (unsigned i = 0; i < l.size() && i < 16; i++)
fds[i] = l[i];
2022-03-06 21:12:57 -05:00
return l.size();
2022-03-06 21:12:57 -05:00
}
int node_netem_fds(vnode *n, int fds[]) {
auto *nc = (Node *)n;
auto l = nc->getNetemFDs();
2022-03-06 21:12:57 -05:00
for (unsigned i = 0; i < l.size() && i < 16; i++)
fds[i] = l[i];
2022-03-06 21:12:57 -05:00
return l.size();
2022-03-06 21:12:57 -05:00
}
bool node_is_valid_name(const char *name) { return Node::isValidName(name); }
2022-03-06 21:12:57 -05:00
bool node_is_enabled(const vnode *n) {
auto *nc = (Node *)n;
return nc->isEnabled();
2022-03-06 21:12:57 -05:00
}
json_t *node_to_json(const vnode *n) {
auto *nc = (Node *)n;
return nc->toJson();
2022-03-06 21:12:57 -05:00
}
const char *node_to_json_str(vnode *n) {
auto json = node_to_json(n);
return json_dumps(json, 0);
2022-03-06 21:12:57 -05:00
}
vsample *sample_alloc(unsigned len) { return (vsample *)sample_alloc_mem(len); }
2022-03-06 21:12:57 -05:00
unsigned sample_length(vsample *s) {
auto *smp = (Sample *)s;
return smp->length;
2022-03-06 21:12:57 -05:00
}
vsample *sample_pack(unsigned seq, struct timespec *ts_origin,
struct timespec *ts_received, unsigned len,
double *values) {
auto *smp = sample_alloc_mem(len);
2022-03-06 21:12:57 -05:00
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;
2022-03-06 21:12:57 -05:00
memcpy((double *)smp->data, values, sizeof(double) * len);
2022-03-06 21:12:57 -05:00
return (vsample *)smp;
2022-03-06 21:12:57 -05:00
}
void sample_unpack(vsample *s, unsigned *seq, struct timespec *ts_origin,
struct timespec *ts_received, int *flags, unsigned *len,
double *values) {
auto *smp = (Sample *)s;
2022-03-06 21:12:57 -05:00
*seq = smp->sequence;
2022-03-06 21:12:57 -05:00
*ts_origin = smp->ts.origin;
*ts_received = smp->ts.received;
2022-03-06 21:12:57 -05:00
*flags = smp->flags;
*len = smp->length;
2022-03-06 21:12:57 -05:00
memcpy(values, (double *)smp->data, sizeof(double) * *len);
2022-03-06 21:12:57 -05:00
}
void sample_decref(vsample *smp) { sample_decref((Sample *)smp); }
2022-03-06 21:12:57 -05:00
int memory_init(int hugepages) { return memory::init(hugepages); }