From 39f955c947841fa0863d105b33854e7da6c3bb27 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 12 May 2018 10:41:40 +0200 Subject: [PATCH] io: renamed some fields within struct io --- include/villas/io.h | 38 ++++++++++++++-------------- lib/io.c | 58 +++++++++++++++++++++---------------------- lib/io/villas_human.c | 4 +-- lib/nodes/file.c | 2 +- tests/unit/io.c | 2 +- 5 files changed, 51 insertions(+), 53 deletions(-) diff --git a/include/villas/io.h b/include/villas/io.h index 6e3ac98e3..293ec9c20 100644 --- a/include/villas/io.h +++ b/include/villas/io.h @@ -39,32 +39,30 @@ struct io { enum state state; int flags; + struct { + int counter; /**< Number of samples, read or written by this IO instance */ + + /** A format type can use this file handle or overwrite the + * format::{open,close,eof,rewind} functions and the private + * data in io::_vd. + */ + union { + FILE *std; + AFILE *adv; + } stream; + + char *buffer; + + struct list *signals; + struct node *node; + } input, output; + enum { IO_MODE_STDIO, IO_MODE_ADVIO, IO_MODE_CUSTOM } mode; - /** A format type can use this file handle or overwrite the - * format::{open,close,eof,rewind} functions and the private - * data in io::_vd. - */ - union { - struct { - FILE *input; - FILE *output; - } stdio; - struct { - AFILE *input; - AFILE *output; - } advio; - }; - - struct { - char *input; - char *output; - } buffer; - void *_vd; struct io_format *_vt; }; diff --git a/lib/io.c b/lib/io.c index 0ee4463a6..1f814185d 100644 --- a/lib/io.c +++ b/lib/io.c @@ -64,23 +64,23 @@ int io_stream_open(struct io *io, const char *uri) else if (aislocal(uri)) { io->mode = IO_MODE_STDIO; - io->stdio.output = fopen(uri, "a+"); - if (io->stdio.output == NULL) + io->output.stream.std = fopen(uri, "a+"); + if (io->output.stream.std == NULL) return -1; - io->stdio.input = fopen(uri, "r"); - if (io->stdio.input == NULL) + io->input.stream.std = fopen(uri, "r"); + if (io->input.stream.std == NULL) return -1; } else { io->mode = IO_MODE_ADVIO; - io->advio.output = afopen(uri, "a+"); - if (io->advio.output == NULL) + io->output.stream.adv = afopen(uri, "a+"); + if (io->output.stream.adv == NULL) return -1; - io->advio.input = afopen(uri, "a+"); - if (io->advio.input == NULL) + io->input.stream.adv = afopen(uri, "a+"); + if (io->input.stream.adv == NULL) return -2; } } @@ -88,8 +88,8 @@ int io_stream_open(struct io *io, const char *uri) stdio: io->mode = IO_MODE_STDIO; io->flags |= IO_FLUSH; - io->stdio.input = stdin; - io->stdio.output = stdout; + io->input.stream.std = stdin; + io->output.stream.std = stdout; } /* Make stream non-blocking if desired */ @@ -113,11 +113,11 @@ stdio: io->mode = IO_MODE_STDIO; /* Enable line buffering on stdio */ if (io->mode == IO_MODE_STDIO) { - ret = setvbuf(io->stdio.input, NULL, _IOLBF, BUFSIZ); + ret = setvbuf(io->input.stream.std, NULL, _IOLBF, BUFSIZ); if (ret) return -1; - ret = setvbuf(io->stdio.output, NULL, _IOLBF, BUFSIZ); + ret = setvbuf(io->output.stream.std, NULL, _IOLBF, BUFSIZ); if (ret) return -1; } @@ -131,25 +131,25 @@ int io_stream_close(struct io *io) switch (io->mode) { case IO_MODE_ADVIO: - ret = afclose(io->advio.input); + ret = afclose(io->input.stream.adv); if (ret) return ret; - ret = afclose(io->advio.output); + ret = afclose(io->output.stream.adv); if (ret) return ret; return 0; case IO_MODE_STDIO: - if (io->stdio.input == stdin) + if (io->input.stream.std == stdin) return 0; - ret = fclose(io->stdio.input); + ret = fclose(io->input.stream.std); if (ret) return ret; - ret = fclose(io->stdio.output); + ret = fclose(io->output.stream.std); if (ret) return ret; @@ -166,9 +166,9 @@ int io_stream_flush(struct io *io) { switch (io->mode) { case IO_MODE_ADVIO: - return afflush(io->advio.output); + return afflush(io->output.stream.adv); case IO_MODE_STDIO: - return fflush(io->stdio.output); + return fflush(io->output.stream.std); case IO_MODE_CUSTOM: return 0; } @@ -180,9 +180,9 @@ int io_stream_eof(struct io *io) { switch (io->mode) { case IO_MODE_ADVIO: - return afeof(io->advio.input); + return afeof(io->input.stream.adv); case IO_MODE_STDIO: - return feof(io->stdio.input); + return feof(io->input.stream.std); case IO_MODE_CUSTOM: return 0; } @@ -194,9 +194,9 @@ void io_stream_rewind(struct io *io) { switch (io->mode) { case IO_MODE_ADVIO: - return arewind(io->advio.input); + return arewind(io->input.stream.adv); case IO_MODE_STDIO: - return rewind(io->stdio.input); + return rewind(io->input.stream.std); case IO_MODE_CUSTOM: { } } } @@ -205,9 +205,9 @@ int io_stream_fd(struct io *io) { switch (io->mode) { case IO_MODE_ADVIO: - return afileno(io->advio.input); + return afileno(io->input.stream.adv); case IO_MODE_STDIO: - return fileno(io->stdio.input); + return fileno(io->input.stream.std); case IO_MODE_CUSTOM: return -1; } @@ -266,8 +266,8 @@ int io_print(struct io *io, struct sample *smps[], unsigned cnt) ret = io->_vt->print(io, smps, cnt); else { FILE *f = io->mode == IO_MODE_ADVIO - ? io->advio.output->file - : io->stdio.output; + ? io->output.stream.adv->file + : io->output.stream.std; //flockfile(f); @@ -301,8 +301,8 @@ int io_scan(struct io *io, struct sample *smps[], unsigned cnt) ret = io->_vt->scan(io, smps, cnt); else { FILE *f = io->mode == IO_MODE_ADVIO - ? io->advio.input->file - : io->stdio.input; + ? io->input.stream.adv->file + : io->input.stream.std; //flockfile(f); diff --git a/lib/io/villas_human.c b/lib/io/villas_human.c index 44b8a18af..367ab4ba5 100644 --- a/lib/io/villas_human.c +++ b/lib/io/villas_human.c @@ -238,8 +238,8 @@ int villas_human_print(struct io *io, struct sample *smps[], unsigned cnt) struct villas_human *h = (struct villas_human *) io->_vd; FILE *f = io->mode == IO_MODE_ADVIO - ? io->advio.output->file - : io->stdio.output; + ? io->output.stream.adv->file + : io->output.stream.std; if (!h->header_written) { fprintf(f, "# %-20s\t\t%s\n", "sec.nsec+offset", "data[]"); diff --git a/lib/nodes/file.c b/lib/nodes/file.c index 129619c69..8dafb58d2 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -293,7 +293,7 @@ retry: ret = io_scan(&f->io, smps, cnt); /* Try to download more data if this is a remote file. */ if (f->io.mode == IO_MODE_ADVIO) - adownload(f->io.advio.input, 1); + adownload(f->io.input.stream.adv, 1); goto retry; diff --git a/tests/unit/io.c b/tests/unit/io.c index 110e154c4..4f18f4a1b 100644 --- a/tests/unit/io.c +++ b/tests/unit/io.c @@ -267,7 +267,7 @@ ParameterizedTest(char *fmt, io, highlevel) #endif if (io.mode == IO_MODE_ADVIO) - adownload(io.advio.input, 0); + adownload(io.input.stream.adv, 0); io_rewind(&io);