diff --git a/compiler/2014/C_CodeGen.jrag b/compiler/2014/C_CodeGen.jrag index d7da9c0d24882c9071b7f17b9f96f5386288f0d2..f5af0352354ff83d15aad595701c58d69c759e39 100644 --- a/compiler/2014/C_CodeGen.jrag +++ b/compiler/2014/C_CodeGen.jrag @@ -691,7 +691,7 @@ aspect C_Decoder { env.println(")"); env.println("{"); env.indent(); - env.println("return d->register_sample("); + env.println("return d->sample_register("); env.indent(); env.println("d,"); env.println("&signature_" + env.prefix + getName() + ","); diff --git a/lib/c/2014/labcomm2014.c b/lib/c/2014/labcomm2014.c index c2285e8fd5f5590140ea14c026b787fbd2ae7a61..1cd953a789568e82d9ade761d88651754ae218f5 100644 --- a/lib/c/2014/labcomm2014.c +++ b/lib/c/2014/labcomm2014.c @@ -250,11 +250,18 @@ void labcomm2014_set_local_index(struct labcomm2014_signature *signature) int labcomm2014_get_local_index(const struct labcomm2014_signature *signature) { - if (signature->index == 0) { - labcomm2014_error_fatal_global(LABCOMM2014_ERROR_SIGNATURE_NOT_SET, - "Signature not set: %s\n", signature->name); + int result; + if (! signature) { + result = 0; + } else { + if (signature->index == 0) { + labcomm2014_error_fatal_global(LABCOMM2014_ERROR_SIGNATURE_NOT_SET, + "Signature not set: %s\n", + signature->name); + } + result = signature->index; } - return signature->index; + return result; } int labcomm2014_get_local_type_index(const struct labcomm2014_signature *signature) diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c index 4aafbaf2a07b945e44e5d8d9d205457476e1bcb2..def7cf48e6501e08ae13318d0c64a04a89339126 100644 --- a/lib/c/2014/labcomm2014_decoder.c +++ b/lib/c/2014/labcomm2014_decoder.c @@ -312,7 +312,13 @@ static int decode_and_handle(struct labcomm2014_decoder *d, } return result; } + int labcomm2014_decoder_decode_one(struct labcomm2014_decoder *d) +{ + return d->decode_one(d); +} + +static int do_decode_one(struct labcomm2014_decoder *d) { int result, remote_index, length; @@ -385,9 +391,7 @@ int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *d, va_list va; va_start(va, action); - result = labcomm2014_reader_ioctl(d->reader, - d->reader->action_context, - 0, 0, NULL, action, va); + result = d->ioctl(d, NULL, action, va); va_end(va); return result; } @@ -395,6 +399,13 @@ int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *d, int labcomm2014_decoder_sample_ref_register( struct labcomm2014_decoder *d, const struct labcomm2014_signature *signature) +{ + return d->ref_register(d, signature); +} + +static int do_ref_register( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature) { struct decoder *id = d->context; int local_index, *remote_to_local_ref; @@ -428,15 +439,19 @@ static int do_ioctl(struct labcomm2014_decoder *d, int local_index, remote_index; local_index = labcomm2014_get_local_index(signature); - labcomm2014_scheduler_data_lock(d->scheduler); - remote_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, - id->local, - struct sample_entry, - local_index)->remote_index; - labcomm2014_scheduler_data_unlock(d->scheduler); + if (local_index == 0) { + remote_index = 0; + } else { + labcomm2014_scheduler_data_lock(d->scheduler); + remote_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, + id->local, + struct sample_entry, + local_index)->remote_index; + labcomm2014_scheduler_data_unlock(d->scheduler); + } result = labcomm2014_reader_ioctl(d->reader, d->reader->action_context, - local_index, remote_index, - signature, action, va); + local_index, remote_index, + signature, action, va); return result; } @@ -623,6 +638,25 @@ static const struct labcomm2014_signature *do_index_to_signature( return result; } +static void do_free(struct labcomm2014_decoder* d) +{ + struct decoder *id = d->context; + struct labcomm2014_memory *memory = d->memory; + + labcomm2014_reader_free(d->reader, d->reader->action_context); + LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->local, struct sample_entry); + LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->remote_to_local, int); + LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->local_ref, + const struct labcomm2014_signature*); + LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->remote_to_local_ref, int); + labcomm2014_memory_free(memory, 0, id); +} + +void labcomm2014_decoder_free(struct labcomm2014_decoder* d) +{ + d->free(d); +} + struct labcomm2014_decoder *labcomm2014_decoder_new( struct labcomm2014_reader *reader, struct labcomm2014_error_handler *error, @@ -647,7 +681,10 @@ struct labcomm2014_decoder *labcomm2014_decoder_new( result->decoder.memory = memory; result->decoder.scheduler = scheduler; result->decoder.on_error = labcomm20142014_on_error_fprintf; - result->decoder.register_sample = do_register_sample; + result->decoder.free = do_free; + result->decoder.decode_one = do_decode_one; + result->decoder.ref_register = do_ref_register; + result->decoder.sample_register = do_register_sample; result->decoder.ioctl = do_ioctl; result->decoder.index_to_signature = do_index_to_signature; LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry); @@ -659,17 +696,4 @@ struct labcomm2014_decoder *labcomm2014_decoder_new( return &(result->decoder); } -void labcomm2014_decoder_free(struct labcomm2014_decoder* d) -{ - struct decoder *id = d->context; - struct labcomm2014_memory *memory = d->memory; - - labcomm2014_reader_free(d->reader, d->reader->action_context); - LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->local, struct sample_entry); - LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->remote_to_local, int); - LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->local_ref, - const struct labcomm2014_signature*); - LABCOMM_SIGNATURE_ARRAY_FREE(memory, id->remote_to_local_ref, int); - labcomm2014_memory_free(memory, 0, id); -} diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c index d603e5f807f27075a987e0fd1b93c799012a9a0e..e2168e1e3d3172f2a1f120ef4f6322eef21eeac5 100644 --- a/lib/c/2014/labcomm2014_encoder.c +++ b/lib/c/2014/labcomm2014_encoder.c @@ -113,6 +113,13 @@ no_end: int labcomm2014_encoder_sample_ref_register( struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature) +{ + return e->ref_register(e, signature); +} + +static int do_ref_register( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) { int result = -EINVAL; struct encoder *ie = e->context; @@ -153,8 +160,8 @@ out: } int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder, - uint32_t action, - ...) + uint32_t action, + ...) { int result; va_list va; @@ -165,9 +172,7 @@ int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder, } va_start(va, action); - result = labcomm2014_writer_ioctl(encoder->writer, - encoder->writer->action_context, - 0, NULL, action, va); + result = encoder->ioctl(encoder, NULL, action, va); va_end(va); out: @@ -340,6 +345,23 @@ out: #endif } +void labcomm2014_encoder_free(struct labcomm2014_encoder* e) +{ + e->free(e); +} + +static void do_free(struct labcomm2014_encoder* e) +{ + struct encoder *ie = e->context; + struct labcomm2014_memory *memory = e->memory; + + labcomm2014_writer_free(e->writer, e->writer->action_context); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->registered, int); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->sample_ref, int); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->typedefs, int); + labcomm2014_memory_free(memory, 0, ie); +} + static struct labcomm2014_encoder *internal_encoder_new( struct labcomm2014_writer *writer, struct labcomm2014_error_handler *error, @@ -364,9 +386,11 @@ static struct labcomm2014_encoder *internal_encoder_new( result->encoder.error = error; result->encoder.memory = memory; result->encoder.scheduler = scheduler; + result->encoder.free = do_free; result->encoder.type_register = do_type_register; result->encoder.type_bind = do_type_bind; result->encoder.sample_register = do_sample_register; + result->encoder.ref_register = do_ref_register; result->encoder.encode = do_encode; result->encoder.ioctl = do_ioctl; result->encoder.signature_to_index = do_signature_to_index; @@ -399,15 +423,4 @@ struct labcomm2014_encoder *labcomm2014_encoder_new( return internal_encoder_new(writer,error,memory,scheduler,LABCOMM2014_TRUE); } -void labcomm2014_encoder_free(struct labcomm2014_encoder* e) -{ - struct encoder *ie = e->context; - struct labcomm2014_memory *memory = e->memory; - - labcomm2014_writer_free(e->writer, e->writer->action_context); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->registered, int); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->sample_ref, int); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->typedefs, int); - labcomm2014_memory_free(memory, 0, ie); -} diff --git a/lib/c/2014/labcomm2014_private.h b/lib/c/2014/labcomm2014_private.h index b67f748608fcc4a2356b6beca085d9eae1b08dae..2afcf0b035ea0bd9d5607906972af772b3662685 100644 --- a/lib/c/2014/labcomm2014_private.h +++ b/lib/c/2014/labcomm2014_private.h @@ -195,11 +195,15 @@ struct labcomm2014_decoder { int version_ok; labcomm2014_error_handler_callback on_error; labcomm2014_handle_new_datatype_callback on_new_datatype; + void (*free)(struct labcomm2014_decoder *d); + int (*decode_one)(struct labcomm2014_decoder *d); + int (*ref_register)(struct labcomm2014_decoder *d, + const struct labcomm2014_signature *s); /* * Non typesafe registration function to be called from * generated labcomm2014_decoder_register_* functions. */ - int (*register_sample)(struct labcomm2014_decoder *d, + int (*sample_register)(struct labcomm2014_decoder *d, const struct labcomm2014_signature *s, labcomm2014_decoder_function decoder, labcomm2014_handler_function handler, @@ -369,22 +373,25 @@ struct labcomm2014_encoder { struct labcomm2014_error_handler *error; struct labcomm2014_memory *memory; struct labcomm2014_scheduler *scheduler; + void (*free)(struct labcomm2014_encoder *e); int (*type_register)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature); int (*type_bind)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature, char has_deps); - int (*sample_register)(struct labcomm2014_encoder *encoder, + int (*sample_register)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature, labcomm2014_encoder_function encode); - int (*encode)(struct labcomm2014_encoder *encoder, + int (*ref_register)(struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature); + int (*encode)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature, labcomm2014_encoder_function encode, void *value); - int (*ioctl)(struct labcomm2014_encoder *encoder, + int (*ioctl)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); - int (*signature_to_index)(struct labcomm2014_encoder *encoder, + int (*signature_to_index)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature); };