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

io: several fixes

This commit is contained in:
Steffen Vogel 2018-05-12 15:25:47 +02:00
parent 4ba077d14e
commit 011971920d
7 changed files with 38 additions and 24 deletions

View file

@ -23,6 +23,7 @@
#include <villas/plugin.h>
#include <villas/sample.h>
#include <villas/compat.h>
#include <villas/io.h>
#include <villas/formats/json.h>
static json_t * json_pack_timestamps(struct sample *smp)
@ -244,13 +245,15 @@ int json_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], uns
return ret;
}
int json_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags)
int json_print(struct io *io, struct sample *smps[], unsigned cnt)
{
int ret, i;
json_t *json;
FILE *f = io_stream_output(io);
for (i = 0; i < cnt; i++) {
ret = json_pack_sample(&json, smps[i], flags);
ret = json_pack_sample(&json, smps[i], io->flags);
if (ret)
return ret;
@ -263,18 +266,20 @@ int json_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags)
return i;
}
int json_fscan(FILE *f, struct sample *smps[], unsigned cnt, int flags)
int json_scan(struct io *io, struct sample *smps[], unsigned cnt)
{
int i, ret;
json_t *json;
json_error_t err;
FILE *f = io_stream_input(io);
for (i = 0; i < cnt; i++) {
skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
if (!json)
break;
ret = json_unpack_sample(json, smps[i], flags);
ret = json_unpack_sample(json, smps[i], io->flags);
if (ret)
goto skip;
@ -289,8 +294,8 @@ static struct plugin p = {
.description = "Javascript Object Notation",
.type = PLUGIN_TYPE_FORMAT,
.io = {
.fscan = json_fscan,
.fprint = json_fprint,
.scan = json_scan,
.print = json_print,
.sscan = json_sscan,
.sprint = json_sprint,
.size = 0

View file

@ -26,6 +26,7 @@
#include <villas/signal.h>
#include <villas/compat.h>
#include <villas/timing.h>
#include <villas/io.h>
#include <villas/formats/json.h>
int json_reserve_pack_sample(json_t **j, struct sample *smp, int flags)
@ -208,13 +209,15 @@ int json_reserve_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smp
return ret;
}
int json_reserve_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags)
int json_reserve_print(struct io *io, struct sample *smps[], unsigned cnt)
{
int ret, i;
json_t *json;
FILE *f = io_stream_output(io);
for (i = 0; i < cnt; i++) {
ret = json_reserve_pack_sample(&json, smps[i], flags);
ret = json_reserve_pack_sample(&json, smps[i], io->flags);
if (ret)
return ret;
@ -227,18 +230,20 @@ int json_reserve_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags)
return i;
}
int json_reserve_fscan(FILE *f, struct sample *smps[], unsigned cnt, int flags)
int json_reserve_scan(struct io *io, struct sample *smps[], unsigned cnt)
{
int i, ret;
json_t *json;
json_error_t err;
FILE *f = io_stream_input(io);
for (i = 0; i < cnt; i++) {
skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
if (!json)
break;
ret = json_reserve_unpack_sample(json, smps[i], flags);
ret = json_reserve_unpack_sample(json, smps[i], io->flags);
if (ret)
goto skip;
@ -253,8 +258,8 @@ static struct plugin p = {
.description = "RESERVE JSON format",
.type = PLUGIN_TYPE_FORMAT,
.io = {
.fscan = json_reserve_fscan,
.fprint = json_reserve_fprint,
.scan = json_reserve_scan,
.print = json_reserve_print,
.sscan = json_reserve_sscan,
.sprint = json_reserve_sprint,
.size = 0

View file

@ -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_FORMAT, \
.type = PLUGIN_TYPE_FORMAT, \
.io = { \
.flags = f | format_type_BINARY, \
.flags = f | FORMAT_TYPE_BINARY,\
.sprint = raw_sprint, \
.sscan = raw_sscan \
} \

View file

@ -1,5 +1,5 @@
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: lib/io/villas.proto */
/* Generated from: lib/formats/villas.proto */
/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED

View file

@ -1,8 +1,8 @@
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: lib/io/villas.proto */
/* Generated from: lib/formats/villas.proto */
#ifndef PROTOBUF_C_lib_2fio_2fvillas_2eproto__INCLUDED
#define PROTOBUF_C_lib_2fio_2fvillas_2eproto__INCLUDED
#ifndef PROTOBUF_C_lib_2fformats_2fvillas_2eproto__INCLUDED
#define PROTOBUF_C_lib_2fformats_2fvillas_2eproto__INCLUDED
#include <protobuf-c/protobuf-c.h>
@ -218,4 +218,4 @@ extern const ProtobufCMessageDescriptor villas__node__value__descriptor;
PROTOBUF_C__END_DECLS
#endif /* PROTOBUF_C_lib_2fio_2fvillas_2eproto__INCLUDED */
#endif /* PROTOBUF_C_lib_2fformats_2fvillas_2eproto__INCLUDED */

View file

@ -120,7 +120,7 @@ static struct plugin p1 = {
.sprint = villas_binary_sprint,
.sscan = villas_binary_sscan,
.size = 0,
.flags = format_type_BINARY
.flags = FORMAT_TYPE_BINARY
},
};
@ -133,7 +133,7 @@ static struct plugin p2 = {
.sprint = villas_binary_sprint,
.sscan = villas_binary_sscan,
.size = 0,
.flags = format_type_BINARY | VILLAS_BINARY_WEB
.flags = FORMAT_TYPE_BINARY | VILLAS_BINARY_WEB
},
};

View file

@ -183,6 +183,7 @@ ParameterizedTest(char *fmt, io, lowlevel)
struct pool p = { .state = STATE_DESTROYED };
struct sample *smps[NUM_SAMPLES];
struct sample *smpt[NUM_SAMPLES];
struct io io;
ret = pool_init(&p, 2 * NUM_SAMPLES, SAMPLE_LEN(NUM_VALUES), &memtype_hugepage);
cr_assert_eq(ret, 0);
@ -194,10 +195,13 @@ ParameterizedTest(char *fmt, io, lowlevel)
f = format_type_lookup(fmt);
cr_assert_not_null(f, "Format '%s' does not exist", fmt);
ret = format_type_sprint(f, buf, sizeof(buf), &wbytes, smps, NUM_SAMPLES, SAMPLE_HAS_ALL);
ret = io_init(&io, f, NULL, SAMPLE_HAS_ALL);
cr_assert_eq(ret, 0);
ret = io_sprint(&io, buf, sizeof(buf), &wbytes, smps, NUM_SAMPLES);
cr_assert_eq(ret, NUM_SAMPLES);
ret = format_type_sscan(f, buf, wbytes, &rbytes, smpt, NUM_SAMPLES, 0);
ret = io_sscan(&io, buf, wbytes, &rbytes, smpt, NUM_SAMPLES);
cr_assert_eq(rbytes, wbytes);
cr_assert_eq_samples(f, smps, smpt, ret);
@ -247,7 +251,7 @@ ParameterizedTest(char *fmt, io, highlevel)
f = format_type_lookup(fmt);
cr_assert_not_null(f, "Format '%s' does not exist", fmt);
ret = io_init(&io, f, SAMPLE_HAS_ALL);
ret = io_init(&io, f, NULL, SAMPLE_HAS_ALL);
cr_assert_eq(ret, 0);
ret = io_open(&io, fn);