diff --git a/compiler/C_CodeGen.jrag b/compiler/C_CodeGen.jrag index 1efc0a385b45b216302a9705853b255e3932bae9..5b04da8a379d738642a33ebc6859b8f7c4c0f491 100644 --- a/compiler/C_CodeGen.jrag +++ b/compiler/C_CodeGen.jrag @@ -641,7 +641,8 @@ aspect C_Encoder { env.println(")"); env.println("{"); env.indent(); - env.println("e->writer.write(&e->writer, labcomm_writer_start);"); + env.println("labcomm_encoder_start(e, &labcomm_signature_" + + env.prefix + getName() + ");"); env.println("labcomm_encode_type_index(e, &labcomm_signature_" + env.prefix + getName() + ");"); env.println("{"); @@ -649,7 +650,8 @@ aspect C_Encoder { getType().C_emitEncoder(env); env.unindent(); env.println("}"); - env.println("e->writer.write(&e->writer, labcomm_writer_end);"); + env.println("labcomm_encoder_end(e, &labcomm_signature_" + + env.prefix + getName() + ");"); env.unindent(); env.println("}"); diff --git a/lib/c/labcomm.c b/lib/c/labcomm.c index fd19058876f78fdffdbc4eb5df399ddd18527f4d..3b790e5752cd5e97954df1edf9e800621cac685d 100644 --- a/lib/c/labcomm.c +++ b/lib/c/labcomm.c @@ -183,6 +183,25 @@ static int get_encoder_index( return result; } +void labcomm_encoder_start(struct labcomm_encoder *e, + labcomm_signature_t *s) +{ + int index = get_encoder_index(e, s); + e->writer.write(&e->writer, labcomm_writer_start, index); +} + +void labcomm_encoder_end(struct labcomm_encoder *e, + labcomm_signature_t *s) +{ + e->writer.write(&e->writer, labcomm_writer_end); +} + +void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s) +{ + int index = get_encoder_index(e, s); + labcomm_encode_packed32(e, index); +} + void labcomm_encode_signature(struct labcomm_encoder *e, labcomm_signature_t *signature) { @@ -248,7 +267,7 @@ static void do_encode( } labcomm_encoder_t *labcomm_encoder_new( - int (*writer)(labcomm_writer_t *, labcomm_writer_action_t), + int (*writer)(labcomm_writer_t *, labcomm_writer_action_t, ...), void *writer_context) { labcomm_encoder_t *result = malloc(sizeof(labcomm_encoder_t)); @@ -342,12 +361,6 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, } -void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s) -{ - int index = get_encoder_index(e, s); - labcomm_encode_packed32(e, index); -} - static void collect_flat_signature( labcomm_decoder_t *decoder, labcomm_encoder_t *signature_writer) diff --git a/lib/c/labcomm.h b/lib/c/labcomm.h index d99d8fa9899a5d792bda7423036c477a269d1872..1d4740f36a42394369d96c704772d4b3cd15f79f 100644 --- a/lib/c/labcomm.h +++ b/lib/c/labcomm.h @@ -147,13 +147,13 @@ typedef struct labcomm_writer { int count; int pos; int error; - int (*write)(struct labcomm_writer *, labcomm_writer_action_t); + int (*write)(struct labcomm_writer *, labcomm_writer_action_t, ...); int (*ioctl)(struct labcomm_writer *, int, va_list); labcomm_error_handler_callback on_error; } labcomm_writer_t; struct labcomm_encoder *labcomm_encoder_new( - int (*writer)(labcomm_writer_t *, labcomm_writer_action_t), + int (*writer)(labcomm_writer_t *, labcomm_writer_action_t, ...), void *writer_context); void labcomm_encoder_free( struct labcomm_encoder *encoder); @@ -162,4 +162,10 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, int ioctl_action, ...); +void labcomm_encoder_start(struct labcomm_encoder *e, + labcomm_signature_t *s) ; + +//HERE BE DRAGONS: is the signature_t* needed here? +void labcomm_encoder_end(struct labcomm_encoder *e, + labcomm_signature_t *s) ; #endif diff --git a/lib/c/labcomm_dynamic_buffer_reader_writer.c b/lib/c/labcomm_dynamic_buffer_reader_writer.c index 1e55c41cc9593050f1ef5e14265b162e8c3f8857..b363f175bdfdabdc1485db1ff37ca049f5deec28 100644 --- a/lib/c/labcomm_dynamic_buffer_reader_writer.c +++ b/lib/c/labcomm_dynamic_buffer_reader_writer.c @@ -2,7 +2,7 @@ int labcomm_dynamic_buffer_writer( labcomm_writer_t *w, - labcomm_writer_action_t action) + labcomm_writer_action_t action, ...) { switch (action) { case labcomm_writer_alloc: { diff --git a/lib/c/labcomm_dynamic_buffer_reader_writer.h b/lib/c/labcomm_dynamic_buffer_reader_writer.h index d82152c571889b98799371567b87323043af2f6e..b03e4665e020632d031f10758bcdec1c32d4e351 100644 --- a/lib/c/labcomm_dynamic_buffer_reader_writer.h +++ b/lib/c/labcomm_dynamic_buffer_reader_writer.h @@ -9,6 +9,6 @@ extern int labcomm_dynamic_buffer_reader( extern int labcomm_dynamic_buffer_writer( labcomm_writer_t *writer, - labcomm_writer_action_t action); + labcomm_writer_action_t action, ...); #endif diff --git a/lib/c/labcomm_fd_reader_writer.c b/lib/c/labcomm_fd_reader_writer.c index bd81f7b7b629121269e7a0fb35c37d35d660ee0b..3ddafc4e08ca3ac9ff63ddca429578850003ed28 100644 --- a/lib/c/labcomm_fd_reader_writer.c +++ b/lib/c/labcomm_fd_reader_writer.c @@ -62,7 +62,7 @@ int labcomm_fd_reader( int labcomm_fd_writer( labcomm_writer_t *w, - labcomm_writer_action_t action) + labcomm_writer_action_t action, ...) { int result = 0; int *fd = w->context; diff --git a/lib/c/labcomm_fd_reader_writer.h b/lib/c/labcomm_fd_reader_writer.h index ef6b6378346e2b523de7248c907c3c30310ad253..1de585816ab74ab8334d0a897533c8818b6309b1 100644 --- a/lib/c/labcomm_fd_reader_writer.h +++ b/lib/c/labcomm_fd_reader_writer.h @@ -9,6 +9,6 @@ extern int labcomm_fd_reader( extern int labcomm_fd_writer( labcomm_writer_t *writer, - labcomm_writer_action_t action); + labcomm_writer_action_t action, ...); #endif diff --git a/lib/c/labcomm_private.h b/lib/c/labcomm_private.h index 7638d73378fcffdd1c931447d01680bd568fa3dd..ed5894cd316751f442e1254f43c432ea3cdcbc9a 100644 --- a/lib/c/labcomm_private.h +++ b/lib/c/labcomm_private.h @@ -331,7 +331,7 @@ static inline void labcomm_encode_string(labcomm_encoder_t *e, void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s); static inline int labcomm_buffer_write(struct labcomm_writer *w, - labcomm_writer_action_t action) + labcomm_writer_action_t action, ...) { // If this gets called, it is an error, // so note error and let producer proceed diff --git a/lib/c/test/labcomm_mem_writer.c b/lib/c/test/labcomm_mem_writer.c index 6f26e6922e2074e29dca51914d9540dd234c0855..294a471ef380b46aa95d87146c1f725b9b768bcb 100644 --- a/lib/c/test/labcomm_mem_writer.c +++ b/lib/c/test/labcomm_mem_writer.c @@ -27,7 +27,7 @@ static void copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontex * Write encoded messages to memory. w->context is assumed to be a pointer to a * labcomm_mem_writer_context_t structure. */ -int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action) +int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...) { int result = 0; // Unwrap pointers for easy access. diff --git a/lib/c/test/labcomm_mem_writer.h b/lib/c/test/labcomm_mem_writer.h index 4585903c93beea5ae17bd2a845c216b801a59539..7506342a9844f442008eafae0a565432d0e06f2d 100644 --- a/lib/c/test/labcomm_mem_writer.h +++ b/lib/c/test/labcomm_mem_writer.h @@ -11,7 +11,7 @@ struct labcomm_mem_writer_context_t { unsigned char *buf; // Allocated destination buffer. }; -int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action); +int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...); /* Wrapper the internal static function copy_data. This is needed so that the exceptions can be unit tested. */ void test_copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf);