mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
UPDATE formts init now compatible to gcc 6.3 c++
This commit is contained in:
parent
36be027f08
commit
d8447664dd
10 changed files with 207 additions and 142 deletions
|
@ -47,12 +47,11 @@ extern "C" {
|
|||
#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data))
|
||||
|
||||
/** Initialize a message with default values */
|
||||
#define MSG_INIT(len, seq) (struct msg) {\
|
||||
.type = MSG_TYPE_DATA, \
|
||||
.version = MSG_VERSION, \
|
||||
.length = (uint16_t) (len), \
|
||||
.sequence = (uint32_t) (seq), \
|
||||
}
|
||||
#define MSG_INIT(len, seq, i) \
|
||||
i->type = MSG_TYPE_DATA; \
|
||||
i->version = MSG_VERSION; \
|
||||
i->length = (uint16_t) (len); \
|
||||
i->sequence = (uint32_t) (seq);
|
||||
|
||||
/** The timestamp of a message in struct timespec format */
|
||||
#define MSG_TS(msg) (struct timespec) { \
|
||||
|
|
|
@ -71,6 +71,5 @@ list(APPEND FORMAT_SRC
|
|||
)
|
||||
|
||||
add_library(formats STATIC ${FORMAT_SRC})
|
||||
target_compile_options(formats PRIVATE -x c)
|
||||
target_include_directories(formats PUBLIC ${INCLUDE_DIRS})
|
||||
target_link_libraries(formats INTERFACE ${LIBRARIES} PUBLIC villas-common)
|
||||
|
|
|
@ -197,35 +197,50 @@ void csv_header(struct io *io, const struct sample *smp)
|
|||
fprintf(f, "%c", io->delimiter);
|
||||
}
|
||||
|
||||
static struct plugin p1 = {
|
||||
.name = "tsv",
|
||||
.description = "Tabulator-separated values",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.header = csv_header,
|
||||
.sprint = csv_sprint,
|
||||
.sscan = csv_sscan,
|
||||
.size = 0,
|
||||
.flags = IO_NEWLINES |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA,
|
||||
.separator = '\t'
|
||||
}
|
||||
};
|
||||
static struct plugin p1;
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
static struct plugin p2 = {
|
||||
.name = "csv",
|
||||
.description = "Comma-separated values",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.header = csv_header,
|
||||
.sprint = csv_sprint,
|
||||
.sscan = csv_sscan,
|
||||
.size = 0,
|
||||
.flags = IO_NEWLINES |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA,
|
||||
.separator = ','
|
||||
}
|
||||
};
|
||||
p1.name = "tsv";
|
||||
p1.description = "Tabulator-separated values";
|
||||
p1.type = PLUGIN_TYPE_FORMAT;
|
||||
p1.format.header = csv_header;
|
||||
p1.format.sprint = csv_sprint;
|
||||
p1.format.sscan = csv_sscan;
|
||||
p1.format.size = 0;
|
||||
p1.format.flags = IO_NEWLINES |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
p1.format.separator = '\t';
|
||||
|
||||
REGISTER_PLUGIN(&p1);
|
||||
REGISTER_PLUGIN(&p2);
|
||||
vlist_push(&plugins, &p1);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p1);
|
||||
}
|
||||
|
||||
static struct plugin p2;
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p2.name = "csv";
|
||||
p2.description = "Comma-separated values";
|
||||
p2.type = PLUGIN_TYPE_FORMAT;
|
||||
p1.format.header = csv_header;
|
||||
p1.format.sprint = csv_sprint;
|
||||
p1.format.sscan = csv_sscan;
|
||||
p1.format.size = 0;
|
||||
p1.format.flags = IO_NEWLINES |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
p1.format.separator = ',';
|
||||
|
||||
vlist_push(&plugins, &p2);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p2);
|
||||
}
|
||||
|
|
|
@ -347,19 +347,27 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
|
|||
return i;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "json",
|
||||
.description = "Javascript Object Notation",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.print = json_print,
|
||||
.scan = json_scan,
|
||||
.sprint = json_sprint,
|
||||
.sscan = json_sscan,
|
||||
.size = 0,
|
||||
.flags = SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA,
|
||||
.delimiter = '\n'
|
||||
},
|
||||
};
|
||||
static struct plugin p;
|
||||
|
||||
REGISTER_PLUGIN(&p);
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p.name = "json";
|
||||
p.description = "Javascript Object Notation";
|
||||
p.type = PLUGIN_TYPE_FORMAT;
|
||||
p.format.print = json_print;
|
||||
p.format.scan = json_scan;
|
||||
p.format.sprint = json_sprint;
|
||||
p.format.sscan = json_sscan;
|
||||
p.format.size = 0;
|
||||
p.format.flags = SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
p.format.delimiter = '\n';
|
||||
|
||||
vlist_push(&plugins, &p);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p);
|
||||
}
|
||||
|
|
|
@ -323,17 +323,25 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
|
|||
return i;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "json.reserve",
|
||||
.description = "RESERVE JSON format",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.print = json_reserve_print,
|
||||
.scan = json_reserve_scan,
|
||||
.sprint = json_reserve_sprint,
|
||||
.sscan = json_reserve_sscan,
|
||||
.size = 0
|
||||
},
|
||||
};
|
||||
static struct plugin p;
|
||||
|
||||
REGISTER_PLUGIN(&p);
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p.name = "json.reserve";
|
||||
p.description = "RESERVE JSON format";
|
||||
p.type = PLUGIN_TYPE_FORMAT;
|
||||
p.format.print = json_reserve_print;
|
||||
p.format.scan = json_reserve_scan;
|
||||
p.format.sprint = json_reserve_sprint;
|
||||
p.format.sscan = json_reserve_sscan;
|
||||
p.format.size = 0;
|
||||
|
||||
vlist_push(&plugins, &p);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p);
|
||||
}
|
||||
|
|
|
@ -106,23 +106,23 @@ int msg_to_sample(struct msg *msg, struct sample *smp, struct vlist *signals)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msg_from_sample(struct msg *msg, struct sample *smp, struct vlist *signals)
|
||||
int msg_from_sample(struct msg *msgIn, struct sample *smp, struct vlist *signals)
|
||||
{
|
||||
*msg = MSG_INIT(smp->length, smp->sequence);
|
||||
MSG_INIT(smp->length, smp->sequence, msgIn);
|
||||
|
||||
msg->ts.sec = smp->ts.origin.tv_sec;
|
||||
msg->ts.nsec = smp->ts.origin.tv_nsec;
|
||||
msgIn->ts.sec = smp->ts.origin.tv_sec;
|
||||
msgIn->ts.nsec = smp->ts.origin.tv_nsec;
|
||||
|
||||
for (unsigned i = 0; i < smp->length; i++) {
|
||||
struct signal *sig = (struct signal *) vlist_at(signals, i);
|
||||
|
||||
switch (sig->type) {
|
||||
case SIGNAL_TYPE_FLOAT:
|
||||
msg->data[i].f = smp->data[i].f;
|
||||
msgIn->data[i].f = smp->data[i].f;
|
||||
break;
|
||||
|
||||
case SIGNAL_TYPE_INTEGER:
|
||||
msg->data[i].i = smp->data[i].i;
|
||||
msgIn->data[i].i = smp->data[i].i;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -29,10 +29,6 @@
|
|||
#include <villas/plugin.h>
|
||||
#include <villas/formats/protobuf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static enum signal_type protobuf_detect_format(Villas__Node__Value *val)
|
||||
{
|
||||
switch (val->value_case) {
|
||||
|
@ -225,18 +221,25 @@ int protobuf_sscan(struct io *io, const char *buf, size_t len, size_t *rbytes, s
|
|||
return i;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "protobuf",
|
||||
.description = "Google Protobuf",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.sprint = protobuf_sprint,
|
||||
.sscan = protobuf_sscan,
|
||||
.flags = IO_HAS_BINARY_PAYLOAD |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA
|
||||
}
|
||||
};
|
||||
REGISTER_PLUGIN(&p);
|
||||
#ifdef __cplusplus
|
||||
static struct plugin p;
|
||||
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p.name = "protobuf";
|
||||
p.description = "Google Protobuf";
|
||||
p.type = PLUGIN_TYPE_FORMAT;
|
||||
p.format.sprint = protobuf_sprint;
|
||||
p.format.sscan = protobuf_sscan;
|
||||
p.format.flags = IO_HAS_BINARY_PAYLOAD |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
|
||||
vlist_push(&plugins, &p);
|
||||
}
|
||||
#endif
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p);
|
||||
}
|
||||
|
||||
|
|
|
@ -408,20 +408,27 @@ int raw_sscan(struct io *io, const char *buf, size_t len, size_t *rbytes, struct
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define REGISTER_FORMAT_RAW(i, n, d, f) \
|
||||
static struct plugin i = { \
|
||||
.name = n, \
|
||||
.description = d, \
|
||||
.type = PLUGIN_TYPE_FORMAT, \
|
||||
.format = { \
|
||||
.sprint = raw_sprint, \
|
||||
.sscan = raw_sscan, \
|
||||
.flags = f | IO_HAS_BINARY_PAYLOAD |\
|
||||
SAMPLE_HAS_DATA \
|
||||
} \
|
||||
}; \
|
||||
REGISTER_PLUGIN(& i);
|
||||
|
||||
#define REGISTER_FORMAT_RAW(i, n, d, f) \
|
||||
static struct plugin i; \
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() { \
|
||||
if (plugins.state == STATE_DESTROYED) \
|
||||
vlist_init(&plugins); \
|
||||
\
|
||||
i.name = n; \
|
||||
i.description = d; \
|
||||
i.type = PLUGIN_TYPE_FORMAT; \
|
||||
i.format.sprint = raw_sprint; \
|
||||
i.format.sscan = raw_sscan; \
|
||||
i.format.flags = f | IO_HAS_BINARY_PAYLOAD | \
|
||||
SAMPLE_HAS_DATA; \
|
||||
\
|
||||
vlist_push(&plugins, &i); \
|
||||
} \
|
||||
\
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() { \
|
||||
if (plugins.state != STATE_DESTROYED) \
|
||||
vlist_remove_all(&plugins, &i); \
|
||||
}
|
||||
/* Feel free to add additional format identifiers here to suit your needs */
|
||||
REGISTER_FORMAT_RAW(p_8, "raw.8", "Raw 8 bit", RAW_BITS_8)
|
||||
REGISTER_FORMAT_RAW(p_16be, "raw.16.be", "Raw 16 bit, big endian byte-order", RAW_BITS_16 | RAW_BIG_ENDIAN)
|
||||
|
|
|
@ -118,32 +118,51 @@ int villas_binary_sscan(struct io *io, const char *buf, size_t len, size_t *rbyt
|
|||
return i;
|
||||
}
|
||||
|
||||
static struct plugin p1 = {
|
||||
.name = "villas.binary",
|
||||
.description = "VILLAS binary network format",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.sprint = villas_binary_sprint,
|
||||
.sscan = villas_binary_sscan,
|
||||
.size = 0,
|
||||
.flags = IO_HAS_BINARY_PAYLOAD |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA
|
||||
},
|
||||
};
|
||||
static struct plugin p1;
|
||||
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p1.name = "villas.binary";
|
||||
p1.description = "VILLAS binary network format";
|
||||
p1.type = PLUGIN_TYPE_FORMAT;
|
||||
p1.format.sprint = villas_binary_sprint;
|
||||
p1.format.sscan = villas_binary_sscan;
|
||||
p1.format.size = 0;
|
||||
p1.format.flags = IO_HAS_BINARY_PAYLOAD |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
|
||||
vlist_push(&plugins, &p1);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p1);
|
||||
}
|
||||
/** The WebSocket node-type usually uses little endian byte order intead of network byte order */
|
||||
static struct plugin p2 = {
|
||||
.name = "villas.web",
|
||||
.description = "VILLAS binary network format for WebSockets",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.sprint = villas_binary_sprint,
|
||||
.sscan = villas_binary_sscan,
|
||||
.size = 0,
|
||||
.flags = IO_HAS_BINARY_PAYLOAD | VILLAS_BINARY_WEB |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA
|
||||
},
|
||||
};
|
||||
static struct plugin p2;
|
||||
|
||||
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
p2.name = "villas.web";
|
||||
p2.description = "VILLAS binary network format for WebSockets";
|
||||
p2.type = PLUGIN_TYPE_FORMAT;
|
||||
p2.format.sprint = villas_binary_sprint;
|
||||
p2.format.sscan = villas_binary_sscan;
|
||||
p2.format.size = 0;
|
||||
p2.format.flags = IO_HAS_BINARY_PAYLOAD | VILLAS_BINARY_WEB |
|
||||
SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
|
||||
vlist_push(&plugins, &p2);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p2);
|
||||
}
|
||||
REGISTER_PLUGIN(&p1);
|
||||
REGISTER_PLUGIN(&p2);
|
||||
|
|
|
@ -224,19 +224,26 @@ void villas_human_header(struct io *io, const struct sample *smp)
|
|||
fprintf(f, "%c", io->delimiter);
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "villas.human",
|
||||
.description = "VILLAS human readable format",
|
||||
.type = PLUGIN_TYPE_FORMAT,
|
||||
.format = {
|
||||
.header = villas_human_header,
|
||||
.sprint = villas_human_sprint,
|
||||
.sscan = villas_human_sscan,
|
||||
.size = 0,
|
||||
.flags = IO_NEWLINES | SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA,
|
||||
.delimiter = '\n',
|
||||
.separator = '\t'
|
||||
}
|
||||
};
|
||||
static struct plugin p;
|
||||
__attribute__((constructor(110))) static void UNIQUE(__ctor)() {
|
||||
if (plugins.state == STATE_DESTROYED)
|
||||
vlist_init(&plugins);
|
||||
|
||||
REGISTER_PLUGIN(&p);
|
||||
p.name = "villas.human";
|
||||
p.description = "VILLAS human readable format";
|
||||
p.type = PLUGIN_TYPE_FORMAT;
|
||||
p.format.header = villas_human_header;
|
||||
p.format.sprint = villas_human_sprint;
|
||||
p.format.sscan = villas_human_sscan;
|
||||
p.format.size = 0;
|
||||
p.format.flags = IO_NEWLINES | SAMPLE_HAS_TS_ORIGIN | SAMPLE_HAS_SEQUENCE | SAMPLE_HAS_DATA;
|
||||
p.format.delimiter = '\n';
|
||||
p.format.separator = '\t';
|
||||
|
||||
vlist_push(&plugins, &p);
|
||||
}
|
||||
|
||||
__attribute__((destructor(110))) static void UNIQUE(__dtor)() {
|
||||
if (plugins.state != STATE_DESTROYED)
|
||||
vlist_remove_all(&plugins, &p);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue