From ebae0d9b4ca87fe37be3f81c476e8f0c50168aca Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Thu, 30 May 2013 12:46:31 +0200 Subject: [PATCH] More changes to facilitate reader/writer stacking. --- lib/c/labcomm.c | 6 +++--- lib/c/labcomm_dynamic_buffer_writer.c | 1 + lib/c/labcomm_fd_reader.c | 4 +++- lib/c/labcomm_fd_writer.c | 4 +++- lib/c/labcomm_private.h | 6 ++++-- lib/c/test/test_labcomm_generated_encoding.c | 1 + 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/c/labcomm.c b/lib/c/labcomm.c index c97a08d..216ca64 100644 --- a/lib/c/labcomm.c +++ b/lib/c/labcomm.c @@ -364,7 +364,7 @@ struct labcomm_encoder *labcomm_encoder_new( result->lock = lock; result->on_error = on_error_fprintf; result->writer->action->alloc(result->writer,result->writer->context, - LABCOMM_VERSION); + result, LABCOMM_VERSION); } return result; } @@ -572,7 +572,7 @@ struct labcomm_decoder *labcomm_decoder_new( result->on_error = on_error_fprintf; result->on_new_datatype = on_new_datatype; result->reader->action->alloc(result->reader, result->reader->context, - LABCOMM_VERSION); + result, LABCOMM_VERSION); } return result; } @@ -625,7 +625,7 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) struct labcomm_sample_entry *entry = NULL; int index, err; - writer.action->alloc(&writer, writer.context, ""); + writer.action->alloc(&writer, writer.context, NULL, ""); writer.action->start(&writer, writer.context, NULL, 0, NULL, NULL); index = labcomm_read_packed32(d->reader); //int signature.name = labcomm_read_string(d->reader); diff --git a/lib/c/labcomm_dynamic_buffer_writer.c b/lib/c/labcomm_dynamic_buffer_writer.c index feb5778..4a1f3ac 100644 --- a/lib/c/labcomm_dynamic_buffer_writer.c +++ b/lib/c/labcomm_dynamic_buffer_writer.c @@ -7,6 +7,7 @@ #include "labcomm_dynamic_buffer_writer.h" static int dyn_alloc(struct labcomm_writer *w, void *context, + struct labcomm_encoder *encoder, char *labcomm_version) { w->data_size = 1000; diff --git a/lib/c/labcomm_fd_reader.c b/lib/c/labcomm_fd_reader.c index 9975564..a9ee68c 100644 --- a/lib/c/labcomm_fd_reader.c +++ b/lib/c/labcomm_fd_reader.c @@ -13,7 +13,9 @@ struct labcomm_fd_reader { int close_fd_on_free; }; -static int fd_alloc(struct labcomm_reader *r, void *context, char *version) +static int fd_alloc(struct labcomm_reader *r, void *context, + struct labcomm_decoder *decoder, + char *version) { int result = 0; diff --git a/lib/c/labcomm_fd_writer.c b/lib/c/labcomm_fd_writer.c index 696e626..6fadb80 100644 --- a/lib/c/labcomm_fd_writer.c +++ b/lib/c/labcomm_fd_writer.c @@ -16,7 +16,9 @@ struct labcomm_fd_writer { static int fd_flush(struct labcomm_writer *w, void *context); -static int fd_alloc(struct labcomm_writer *w, void *context, char *version) +static int fd_alloc(struct labcomm_writer *w, void *context, + struct labcomm_encoder *encoder, + char *version) { w->data = malloc(BUFFER_SIZE); if (! w->data) { diff --git a/lib/c/labcomm_private.h b/lib/c/labcomm_private.h index dfad869..4bd2777 100644 --- a/lib/c/labcomm_private.h +++ b/lib/c/labcomm_private.h @@ -71,7 +71,8 @@ typedef void (*labcomm_decoder_function)( void *context); struct labcomm_reader_action { - int (*alloc)(struct labcomm_reader *r, void *context, char *labcomm_version); + int (*alloc)(struct labcomm_reader *r, void *context, + struct labcomm_decoder *decoder, char *labcomm_version); int (*free)(struct labcomm_reader *r, void *context); int (*start)(struct labcomm_reader *r, void *context); int (*end)(struct labcomm_reader *r, void *context); @@ -196,7 +197,8 @@ typedef int (*labcomm_encoder_function)( struct labcomm_writer; struct labcomm_writer_action { - int (*alloc)(struct labcomm_writer *w, void *context, char *labcomm_version); + int (*alloc)(struct labcomm_writer *w, void *context, + struct labcomm_encoder *encoder, char *labcomm_version); int (*free)(struct labcomm_writer *w, void *context); int (*start)(struct labcomm_writer *w, void *context, struct labcomm_encoder *encoder, diff --git a/lib/c/test/test_labcomm_generated_encoding.c b/lib/c/test/test_labcomm_generated_encoding.c index 059fe7d..6cb0d34 100644 --- a/lib/c/test/test_labcomm_generated_encoding.c +++ b/lib/c/test/test_labcomm_generated_encoding.c @@ -12,6 +12,7 @@ static unsigned char buffer[128]; struct labcomm_writer *writer; static int buf_writer_alloc(struct labcomm_writer *w, void *context, + struct labcomm_encoder *encoder, char *labcomm_version) { writer = w; /* Hack */ -- GitLab