Skip to content
Snippets Groups Projects
Commit f1cf1aa5 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

refactored c pragma. still TODO: share decoder registry

parent 5340978e
Branches
No related tags found
No related merge requests found
......@@ -117,7 +117,7 @@ void labcomm_decoder_free(
struct labcomm_decoder *decoder);
int labcomm_decoder_decode_one(
struct labcomm_decoder *decoder);
void labcomm_decoder_run(
int labcomm_decoder_run(
struct labcomm_decoder *decoder);
/* See labcomm_ioctl.h for predefined ioctl_action values */
......@@ -137,12 +137,12 @@ struct labcomm_pragma_handler {
int foo;
};
typedef int (*labcomm_handle_pragma_callback)(
typedef int (*labcomm_pragma_handler_callback)(
struct labcomm_decoder *decoder,
char *pragma_type);
void labcomm_decoder_register_pragma_handler(struct labcomm_decoder *d,
labcomm_handle_pragma_callback pragma_dispatcher);
labcomm_pragma_handler_callback pragma_dispatcher);
/*
* Encoder
......
......@@ -35,6 +35,17 @@ struct sample_entry {
void *context;
};
//XXX move to pragma.ch
//int default_pragma_handler(struct labcomm_decoder *d, char *pragma_type);
int default_pragma_handler(struct labcomm_decoder *d, char *pragma_type)
{
printf("Default pragma handler got pragma: %s\n", pragma_type);
int res = labcomm_decoder_run(d);
printf("... %d:%s\n",res,strerror(-res));
return LABCOMM_PRAGMA;
}
struct labcomm_decoder {
struct labcomm_reader *reader;
int reader_allocated;
......@@ -46,6 +57,7 @@ struct labcomm_decoder {
labcomm_handle_new_datatype_callback on_new_datatype;
LABCOMM_SIGNATURE_ARRAY_DEF(local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local, int);
labcomm_pragma_handler_callback pragma_handler;
};
struct labcomm_decoder *labcomm_decoder_new(
......@@ -73,6 +85,7 @@ struct labcomm_decoder *labcomm_decoder_new(
result->on_error = on_error_fprintf;
LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int);
result->pragma_handler = default_pragma_handler;
}
return result;
}
......@@ -253,8 +266,7 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
}
int bytes = labcomm_size_string(pragma_type);
int psize = len-bytes;
printf("got pragma: %s\n", pragma_type);
if(0 /*d->pragma_handler*/) {
if(d->pragma_handler) {
//read the entire packet to a buffer and then run
// decode on that through a bytearray_reader.
// (to easily handle multiple labcomm packets in one metadata packet)
......@@ -267,18 +279,19 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
goto out;
}
}
printf("read %d bytes\n", psize);
//printf("read %d bytes\n", psize);
//TODO: add wrapped decoders, and create pragma decoder that does not
// expect a version packet
struct labcomm_reader *pr = labcomm_bytearray_reader_new(
d->reader->memory, pragma_data, psize);
struct labcomm_decoder *pd = labcomm_decoder_new(
pr, d->error, d->memory, d->scheduler);
/* d->prama_handler(pd, ptype, plen); */
labcomm_decoder_run(pd);
pd->version_ok = 1;
printf("calling pragma_handler\n");
result = d->pragma_handler(pd, pragma_type);
printf("returned from pragma_handler\n");
internal_labcomm_decoder_free(pd);
result = 0;
} else {
result = decoder_skip(d, psize, LABCOMM_PRAGMA);
}
......@@ -356,10 +369,12 @@ out:
return result;
}
void labcomm_decoder_run(struct labcomm_decoder *d)
int labcomm_decoder_run(struct labcomm_decoder *d)
{
while (labcomm_decoder_decode_one(d) > 0) {
int res;
while ( (res=labcomm_decoder_decode_one(d)) > 0) {
}
return res;
}
int labcomm_decoder_ioctl(struct labcomm_decoder *d,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment