Commit 9d24c494 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Renaming decoder implemented

parent 48df451b
......@@ -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
......@@ -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
......@@ -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);
}
......@@ -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);
}
......@@ -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);
};
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment