From c0313c79634df63b4e7741baad023b71ee701e19 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 12 May 2018 13:56:12 +0200 Subject: [PATCH] refactored: io_format -> format_type --- include/villas/{io_format.h => format_type.h} | 24 ++++++++-------- include/villas/{io => formats}/csv.h | 0 include/villas/{io => formats}/json-reserve.h | 0 include/villas/{io => formats}/json.h | 0 include/villas/{io => formats}/msg.h | 0 include/villas/{io => formats}/msg_format.h | 0 include/villas/{io => formats}/protobuf.h | 0 include/villas/{io => formats}/raw.h | 0 .../villas/{io => formats}/villas_binary.h | 0 include/villas/{io => formats}/villas_human.h | 0 include/villas/io.h | 6 ++-- include/villas/nodes/amqp.h | 4 +-- include/villas/nodes/file.h | 2 +- include/villas/nodes/mqtt.h | 4 +-- include/villas/nodes/nanomsg.h | 4 +-- include/villas/nodes/socket.h | 4 +-- include/villas/nodes/test_rtt.h | 2 +- include/villas/nodes/websocket.h | 2 +- include/villas/nodes/zeromq.h | 4 +-- include/villas/plugin.h | 6 ++-- lib/Makefile.villas.inc | 6 ++-- lib/api/actions/capabiltities.c | 2 +- lib/{io => formats}/Makefile.inc | 10 +++---- lib/{io => formats}/csv.c | 4 +-- lib/{io => formats}/json.c | 4 +-- lib/{io => formats}/json_reserve.c | 4 +-- lib/{io => formats}/msg.c | 4 +-- lib/{io => formats}/protobuf.c | 4 +-- lib/{io => formats}/raw.c | 6 ++-- lib/{io => formats}/villas.pb-c.c | 2 +- lib/{io => formats}/villas.pb-c.h | 0 lib/{io => formats}/villas.proto | 0 lib/{io => formats}/villas_binary.c | 14 +++++----- lib/{io => formats}/villas_human.c | 4 +-- lib/hooks/print.c | 6 ++-- lib/io.c | 16 +++++------ lib/io_format.c | 14 +++++----- lib/nodes/amqp.c | 8 +++--- lib/nodes/file.c | 2 +- lib/nodes/mqtt.c | 8 +++--- lib/nodes/nanomsg.c | 8 +++--- lib/nodes/socket.c | 8 +++--- lib/nodes/test_rtt.c | 2 +- lib/nodes/websocket.c | 14 +++++----- lib/nodes/zeromq.c | 8 +++--- src/convert.c | 2 +- src/hook.c | 4 +-- src/node.c | 2 +- src/pipe.c | 2 +- src/signal.c | 2 +- src/test-cmp.c | 6 ++-- tests/unit/advio.c | 19 ++++++------- tests/unit/io.c | 28 ++++++++++--------- 53 files changed, 143 insertions(+), 142 deletions(-) rename include/villas/{io_format.h => format_type.h} (84%) rename include/villas/{io => formats}/csv.h (100%) rename include/villas/{io => formats}/json-reserve.h (100%) rename include/villas/{io => formats}/json.h (100%) rename include/villas/{io => formats}/msg.h (100%) rename include/villas/{io => formats}/msg_format.h (100%) rename include/villas/{io => formats}/protobuf.h (100%) rename include/villas/{io => formats}/raw.h (100%) rename include/villas/{io => formats}/villas_binary.h (100%) rename include/villas/{io => formats}/villas_human.h (100%) rename lib/{io => formats}/Makefile.inc (83%) rename lib/{io => formats}/csv.c (98%) rename lib/{io => formats}/json.c (99%) rename lib/{io => formats}/json_reserve.c (98%) rename lib/{io => formats}/msg.c (97%) rename lib/{io => formats}/protobuf.c (98%) rename lib/{io => formats}/raw.c (98%) rename lib/{io => formats}/villas.pb-c.c (99%) rename lib/{io => formats}/villas.pb-c.h (100%) rename lib/{io => formats}/villas.proto (100%) rename lib/{io => formats}/villas_binary.c (93%) rename lib/{io => formats}/villas_human.c (98%) diff --git a/include/villas/io_format.h b/include/villas/format_type.h similarity index 84% rename from include/villas/io_format.h rename to include/villas/format_type.h index 5f8ecb14a..0bb773a5e 100644 --- a/include/villas/io_format.h +++ b/include/villas/format_type.h @@ -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); diff --git a/include/villas/io/csv.h b/include/villas/formats/csv.h similarity index 100% rename from include/villas/io/csv.h rename to include/villas/formats/csv.h diff --git a/include/villas/io/json-reserve.h b/include/villas/formats/json-reserve.h similarity index 100% rename from include/villas/io/json-reserve.h rename to include/villas/formats/json-reserve.h diff --git a/include/villas/io/json.h b/include/villas/formats/json.h similarity index 100% rename from include/villas/io/json.h rename to include/villas/formats/json.h diff --git a/include/villas/io/msg.h b/include/villas/formats/msg.h similarity index 100% rename from include/villas/io/msg.h rename to include/villas/formats/msg.h diff --git a/include/villas/io/msg_format.h b/include/villas/formats/msg_format.h similarity index 100% rename from include/villas/io/msg_format.h rename to include/villas/formats/msg_format.h diff --git a/include/villas/io/protobuf.h b/include/villas/formats/protobuf.h similarity index 100% rename from include/villas/io/protobuf.h rename to include/villas/formats/protobuf.h diff --git a/include/villas/io/raw.h b/include/villas/formats/raw.h similarity index 100% rename from include/villas/io/raw.h rename to include/villas/formats/raw.h diff --git a/include/villas/io/villas_binary.h b/include/villas/formats/villas_binary.h similarity index 100% rename from include/villas/io/villas_binary.h rename to include/villas/formats/villas_binary.h diff --git a/include/villas/io/villas_human.h b/include/villas/formats/villas_human.h similarity index 100% rename from include/villas/io/villas_human.h rename to include/villas/formats/villas_human.h diff --git a/include/villas/io.h b/include/villas/io.h index 9a0d2b688..d073283c3 100644 --- a/include/villas/io.h +++ b/include/villas/io.h @@ -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); diff --git a/include/villas/nodes/amqp.h b/include/villas/nodes/amqp.h index 3b0d9eb18..720dfbc7d 100644 --- a/include/villas/nodes/amqp.h +++ b/include/villas/nodes/amqp.h @@ -37,7 +37,7 @@ #include /* 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 */ diff --git a/include/villas/nodes/file.h b/include/villas/nodes/file.h index 75a40b790..3e4465873 100644 --- a/include/villas/nodes/file.h +++ b/include/villas/nodes/file.h @@ -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. */ diff --git a/include/villas/nodes/mqtt.h b/include/villas/nodes/mqtt.h index 07ef84957..088e1f54a 100644 --- a/include/villas/nodes/mqtt.h +++ b/include/villas/nodes/mqtt.h @@ -36,7 +36,7 @@ #include /* 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 */ diff --git a/include/villas/nodes/nanomsg.h b/include/villas/nodes/nanomsg.h index 04d5c009b..e5f52f018 100644 --- a/include/villas/nodes/nanomsg.h +++ b/include/villas/nodes/nanomsg.h @@ -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 */ diff --git a/include/villas/nodes/socket.h b/include/villas/nodes/socket.h index b7d4c3680..b77a0500f 100644 --- a/include/villas/nodes/socket.h +++ b/include/villas/nodes/socket.h @@ -52,7 +52,7 @@ #include /* 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 { diff --git a/include/villas/nodes/test_rtt.h b/include/villas/nodes/test_rtt.h index 0b5b04037..a0e14e533 100644 --- a/include/villas/nodes/test_rtt.h +++ b/include/villas/nodes/test_rtt.h @@ -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. */ diff --git a/include/villas/nodes/websocket.h b/include/villas/nodes/websocket.h index ced6e522c..1684c695c 100644 --- a/include/villas/nodes/websocket.h +++ b/include/villas/nodes/websocket.h @@ -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; diff --git a/include/villas/nodes/zeromq.h b/include/villas/nodes/zeromq.h index adf0836de..042cf5e14 100644 --- a/include/villas/nodes/zeromq.h +++ b/include/villas/nodes/zeromq.h @@ -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; diff --git a/include/villas/plugin.h b/include/villas/plugin.h index f0a52ddc0..ed6bb7e2b 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -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; diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc index 013d0bad7..52d832fc4 100644 --- a/lib/Makefile.villas.inc +++ b/lib/Makefile.villas.inc @@ -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)) diff --git a/lib/api/actions/capabiltities.c b/lib/api/actions/capabiltities.c index ea2a0d57b..b244279af 100644 --- a/lib/api/actions/capabiltities.c +++ b/lib/api/actions/capabiltities.c @@ -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); } } diff --git a/lib/io/Makefile.inc b/lib/formats/Makefile.inc similarity index 83% rename from lib/io/Makefile.inc rename to lib/formats/Makefile.inc index 5d6129846..dc8e9b087 100644 --- a/lib/io/Makefile.inc +++ b/lib/formats/Makefile.inc @@ -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 diff --git a/lib/io/csv.c b/lib/formats/csv.c similarity index 98% rename from lib/io/csv.c rename to lib/formats/csv.c index a88b9721c..42ad3dcd7 100644 --- a/lib/io/csv.c +++ b/lib/formats/csv.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -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, diff --git a/lib/io/json.c b/lib/formats/json.c similarity index 99% rename from lib/io/json.c rename to lib/formats/json.c index d21365962..bffe67c11 100644 --- a/lib/io/json.c +++ b/lib/formats/json.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include 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, diff --git a/lib/io/json_reserve.c b/lib/formats/json_reserve.c similarity index 98% rename from lib/io/json_reserve.c rename to lib/formats/json_reserve.c index c2e8f29b3..31e31705e 100644 --- a/lib/io/json_reserve.c +++ b/lib/formats/json_reserve.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include 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, diff --git a/lib/io/msg.c b/lib/formats/msg.c similarity index 97% rename from lib/io/msg.c rename to lib/formats/msg.c index 2960fc808..ee70148bd 100644 --- a/lib/io/msg.c +++ b/lib/formats/msg.c @@ -22,8 +22,8 @@ #include -#include -#include +#include +#include #include #include diff --git a/lib/io/protobuf.c b/lib/formats/protobuf.c similarity index 98% rename from lib/io/protobuf.c rename to lib/formats/protobuf.c index defa8aa1a..06d37e184 100644 --- a/lib/io/protobuf.c +++ b/lib/formats/protobuf.c @@ -25,7 +25,7 @@ #include #include -#include +#include 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 diff --git a/lib/io/raw.c b/lib/formats/raw.c similarity index 98% rename from lib/io/raw.c rename to lib/formats/raw.c index 7f3e26042..bfb8c3f57 100644 --- a/lib/io/raw.c +++ b/lib/formats/raw.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include /** 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 \ } \ diff --git a/lib/io/villas.pb-c.c b/lib/formats/villas.pb-c.c similarity index 99% rename from lib/io/villas.pb-c.c rename to lib/formats/villas.pb-c.c index 4f86e6e61..b8ddd5ec2 100644 --- a/lib/io/villas.pb-c.c +++ b/lib/formats/villas.pb-c.c @@ -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) { diff --git a/lib/io/villas.pb-c.h b/lib/formats/villas.pb-c.h similarity index 100% rename from lib/io/villas.pb-c.h rename to lib/formats/villas.pb-c.h diff --git a/lib/io/villas.proto b/lib/formats/villas.proto similarity index 100% rename from lib/io/villas.proto rename to lib/formats/villas.proto diff --git a/lib/io/villas_binary.c b/lib/formats/villas_binary.c similarity index 93% rename from lib/io/villas_binary.c rename to lib/formats/villas_binary.c index 73f4a7251..c4646e698 100644 --- a/lib/io/villas_binary.c +++ b/lib/formats/villas_binary.c @@ -22,9 +22,9 @@ #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -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 }, }; diff --git a/lib/io/villas_human.c b/lib/formats/villas_human.c similarity index 98% rename from lib/io/villas_human.c rename to lib/formats/villas_human.c index 6adc04242..08dc33ad9 100644 --- a/lib/io/villas_human.c +++ b/lib/formats/villas_human.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include 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, diff --git a/lib/hooks/print.c b/lib/hooks/print.c index 91e7005a1..a4a736215 100644 --- a/lib/hooks/print.c +++ b/lib/hooks/print.c @@ -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); } diff --git a/lib/io.c b/lib/io.c index 6c4f80248..2716122d8 100644 --- a/lib/io.c +++ b/lib/io.c @@ -27,11 +27,11 @@ #include #include -#include +#include #include #include -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; } diff --git a/lib/io_format.c b/lib/io_format.c index 605941875..bb01ae836 100644 --- a/lib/io_format.c +++ b/lib/io_format.c @@ -24,37 +24,37 @@ #include #include -#include +#include -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; diff --git a/lib/nodes/amqp.c b/lib/nodes/amqp.c index 23c21e5db..f6ae610e2 100644 --- a/lib/nodes/amqp.c +++ b/lib/nodes/amqp.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include 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; diff --git a/lib/nodes/file.c b/lib/nodes/file.c index 8dafb58d2..3e0088286 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -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)); diff --git a/lib/nodes/mqtt.c b/lib/nodes/mqtt.c index 305c8f253..c4f10c465 100644 --- a/lib/nodes/mqtt.c +++ b/lib/nodes/mqtt.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #ifdef MQTT_THREAD #include @@ -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; diff --git a/lib/nodes/nanomsg.c b/lib/nodes/nanomsg.c index 04ee08820..2e3bf8603 100644 --- a/lib/nodes/nanomsg.c +++ b/lib/nodes/nanomsg.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include 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; diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 0ccb7d51d..d5b66a2fc 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -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)); diff --git a/lib/nodes/test_rtt.c b/lib/nodes/test_rtt.c index 0f2c677b8..060923325 100644 --- a/lib/nodes/test_rtt.c +++ b/lib/nodes/test_rtt.c @@ -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)); diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index 4a760e5a1..604ef8fca 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -32,8 +32,8 @@ #include #include #include -#include -#include +#include +#include /* 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; diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index e01644137..49c8738d6 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include 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; diff --git a/src/convert.c b/src/convert.c index f95ff2e02..0cd214a27 100644 --- a/src/convert.c +++ b/src/convert.c @@ -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); diff --git a/src/hook.c b/src/hook.c index b98ab9a80..55eac6993 100644 --- a/src/hook.c +++ b/src/hook.c @@ -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); diff --git a/src/node.c b/src/node.c index f864dc5cc..0119362ad 100644 --- a/src/node.c +++ b/src/node.c @@ -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(); diff --git a/src/pipe.c b/src/pipe.c index 7b41d880e..95346878e 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -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); diff --git a/src/signal.c b/src/signal.c index 274136951..588bba5c6 100644 --- a/src/signal.c +++ b/src/signal.c @@ -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); diff --git a/src/test-cmp.c b/src/test-cmp.c index 89b5a1fe5..6bc07d896 100644 --- a/src/test-cmp.c +++ b/src/test-cmp.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -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); diff --git a/tests/unit/advio.c b/tests/unit/advio.c index 18b6f256d..b45c0bb87 100644 --- a/tests/unit/advio.c +++ b/tests/unit/advio.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include /** 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"); diff --git a/tests/unit/io.c b/tests/unit/io.c index 4f18f4a1b..e8217028b 100644 --- a/tests/unit/io.c +++ b/tests/unit/io.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #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);