From 9d24c4941962c56ecee3ab5e95ff50fb101dc136 Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Fri, 22 May 2015 16:42:13 +0200 Subject: [PATCH] Renaming decoder implemented --- lib/c/2014/Makefile | 6 +++++- lib/c/2014/labcomm2014.h | 16 ++++++++++++---- lib/c/2014/labcomm2014_decoder.c | 15 +++++++++++++++ lib/c/2014/labcomm2014_encoder.c | 15 +++++++++++++++ lib/c/2014/labcomm2014_private.h | 10 +++++++--- lib/c/2014/labcomm2014_renaming.c | 2 -- lib/c/2014/labcomm2014_renaming_decoder.c | 16 ++++++++++++++++ lib/c/2014/labcomm2014_renaming_encoder.c | 16 ++++++++++++++++ 8 files changed, 86 insertions(+), 10 deletions(-) diff --git a/lib/c/2014/Makefile b/lib/c/2014/Makefile index 596658b..81c0244 100644 --- a/lib/c/2014/Makefile +++ b/lib/c/2014/Makefile @@ -50,7 +50,8 @@ TESTS=test_labcomm_basic_type_encoding \ test_labcomm \ test_labcomm_pthread_scheduler \ test_labcomm_copy \ - test_labcomm_renaming_encoder + test_labcomm_renaming_encoder \ + test_labcomm_renaming_decoder #FIXME: test_labcomm_errors TEST_DIR=test @@ -176,3 +177,6 @@ $(TEST_DIR)/gen/test_labcomm_copy: \ $(TEST_DIR)/gen/test_labcomm_renaming_encoder: \ $(TEST_DIR)/gen/generated_encoding.o + +$(TEST_DIR)/gen/test_labcomm_renaming_decoder: \ + $(TEST_DIR)/gen/generated_encoding.o diff --git a/lib/c/2014/labcomm2014.h b/lib/c/2014/labcomm2014.h index c9e173f..81acb04 100644 --- a/lib/c/2014/labcomm2014.h +++ b/lib/c/2014/labcomm2014.h @@ -109,8 +109,12 @@ int labcomm2014_decoder_sample_ref_register( /* See labcomm2014_ioctl.h for predefined ioctl_action values */ int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *decoder, - uint32_t ioctl_action, - ...); + uint32_t ioctl_action, + ...); + +const struct labcomm2014_signature *labcomm2014_decoder_get_ref_signature( + struct labcomm2014_decoder *decoder, + const struct labcomm2014_signature *signature); /* * Encoder @@ -130,7 +134,11 @@ int labcomm2014_encoder_sample_ref_register( /* See labcomm2014_ioctl.h for predefined ioctl_action values */ int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder, - uint32_t ioctl_action, - ...); + uint32_t ioctl_action, + ...); + +const struct labcomm2014_signature *labcomm2014_encoder_get_sample_ref( + struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature); #endif diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c index def7cf4..a248abe 100644 --- a/lib/c/2014/labcomm2014_decoder.c +++ b/lib/c/2014/labcomm2014_decoder.c @@ -638,6 +638,13 @@ static const struct labcomm2014_signature *do_index_to_signature( return result; } +static const struct labcomm2014_signature *do_get_ref_signature( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature) +{ + return signature; +} + static void do_free(struct labcomm2014_decoder* d) { struct decoder *id = d->context; @@ -687,6 +694,7 @@ struct labcomm2014_decoder *labcomm2014_decoder_new( result->decoder.sample_register = do_register_sample; result->decoder.ioctl = do_ioctl; result->decoder.index_to_signature = do_index_to_signature; + result->decoder.get_ref_signature = do_get_ref_signature; LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry); LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int); LABCOMM_SIGNATURE_ARRAY_INIT(result->local_ref, @@ -697,3 +705,10 @@ struct labcomm2014_decoder *labcomm2014_decoder_new( } +const struct labcomm2014_signature *labcomm2014_decoder_get_ref_signature( + struct labcomm2014_decoder *decoder, + const struct labcomm2014_signature *signature) +{ + return decoder->get_ref_signature(decoder, signature); +} + diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c index e2168e1..a2bf410 100644 --- a/lib/c/2014/labcomm2014_encoder.c +++ b/lib/c/2014/labcomm2014_encoder.c @@ -345,6 +345,13 @@ out: #endif } +static const struct labcomm2014_signature *do_ref_get( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) +{ + return signature; +} + void labcomm2014_encoder_free(struct labcomm2014_encoder* e) { e->free(e); @@ -394,6 +401,7 @@ static struct labcomm2014_encoder *internal_encoder_new( result->encoder.encode = do_encode; result->encoder.ioctl = do_ioctl; result->encoder.signature_to_index = do_signature_to_index; + result->encoder.ref_get = do_ref_get; LABCOMM_SIGNATURE_ARRAY_INIT(result->registered, int); LABCOMM_SIGNATURE_ARRAY_INIT(result->sample_ref, int); LABCOMM_SIGNATURE_ARRAY_INIT(result->typedefs, int); @@ -424,3 +432,10 @@ struct labcomm2014_encoder *labcomm2014_encoder_new( } +const struct labcomm2014_signature *labcomm2014_encoder_get_sample_ref( + struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature) +{ + return encoder->ref_get(encoder, signature); +} + diff --git a/lib/c/2014/labcomm2014_private.h b/lib/c/2014/labcomm2014_private.h index 2afcf0b..ace311a 100644 --- a/lib/c/2014/labcomm2014_private.h +++ b/lib/c/2014/labcomm2014_private.h @@ -211,16 +211,17 @@ struct labcomm2014_decoder { int (*ioctl)(struct labcomm2014_decoder *d, const struct labcomm2014_signature *s, uint32_t ioctl_action, va_list args); - const struct labcomm2014_signature *(*index_to_signature)( struct labcomm2014_decoder *decoder, int index); - + const struct labcomm2014_signature *(*get_ref_signature)( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature); }; #if __BYTE_ORDER == __LITTLE_ENDIAN #define LABCOMM_DECODE(name, type) \ - static inline type labcomm2014_read_##name(struct labcomm2014_reader *r) { \ + static inline type labcomm2014_read_##name(struct labcomm2014_reader *r) { \ type result; int i; \ for (i = sizeof(type) - 1 ; i >= 0 ; i--) { \ if (r->pos >= r->count) { \ @@ -393,6 +394,9 @@ struct labcomm2014_encoder { uint32_t ioctl_action, va_list args); int (*signature_to_index)(struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature); + const struct labcomm2014_signature *(*ref_get)( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature); }; diff --git a/lib/c/2014/labcomm2014_renaming.c b/lib/c/2014/labcomm2014_renaming.c index aeaee53..332c638 100644 --- a/lib/c/2014/labcomm2014_renaming.c +++ b/lib/c/2014/labcomm2014_renaming.c @@ -22,7 +22,6 @@ #include "labcomm2014_renaming.h" #include <string.h> -#include <stdio.h> char *labcomm2014_renaming_prefix(struct labcomm2014_memory *m, char *name, void *context) @@ -36,7 +35,6 @@ char *labcomm2014_renaming_prefix(struct labcomm2014_memory *m, strcpy(result, prefix); strcat(result, name); } - fprintf(stderr, "%s + %s -> %s\n", prefix, name, result); return result; } diff --git a/lib/c/2014/labcomm2014_renaming_decoder.c b/lib/c/2014/labcomm2014_renaming_decoder.c index a7f8c1d..9a37d7a 100644 --- a/lib/c/2014/labcomm2014_renaming_decoder.c +++ b/lib/c/2014/labcomm2014_renaming_decoder.c @@ -155,6 +155,21 @@ static const struct labcomm2014_signature *do_index_to_signature( return id->next->index_to_signature(id->next, index); } +static const struct labcomm2014_signature *do_get_ref_signature( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature) +{ + const struct labcomm2014_signature *renamed; + struct decoder *id = d->context; + + renamed = get_renamed(d, signature); + if (renamed == NULL) { + return id->next->get_ref_signature(id->next, signature); + } else { + return id->next->get_ref_signature(id->next, renamed); + } +} + static void do_free(struct labcomm2014_decoder *d) { struct decoder *id = d->context; @@ -196,6 +211,7 @@ struct labcomm2014_decoder *labcomm2014_renaming_decoder_new( result->decoder.ref_register = do_ref_register; result->decoder.ioctl = do_ioctl; result->decoder.index_to_signature = do_index_to_signature; + result->decoder.get_ref_signature = do_get_ref_signature; result->next = d; result->rename = rename; result->context = context; diff --git a/lib/c/2014/labcomm2014_renaming_encoder.c b/lib/c/2014/labcomm2014_renaming_encoder.c index 414702e..cd44c1c 100644 --- a/lib/c/2014/labcomm2014_renaming_encoder.c +++ b/lib/c/2014/labcomm2014_renaming_encoder.c @@ -179,6 +179,21 @@ static int do_signature_to_index(struct labcomm2014_encoder *e, return ie->next->signature_to_index(ie->next, get_renamed(e, signature)); } +static const struct labcomm2014_signature *do_ref_get( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) +{ + const struct labcomm2014_signature *renamed; + struct encoder *ie = e->context; + + renamed = get_renamed(e, signature); + if (renamed == NULL) { + return ie->next->ref_get(ie->next, signature); + } else { + return ie->next->ref_get(ie->next, renamed); + } +} + static void do_free(struct labcomm2014_encoder *e) { struct encoder *ie = e->context; @@ -222,6 +237,7 @@ struct labcomm2014_encoder *labcomm2014_renaming_encoder_new( result->encoder.encode = do_encode; result->encoder.ioctl = do_ioctl; result->encoder.signature_to_index = do_signature_to_index; + result->encoder.ref_get = do_ref_get; result->next = e; result->rename = rename; result->context = context; -- GitLab