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

refactored: io_format -> format_type

This commit is contained in:
Steffen Vogel 2018-05-12 13:56:12 +02:00
parent 3438dc305d
commit c0313c7963
53 changed files with 143 additions and 142 deletions

View file

@ -29,11 +29,11 @@
struct sample;
struct io;
enum io_format_flags {
IO_FORMAT_BINARY = (1 << 8)
enum format_type_flags {
format_type_BINARY = (1 << 8)
};
struct io_format {
struct format_type {
int (*init)(struct io *io);
int (*destroy)(struct io *io);
@ -89,16 +89,16 @@ struct io_format {
* Low-level interface
*/
/** @see io_format_sscan */
/** @see format_type_sscan */
int (*sscan)(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
/** @see io_format_sprint */
/** @see format_type_sprint */
int (*sprint)(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
/** @see io_format_fscan */
/** @see format_type_fscan */
int (*fscan)(FILE *f, struct sample *smps[], unsigned cnt, int flags);
/** @see io_format_fprint */
/** @see format_type_fprint */
int (*fprint)(FILE *f, struct sample *smps[], unsigned cnt, int flags);
/** @} */
@ -107,7 +107,7 @@ struct io_format {
int flags; /**< A set of flags which is automatically used. */
};
struct io_format * io_format_lookup(const char *name);
struct format_type * format_type_lookup(const char *name);
/** Parse samples from the buffer \p buf with a length of \p len bytes.
*
@ -120,7 +120,7 @@ struct io_format * io_format_lookup(const char *name);
* @retval >=0 The number of samples which have been parsed from \p buf and written into \p smps.
* @retval <0 Something went wrong.
*/
int io_format_sscan(struct io_format *fmt, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
int format_type_sscan(struct format_type *fmt, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
/** Print \p cnt samples from \p smps into buffer \p buf of length \p len.
*
@ -133,18 +133,18 @@ int io_format_sscan(struct io_format *fmt, char *buf, size_t len, size_t *rbytes
* @retval >=0 The number of samples from \p smps which have been written into \p buf.
* @retval <0 Something went wrong.
*/
int io_format_sprint(struct io_format *fmt, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
int format_type_sprint(struct format_type *fmt, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
/** Parse up to \p cnt samples from stream \p f into array \p smps.
*
* @retval >=0 The number of samples which have been parsed from \p f and written into \p smps.
* @retval <0 Something went wrong.
*/
int io_format_fscan(struct io_format *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags);
int format_type_fscan(struct format_type *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags);
/** Print \p cnt samples from \p smps to stream \p f.
*
* @retval >=0 The number of samples from \p smps which have been written to \p f.
* @retval <0 Something went wrong.
*/
int io_format_fprint(struct io_format *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags);
int format_type_fprint(struct format_type *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags);

View file

@ -28,7 +28,7 @@
/* Forward declarations */
struct sample;
struct io_format;
struct format_type;
enum io_flags {
IO_FLUSH = (1 << 8), /**< Flush the output stream after each chunk of samples. */
@ -65,10 +65,10 @@ struct io {
} mode;
void *_vd;
struct io_format *_vt;
struct format_type *_vt;
};
int io_init(struct io *io, struct io_format *fmt, int flags);
int io_init(struct io *io, struct format_type *fmt, int flags);
int io_destroy(struct io *io);

View file

@ -37,7 +37,7 @@
#include <villas/list.h>
/* Forward declarations */
struct io_format;
struct format_type;
struct amqp_ssl_info {
int verify_peer;
@ -60,7 +60,7 @@ struct amqp {
amqp_connection_state_t producer;
amqp_connection_state_t consumer;
struct io_format *format;
struct format_type *format;
};
/** @see node_type::print */

View file

@ -39,7 +39,7 @@
struct file {
struct io io; /**< Format and file IO */
struct io_format *format;
struct format_type *format;
char *uri_tmpl; /**< Format string for file name. */
char *uri; /**< Real file name. */

View file

@ -36,7 +36,7 @@
#include <villas/queue_signalled.h>
/* Forward declarations */
struct io_format;
struct format_type;
struct mosquitto;
struct mqtt {
@ -63,7 +63,7 @@ struct mqtt {
char *keyfile; /**< SSL private key. */
} ssl;
struct io_format *format;
struct format_type *format;
};
/** @see node_type::reverse */

View file

@ -38,7 +38,7 @@
#define NANOMSG_MAX_PACKET_LEN 1500
/* Forward declarations */
struct io_format;
struct format_type;
struct nanomsg {
struct {
@ -51,7 +51,7 @@ struct nanomsg {
struct list endpoints;
} subscriber;
struct io_format *format;
struct format_type *format;
};
/** @see node_type::print */

View file

@ -52,7 +52,7 @@
#include <villas/node.h>
/* Forward declarations */
struct io_format;
struct format_type;
/** The maximum length of a packet which contains stuct msg. */
#define SOCKET_INITIAL_BUFFER_LEN 1500
@ -85,7 +85,7 @@ struct socket {
union sockaddr_union local; /**< Local address of the socket */
union sockaddr_union remote; /**< Remote address of the socket */
struct io_format *format;
struct format_type *format;
/* Multicast options */
struct multicast {

View file

@ -49,7 +49,7 @@ struct test_rtt_case {
struct test_rtt {
struct task task; /**< The periodic task for test_rtt_read() */
struct io io; /**< The format of the output file */
struct io_format *format;
struct format_type *format;
double cooldown; /**< Number of seconds to wait beween tests. */

View file

@ -72,7 +72,7 @@ struct websocket_connection {
struct lws *wsi;
struct node *node;
struct io_format *format; /**< The IO format used for this connection. */
struct format_type *format; /**< The IO format used for this connection. */
struct queue queue; /**< For samples which are sent to the WebSocket */
struct websocket_destination *destination;

View file

@ -39,7 +39,7 @@
#endif
/* Forward declarations */
struct io_format;
struct format_type;
struct node;
struct sample;
@ -48,7 +48,7 @@ struct zeromq {
char *filter;
struct io_format *format;
struct format_type *format;
struct {
int enabled;

View file

@ -23,7 +23,7 @@
#pragma once
#include "io_format.h"
#include "format_type.h"
#include "hook.h"
#include "api.h"
#include "common.h"
@ -50,7 +50,7 @@ enum plugin_type {
PLUGIN_TYPE_HOOK,
PLUGIN_TYPE_NODE,
PLUGIN_TYPE_API,
PLUGIN_TYPE_IO,
PLUGIN_TYPE_FORMAT,
PLUGIN_TYPE_FPGA_IP,
PLUGIN_TYPE_MODEL_CBUILDER
};
@ -69,7 +69,7 @@ struct plugin {
int (*unload)(struct plugin *p);
union {
struct io_format io;
struct format_type io;
struct api_action api;
struct node_type node;
struct hook_type hook;

View file

@ -45,8 +45,8 @@ LIB_PKGS += openssl libcurl
include lib/nodes/Makefile.inc
ifeq ($(WITH_IO),1)
LIB_SRCS += lib/io.c lib/io_format.c
include lib/io/Makefile.inc
LIB_SRCS += lib/io.c lib/format_type.c
include lib/formats/Makefile.inc
endif
ifeq ($(WITH_HOOKS),1)
@ -65,7 +65,7 @@ ifeq ($(WITH_API),1)
endif
LIB_SRCS += $(patsubst %, lib/nodes/%.c, $(LIB_NODES))
LIB_SRCS += $(patsubst %, lib/io/%.c, $(LIB_FORMATS))
LIB_SRCS += $(patsubst %, lib/formats/%.c, $(LIB_FORMATS))
# Add flags by pkg-config
LIB_LDLIBS += $(shell $(PKGCONFIG) --libs $(LIB_PKGS))

View file

@ -40,7 +40,7 @@ static int api_capabilities(struct api_action *h, json_t *args, json_t **resp, s
case PLUGIN_TYPE_NODE: json_array_append_new(json_nodes, json_name); break;
case PLUGIN_TYPE_HOOK: json_array_append_new(json_hooks, json_name); break;
case PLUGIN_TYPE_API: json_array_append_new(json_apis, json_name); break;
case PLUGIN_TYPE_IO: json_array_append_new(json_ios, json_name); break;
case PLUGIN_TYPE_FORMAT: json_array_append_new(json_ios, json_name); break;
default: json_decref(json_name);
}
}

View file

@ -21,12 +21,12 @@
###################################################################################
LIB_FORMATS += json json_reserve villas_binary villas_human csv raw
LIB_SRCS += lib/io/msg.c
LIB_SRCS += lib/formats/msg.c
# Enable Google Protobuf IO format
# Enable Google Protobuf format
ifeq ($(WITH_FORMAT_PROTOBUF),1)
ifeq ($(shell $(PKGCONFIG) libprotobuf-c; echo $$?),0)
LIB_SRCS += lib/io/protobuf.c lib/io/villas.pb-c.c
LIB_SRCS += lib/formats/protobuf.c lib/formats/villas.pb-c.c
LIB_PKGS += libprotobuf-c
LIB_FORMATS += protobuf
endif
@ -36,6 +36,6 @@ endif
protoc-c --proto_path=$(SRCDIR) --c_out=$(SRCDIR) --dependency_out=$(BUILDDIR)/$*.d $(realpath $^)
$(BUILDDIR)/%.pb-c.o: LIB_CFLAGS += -I$(SRCDIR)
$(BUILDDIR)/lib/io/protobuf.o: LIB_CFLAGS += -I$(SRCDIR)/lib/io
$(BUILDDIR)/lib/formats/protobuf.o: LIB_CFLAGS += -I$(SRCDIR)/lib/formats
$(BUILDDIR)/lib/io/protobuf.o: lib/io/villas.pb-c.h
$(BUILDDIR)/lib/formats/protobuf.o: lib/formats/villas.pb-c.h

View file

@ -25,7 +25,7 @@
#include <string.h>
#include <villas/io.h>
#include <villas/io/csv.h>
#include <villas/formats/csv.h>
#include <villas/plugin.h>
#include <villas/sample.h>
#include <villas/timing.h>
@ -165,7 +165,7 @@ void csv_header(struct io *io)
static struct plugin p = {
.name = "csv",
.description = "Tabulator-separated values",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.sprint = csv_sprint,
.sscan = csv_sscan,

View file

@ -23,7 +23,7 @@
#include <villas/plugin.h>
#include <villas/sample.h>
#include <villas/compat.h>
#include <villas/io/json.h>
#include <villas/formats/json.h>
static json_t * json_pack_timestamps(struct sample *smp)
{
@ -287,7 +287,7 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
static struct plugin p = {
.name = "json",
.description = "Javascript Object Notation",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.fscan = json_fscan,
.fprint = json_fprint,

View file

@ -26,7 +26,7 @@
#include <villas/signal.h>
#include <villas/compat.h>
#include <villas/timing.h>
#include <villas/io/json.h>
#include <villas/formats/json.h>
int json_reserve_pack_sample(json_t **j, struct sample *smp, int flags)
{
@ -251,7 +251,7 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
static struct plugin p = {
.name = "json.reserve",
.description = "RESERVE JSON format",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.fscan = json_reserve_fscan,
.fprint = json_reserve_fprint,

View file

@ -22,8 +22,8 @@
#include <arpa/inet.h>
#include <villas/io/msg.h>
#include <villas/io/msg_format.h>
#include <villas/formats/msg.h>
#include <villas/formats/msg_format.h>
#include <villas/sample.h>
#include <villas/utils.h>

View file

@ -25,7 +25,7 @@
#include <villas/sample.h>
#include <villas/plugin.h>
#include <villas/io/protobuf.h>
#include <villas/formats/protobuf.h>
int protobuf_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
{
@ -155,7 +155,7 @@ int protobuf_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[],
static struct plugin p = {
.name = "protobuf",
.description = "Google Protobuf",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.sprint = protobuf_sprint,
.sscan = protobuf_sscan

View file

@ -23,7 +23,7 @@
#include <villas/sample.h>
#include <villas/plugin.h>
#include <villas/utils.h>
#include <villas/io/raw.h>
#include <villas/formats/raw.h>
#include <villas/compat.h>
/** Convert float to host byte order */
@ -242,9 +242,9 @@ int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsi
static struct plugin i = { \
.name = n, \
.description = d, \
.type = PLUGIN_TYPE_IO, \
.type = PLUGIN_TYPE_FORMAT, \
.io = { \
.flags = f | IO_FORMAT_BINARY, \
.flags = f | format_type_BINARY, \
.sprint = raw_sprint, \
.sscan = raw_sscan \
} \

View file

@ -6,7 +6,7 @@
#define PROTOBUF_C__NO_DEPRECATED
#endif
#include "lib/io/villas.pb-c.h"
#include "lib/formats/villas.pb-c.h"
void villas__node__message__init
(Villas__Node__Message *message)
{

View file

@ -22,9 +22,9 @@
#include <string.h>
#include <villas/io/villas_binary.h>
#include <villas/io/msg.h>
#include <villas/io/msg_format.h>
#include <villas/formats/villas_binary.h>
#include <villas/formats/msg.h>
#include <villas/formats/msg_format.h>
#include <villas/sample.h>
#include <villas/utils.h>
#include <villas/plugin.h>
@ -115,12 +115,12 @@ int villas_binary_sscan(char *buf, size_t len, size_t *rbytes, struct sample *sm
static struct plugin p1 = {
.name = "villas.binary",
.description = "VILLAS binary network format",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.sprint = villas_binary_sprint,
.sscan = villas_binary_sscan,
.size = 0,
.flags = IO_FORMAT_BINARY
.flags = format_type_BINARY
},
};
@ -128,12 +128,12 @@ static struct plugin p1 = {
static struct plugin p2 = {
.name = "villas.web",
.description = "VILLAS binary network format for WebSockets",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.sprint = villas_binary_sprint,
.sscan = villas_binary_sscan,
.size = 0,
.flags = IO_FORMAT_BINARY | VILLAS_BINARY_WEB
.flags = format_type_BINARY | VILLAS_BINARY_WEB
},
};

View file

@ -29,7 +29,7 @@
#include <villas/utils.h>
#include <villas/timing.h>
#include <villas/sample.h>
#include <villas/io/villas_human.h>
#include <villas/formats/villas_human.h>
size_t villas_human_sprint_single(char *buf, size_t len, struct sample *s, int flags)
{
@ -196,7 +196,7 @@ void villas_human_header(struct io *io)
static struct plugin p = {
.name = "villas.human",
.description = "VILLAS human readable format",
.type = PLUGIN_TYPE_IO,
.type = PLUGIN_TYPE_FORMAT,
.io = {
.sprint = villas_human_sprint,
.sscan = villas_human_sscan,

View file

@ -31,7 +31,7 @@
struct print {
struct io io;
struct io_format *format;
struct format_type *format;
const char *uri;
};
@ -41,7 +41,7 @@ static int print_init(struct hook *h)
struct print *p = (struct print *) h->_vd;
p->uri = NULL;
p->format = io_format_lookup("villas.human");
p->format = format_type_lookup("villas.human");
return 0;
}
@ -93,7 +93,7 @@ static int print_parse(struct hook *h, json_t *cfg)
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
if (format) {
p->format = io_format_lookup(format);
p->format = format_type_lookup(format);
if (!p->format)
jerror(&err, "Invalid format '%s'", format);
}

View file

@ -27,11 +27,11 @@
#include <ctype.h>
#include <villas/io.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
#include <villas/utils.h>
#include <villas/sample.h>
int io_init(struct io *io, struct io_format *fmt, int flags)
int io_init(struct io *io, struct format_type *fmt, int flags)
{
io->_vt = fmt;
io->_vd = alloc(fmt->size);
@ -308,11 +308,11 @@ int io_print(struct io *io, struct sample *smps[], unsigned cnt)
FILE *f = io_stream_output(io);
if (io->_vt->fprint)
ret = io_format_fprint(io->_vt, f, smps, cnt, io->flags);
ret = format_type_fprint(io->_vt, f, smps, cnt, io->flags);
else if (io->_vt->sprint) {
size_t wbytes;
ret = io_format_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, smps, cnt, io->flags);
ret = format_type_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, smps, cnt, io->flags);
fwrite(io->output.buffer, wbytes, 1, f);
}
@ -338,13 +338,13 @@ int io_scan(struct io *io, struct sample *smps[], unsigned cnt)
FILE *f = io_stream_input(io);
if (io->_vt->fscan)
ret = io_format_fscan(io->_vt, f, smps, cnt, io->flags);
ret = format_type_fscan(io->_vt, f, smps, cnt, io->flags);
else if (io->_vt->sscan) {
size_t bytes, rbytes;
bytes = fread(io->input.buffer, 1, io->input.buflen, f);
ret = io_format_sscan(io->_vt, io->input.buffer, bytes, &rbytes, smps, cnt, io->flags);
ret = format_type_sscan(io->_vt, io->input.buffer, bytes, &rbytes, smps, cnt, io->flags);
}
else
ret = -1;
@ -362,7 +362,7 @@ int io_print_lines(struct io *io, struct sample *smps[], unsigned cnt)
for (i = 0; i < cnt; i++) {
size_t wbytes;
ret = io_format_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, &smps[i], 1, io->flags);
ret = format_type_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, &smps[i], 1, io->flags);
if (ret < 0)
return ret;
@ -393,7 +393,7 @@ skip: bytes = getdelim(&io->input.buffer, &io->input.buflen, io->delimiter, f);
if (ptr[0] == '\0' || ptr[0] == '#')
goto skip;
ret = io_format_sscan(io->_vt, io->input.buffer, bytes, &rbytes, &smps[i], 1, io->flags);
ret = format_type_sscan(io->_vt, io->input.buffer, bytes, &rbytes, &smps[i], 1, io->flags);
if (ret < 0)
return ret;
}

View file

@ -24,37 +24,37 @@
#include <stdio.h>
#include <villas/plugin.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
int io_format_sscan(struct io_format *fmt, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int format_type_sscan(struct format_type *fmt, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
{
flags |= fmt->flags;
return fmt->sscan ? fmt->sscan(buf, len, rbytes, smps, cnt, flags) : -1;
}
int io_format_sprint(struct io_format *fmt, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int format_type_sprint(struct format_type *fmt, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
{
flags |= fmt->flags;
return fmt->sprint ? fmt->sprint(buf, len, wbytes, smps, cnt, flags) : -1;
}
int io_format_fscan(struct io_format *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags)
int format_type_fscan(struct format_type *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags)
{
return fmt->sprint ? fmt->fscan(f, smps, cnt, flags) : -1;
}
int io_format_fprint(struct io_format *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags)
int format_type_fprint(struct format_type *fmt, FILE *f, struct sample *smps[], unsigned cnt, int flags)
{
return fmt->fprint ? fmt->fprint(f, smps, cnt, flags) : -1;
}
struct io_format * io_format_lookup(const char *name)
struct format_type * format_type_lookup(const char *name)
{
struct plugin *p;
p = plugin_lookup(PLUGIN_TYPE_IO, name);
p = plugin_lookup(PLUGIN_TYPE_FORMAT, name);
if (!p)
return NULL;

View file

@ -28,7 +28,7 @@
#include <villas/plugin.h>
#include <villas/nodes/amqp.h>
#include <villas/utils.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
static void amqp_default_ssl_info(struct amqp_ssl_info *s)
{
@ -174,7 +174,7 @@ int amqp_parse(struct node *n, json_t *json)
a->ssl_info.client_key = strdup(client_key);
}
a->format = io_format_lookup(format);
a->format = format_type_lookup(format);
if (!a->format)
error("Invalid format '%s' for node %s", format, node_name(n));
@ -295,7 +295,7 @@ int amqp_read(struct node *n, struct sample *smps[], unsigned cnt)
if (rep.reply_type != AMQP_RESPONSE_NORMAL)
return -1;
ret = io_format_sscan(a->format, env.message.body.bytes, env.message.body.len, NULL, smps, cnt, 0);
ret = format_type_sscan(a->format, env.message.body.bytes, env.message.body.len, NULL, smps, cnt, 0);
amqp_destroy_envelope(&env);
@ -309,7 +309,7 @@ int amqp_write(struct node *n, struct sample *smps[], unsigned cnt)
char data[1500];
size_t wbytes;
ret = io_format_sprint(a->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
ret = format_type_sprint(a->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
if (ret <= 0)
return -1;

View file

@ -105,7 +105,7 @@ int file_parse(struct node *n, json_t *cfg)
f->epoch = time_from_double(epoch_flt);
f->uri_tmpl = uri_tmpl ? strdup(uri_tmpl) : NULL;
f->format = io_format_lookup(format);
f->format = format_type_lookup(format);
if (!f->format)
error("Invalid format '%s' for node %s", format, node_name(n));

View file

@ -26,7 +26,7 @@
#include <villas/nodes/mqtt.h>
#include <villas/plugin.h>
#include <villas/utils.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
#ifdef MQTT_THREAD
#include <pthread.h>
@ -183,7 +183,7 @@ static void mqtt_message_cb(struct mosquitto *mosq, void *userdata, const struct
return;
}
ret = io_format_sscan(m->format, msg->payload, msg->payloadlen, NULL, &smp, 1, 0);
ret = format_type_sscan(m->format, msg->payload, msg->payloadlen, NULL, &smp, 1, 0);
if (ret != 1)
return;
@ -278,7 +278,7 @@ int mqtt_parse(struct node *n, json_t *cfg)
m->ssl.keyfile = keyfile ? strdup(keyfile) : NULL;
}
m->format = io_format_lookup(format);
m->format = format_type_lookup(format);
if (!m->format)
error("Invalid format '%s' for node %s", format, node_name(n));
@ -490,7 +490,7 @@ int mqtt_write(struct node *n, struct sample *smps[], unsigned cnt)
char data[1500];
ret = io_format_sprint(m->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
ret = format_type_sprint(m->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
if (ret <= 0)
return -1;

View file

@ -27,7 +27,7 @@
#include <villas/plugin.h>
#include <villas/nodes/nanomsg.h>
#include <villas/utils.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
int nanomsg_reverse(struct node *n)
{
@ -112,7 +112,7 @@ int nanomsg_parse(struct node *n, json_t *cfg)
error("Invalid type for 'subscribe' setting of node %s", node_name(n));
}
m->format = io_format_lookup(format);
m->format = format_type_lookup(format);
if (!m->format)
error("Invalid format '%s' for node %s", format, node_name(n));
@ -223,7 +223,7 @@ int nanomsg_read(struct node *n, struct sample *smps[], unsigned cnt)
if (bytes < 0)
return -1;
return io_format_sscan(m->format, data, bytes, NULL, smps, cnt, 0);
return format_type_sscan(m->format, data, bytes, NULL, smps, cnt, 0);
}
int nanomsg_write(struct node *n, struct sample *smps[], unsigned cnt)
@ -235,7 +235,7 @@ int nanomsg_write(struct node *n, struct sample *smps[], unsigned cnt)
char data[NANOMSG_MAX_PACKET_LEN];
ret = io_format_sprint(m->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
ret = format_type_sprint(m->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
if (ret <= 0)
return -1;

View file

@ -33,7 +33,7 @@
#include <villas/nodes/socket.h>
#include <villas/config.h>
#include <villas/utils.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
#include <villas/sample.h>
#include <villas/queue.h>
#include <villas/plugin.h>
@ -379,7 +379,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt)
goto out;
}
ret = io_format_sscan(s->format, ptr, bytes, &rbytes, smps, cnt, 0);
ret = format_type_sscan(s->format, ptr, bytes, &rbytes, smps, cnt, 0);
if (ret < 0 || bytes != rbytes)
warn("Received invalid packet from node: %s ret=%d, bytes=%zu, rbytes=%zu", node_name(n), ret, bytes, rbytes);
@ -404,7 +404,7 @@ int socket_write(struct node *n, struct sample *smps[], unsigned cnt)
if (!buf)
return -1;
retry: ret = io_format_sprint(s->format, buf, buflen, &wbytes, smps, cnt, SAMPLE_HAS_ALL);
retry: ret = format_type_sprint(s->format, buf, buflen, &wbytes, smps, cnt, SAMPLE_HAS_ALL);
if (ret < 0)
goto out;
@ -477,7 +477,7 @@ int socket_parse(struct node *n, json_t *cfg)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
/* Format */
s->format = io_format_lookup(format);
s->format = format_type_lookup(format);
if (!s->format)
error("Invalid format '%s' for node %s", format, node_name(n));

View file

@ -107,7 +107,7 @@ int test_rtt_parse(struct node *n, json_t *cfg)
t->prefix = strdup(prefix);
/* Initialize IO module */
t->format = io_format_lookup(format);
t->format = format_type_lookup(format);
if (!t->format)
error("Invalid value for setting 'format' of node %s", node_name(n));

View file

@ -32,8 +32,8 @@
#include <villas/buffer.h>
#include <villas/plugin.h>
#include <villas/nodes/websocket.h>
#include <villas/io_format.h>
#include <villas/io/msg_format.h>
#include <villas/format_type.h>
#include <villas/formats/msg_format.h>
/* Private static storage */
static struct list connections = { .state = STATE_DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */
@ -161,7 +161,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
return -1;
}
c->format = io_format_lookup(format);
c->format = format_type_lookup(format);
if (!c->format) {
websocket_connection_close(c, wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, "Invalid format");
return -1;
@ -233,9 +233,9 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
pulled = queue_pull_many(&c->queue, (void **) smps, cnt);
if (pulled > 0) {
io_format_sprint(c->format, c->buffers.send.buf + LWS_PRE, c->buffers.send.size - LWS_PRE, &wbytes, smps, pulled, SAMPLE_HAS_ALL);
format_type_sprint(c->format, c->buffers.send.buf + LWS_PRE, c->buffers.send.size - LWS_PRE, &wbytes, smps, pulled, SAMPLE_HAS_ALL);
ret = lws_write(wsi, (unsigned char *) c->buffers.send.buf + LWS_PRE, wbytes, c->format->flags & IO_FORMAT_BINARY ? LWS_WRITE_BINARY : LWS_WRITE_TEXT);
ret = lws_write(wsi, (unsigned char *) c->buffers.send.buf + LWS_PRE, wbytes, c->format->flags & format_type_BINARY ? LWS_WRITE_BINARY : LWS_WRITE_TEXT);
sample_put_many(smps, pulled);
@ -274,7 +274,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
if (avail < cnt)
warn("Pool underrun for connection: %s", websocket_connection_name(c));
recvd = io_format_sscan(c->format, c->buffers.recv.buf, c->buffers.recv.len, NULL, smps, avail, 0);
recvd = format_type_sscan(c->format, c->buffers.recv.buf, c->buffers.recv.len, NULL, smps, avail, 0);
if (recvd < 0) {
warn("Failed to parse sample data received on connection: %s", websocket_connection_name(c));
break;
@ -367,7 +367,7 @@ int websocket_start(struct node *n)
c->destination = d;
c->_name = NULL;
c->format = io_format_lookup("villas-web"); /** @todo We could parse the format from the URI */
c->format = format_type_lookup("villas-web"); /** @todo We could parse the format from the URI */
d->info.context = web->context;
d->info.vhost = web->vhost;

View file

@ -32,7 +32,7 @@
#include <villas/utils.h>
#include <villas/queue.h>
#include <villas/plugin.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
static void *context;
@ -127,7 +127,7 @@ int zeromq_parse(struct node *n, json_t *cfg)
z->subscriber.endpoint = ep ? strdup(ep) : NULL;
z->filter = filter ? strdup(filter) : NULL;
z->format = io_format_lookup(format);
z->format = format_type_lookup(format);
if (!z->format)
error("Invalid format '%s' for node %s", format, node_name(n));
@ -430,7 +430,7 @@ int zeromq_read(struct node *n, struct sample *smps[], unsigned cnt)
if (ret < 0)
return ret;
recv = io_format_sscan(z->format, zmq_msg_data(&m), zmq_msg_size(&m), NULL, smps, cnt, 0);
recv = format_type_sscan(z->format, zmq_msg_data(&m), zmq_msg_size(&m), NULL, smps, cnt, 0);
ret = zmq_msg_close(&m);
if (ret)
@ -449,7 +449,7 @@ int zeromq_write(struct node *n, struct sample *smps[], unsigned cnt)
char data[4096];
ret = io_format_sprint(z->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
ret = format_type_sprint(z->format, data, sizeof(data), &wbytes, smps, cnt, SAMPLE_HAS_ALL);
if (ret <= 0)
return -1;

View file

@ -102,7 +102,7 @@ check: if (optarg == endptr)
};
for (int i = 0; i < ARRAY_LEN(dirs); i++) {
p = plugin_lookup(PLUGIN_TYPE_IO, dirs[i].name);
p = plugin_lookup(PLUGIN_TYPE_FORMAT, dirs[i].name);
if (!p)
error("Invalid format: %s", dirs[i].name);

View file

@ -91,7 +91,7 @@ static void usage()
printf("\n");
printf("Supported IO formats:\n");
plugin_dump(PLUGIN_TYPE_IO);
plugin_dump(PLUGIN_TYPE_FORMAT);
printf("\n");
printf("Example:");
@ -177,7 +177,7 @@ check: if (optarg == endptr)
error("Failed to initilize memory pool");
/* Initialize IO */
p = plugin_lookup(PLUGIN_TYPE_IO, format);
p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
if (!p)
error("Unknown IO format '%s'", format);

View file

@ -94,7 +94,7 @@ static void usage()
printf("\n");
printf("Supported IO formats:\n");
plugin_dump(PLUGIN_TYPE_IO);
plugin_dump(PLUGIN_TYPE_FORMAT);
printf("\n");
print_copyright();

View file

@ -305,7 +305,7 @@ check: if (optarg == endptr)
if (ret)
error("Failed to initalize real-time");
p = plugin_lookup(PLUGIN_TYPE_IO, format);
p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
if (!p)
error("Invalid format: %s", format);

View file

@ -132,7 +132,7 @@ int main(int argc, char *argv[])
if (ret)
error("Failed to initialize node");
p = plugin_lookup(PLUGIN_TYPE_IO, format);
p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
if (!p)
error("Invalid output format '%s'", format);

View file

@ -28,7 +28,7 @@
#include <villas/sample.h>
#include <villas/io.h>
#include <villas/io_format.h>
#include <villas/format_type.h>
#include <villas/utils.h>
#include <villas/pool.h>
#include <villas/config.h>
@ -40,7 +40,7 @@ struct side {
struct sample *sample;
struct io io;
struct io_format *fmt;
struct format_type *fmt;
};
void usage()
@ -131,7 +131,7 @@ check: if (optarg == endptr)
s[i].format = format;
s[i].path = argv[optind + i];
s[i].fmt = io_format_lookup(s[i].format);
s[i].fmt = format_type_lookup(s[i].format);
if (!s[i].fmt)
error("Invalid IO format: %s", s[i].format);

View file

@ -28,7 +28,7 @@
#include <villas/utils.h>
#include <villas/advio.h>
#include <villas/sample.h>
#include <villas/io/villas_human.h>
#include <villas/formats/villas_human.h>
/** This URI points to a Sciebo share which contains some test files.
* The Sciebo share is read/write accessible via WebDAV. */
@ -95,18 +95,17 @@ Test(advio, download_large)
af = afopen(BASE_URI "/download-large" , "r");
cr_assert(af, "Failed to download file");
ret = villas_human_fscan(af->file, &smp, 1, 0);
cr_assert_eq(ret, 1);
char line[4096];
cr_assert_eq(smp->sequence, 0);
cr_assert_eq(smp->length, 4);
cr_assert_eq(smp->ts.origin.tv_sec, 1497710378);
cr_assert_eq(smp->ts.origin.tv_nsec, 863332240);
afgets(line, 4096, af);
float data[] = { 0.022245, 0.000000, -1.000000, 1.000000 };
/* Check first line */
cr_assert_str_eq(line, "# VILLASnode signal params: type=mixed, values=4, rate=1000.000000, limit=100000, amplitude=1.000000, freq=1.000000\n");
for (int i = 0; i < smp->length; i++)
cr_assert_float_eq(smp->data[i].f, data[i], 1e-5);
while(afgets(line, 4096, af));
/* Check last line */
cr_assert_str_eq(line, "1497710478.862332239(99999) 0.752074 -0.006283 1.000000 0.996000\n");
ret = afclose(af);
cr_assert_eq(ret, 0, "Failed to close file");

View file

@ -33,7 +33,7 @@
#include <villas/plugin.h>
#include <villas/pool.h>
#include <villas/io.h>
#include <villas/io/raw.h>
#include <villas/formats/raw.h>
#define NUM_SAMPLES 10
#define NUM_VALUES 10
@ -117,7 +117,7 @@ void cr_assert_eq_sample(struct sample *a, struct sample *b)
}
}
void cr_assert_eq_samples(struct io_format *f, struct sample *smps[], struct sample *smpt[], unsigned cnt)
void cr_assert_eq_samples(struct format_type *f, struct sample *smps[], struct sample *smpt[], unsigned cnt)
{
/* The RAW format has certain limitations:
* - limited accuracy if smaller datatypes are used
@ -178,7 +178,7 @@ ParameterizedTest(char *fmt, io, lowlevel)
char buf[8192];
size_t wbytes, rbytes;
struct io_format *f;
struct format_type *f;
struct pool p = { .state = STATE_DESTROYED };
struct sample *smps[NUM_SAMPLES];
@ -187,17 +187,17 @@ ParameterizedTest(char *fmt, io, lowlevel)
ret = pool_init(&p, 2 * NUM_SAMPLES, SAMPLE_LEN(NUM_VALUES), &memtype_hugepage);
cr_assert_eq(ret, 0);
info("format = %s", fmt);
info("Running test for format = %s", fmt);
generate_samples(&p, smps, smpt, NUM_SAMPLES, NUM_VALUES);
f = io_format_lookup(fmt);
f = format_type_lookup(fmt);
cr_assert_not_null(f, "Format '%s' does not exist", fmt);
ret = io_format_sprint(f, buf, sizeof(buf), &wbytes, smps, NUM_SAMPLES, SAMPLE_HAS_ALL);
ret = format_type_sprint(f, buf, sizeof(buf), &wbytes, smps, NUM_SAMPLES, SAMPLE_HAS_ALL);
cr_assert_eq(ret, NUM_SAMPLES);
ret = io_format_sscan(f, buf, wbytes, &rbytes, smpt, NUM_SAMPLES, 0);
ret = format_type_sscan(f, buf, wbytes, &rbytes, smpt, NUM_SAMPLES, 0);
cr_assert_eq(rbytes, wbytes);
cr_assert_eq_samples(f, smps, smpt, ret);
@ -220,12 +220,14 @@ ParameterizedTest(char *fmt, io, highlevel)
char *retp;
struct io io;
struct io_format *f;
struct format_type *f;
struct pool p = { .state = STATE_DESTROYED };
struct sample *smps[NUM_SAMPLES];
struct sample *smpt[NUM_SAMPLES];
info("Running test for format = %s", fmt);
ret = pool_init(&p, 2 * NUM_SAMPLES, SAMPLE_LEN(NUM_VALUES), &memtype_hugepage);
cr_assert_eq(ret, 0);
@ -242,7 +244,7 @@ ParameterizedTest(char *fmt, io, highlevel)
ret = asprintf(&fn, "%s/file", dir);
cr_assert_gt(ret, 0);
f = io_format_lookup(fmt);
f = format_type_lookup(fmt);
cr_assert_not_null(f, "Format '%s' does not exist", fmt);
ret = io_init(&io, f, SAMPLE_HAS_ALL);
@ -259,20 +261,20 @@ ParameterizedTest(char *fmt, io, highlevel)
#if 0 /* Show the file contents */
char cmd[128];
if (!strcmp(fmt, "json") || !strcmp(fmt, "villas.human"))
if (!strcmp(fmt, "csv") || !strcmp(fmt, "json") || !strcmp(fmt, "villas.human"))
snprintf(cmd, sizeof(cmd), "cat %s", fn);
else
snprintf(cmd, sizeof(cmd), "hexdump -C %s", fn);
system(cmd);
#endif
io_rewind(&io);
if (io.mode == IO_MODE_ADVIO)
adownload(io.input.stream.adv, 0);
io_rewind(&io);
cnt = io_scan(&io, smpt, NUM_SAMPLES);
cr_assert_gt(cnt, 0, "Failed to read samples back");
cr_assert_gt(cnt, 0, "Failed to read samples back: cnt=%d", cnt);
cr_assert_eq_samples(f, smps, smpt, cnt);