diff --git a/lib/c/labcomm.h b/lib/c/labcomm.h index d3e177fb23a5fb669b401a20fc7398d2eaa10bd9..d67bb2a3977afb73d202c3cc912874f09a9d28c7 100644 --- a/lib/c/labcomm.h +++ b/lib/c/labcomm.h @@ -139,6 +139,7 @@ struct labcomm_pragma_handler { typedef int (*labcomm_pragma_handler_callback)( struct labcomm_decoder *decoder, + struct labcomm_decoder *registry, char *pragma_type); void labcomm_decoder_register_pragma_handler(struct labcomm_decoder *d, diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c index abf2780aaa1eba1dd5dba8652a5a1bb0444efecd..8fabdc8721fc5b60b9f5a89bfa2dd1cebc8fe210 100644 --- a/lib/c/labcomm_decoder.c +++ b/lib/c/labcomm_decoder.c @@ -35,12 +35,18 @@ struct sample_entry { void *context; }; +static int internal_decoder_run(struct labcomm_decoder *d, + struct labcomm_decoder *registry); +static int internal_decode_one(struct labcomm_decoder *d, + struct labcomm_decoder *registry); //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) +int default_pragma_handler(struct labcomm_decoder *d, + struct labcomm_decoder *registry, + char *pragma_type) { printf("Default pragma handler got pragma: %s\n", pragma_type); - int res = labcomm_decoder_run(d); + int res = internal_decoder_run(d, registry); printf("... %d:%s\n",res,strerror(-res)); return LABCOMM_PRAGMA; } @@ -121,7 +127,9 @@ void labcomm_decoder_free(struct labcomm_decoder* d) } #endif -static int decode_sample_def(struct labcomm_decoder *d, int kind) +static int decode_sample_def(struct labcomm_decoder *d, + struct labcomm_decoder *registry, + int kind) { int result; struct labcomm_signature signature, *local_signature; @@ -224,7 +232,8 @@ static void reader_alloc(struct labcomm_decoder *d) labcomm_reader_alloc(d->reader, d->reader->action_context); } } -static int decode_version(struct labcomm_decoder *d, int remote_index) +static int decode_version(struct labcomm_decoder *d, + int remote_index) { int result; char *version = labcomm_read_string(d->reader); @@ -255,7 +264,9 @@ static int decoder_skip(struct labcomm_decoder *d, int len, int tag) } return tag; } -static int decode_pragma(struct labcomm_decoder *d, int len) +static int decode_pragma(struct labcomm_decoder *d, + struct labcomm_decoder *registry, + int len) { char *pragma_type; int result; @@ -290,7 +301,7 @@ static int decode_pragma(struct labcomm_decoder *d, int len) pr, d->error, d->memory, d->scheduler); pd->version_ok = 1; printf("calling pragma_handler\n"); - result = d->pragma_handler(pd, pragma_type); + result = d->pragma_handler(pd, pd, pragma_type); printf("returned from pragma_handler\n"); internal_labcomm_decoder_free(pd); @@ -326,7 +337,9 @@ static labcomm_decoder_function lookup_h(struct labcomm_decoder *d, labcomm_scheduler_data_unlock(d->scheduler); return do_decode; } -static int decode_and_handle(struct labcomm_decoder *d, int remote_index) +static int decode_and_handle(struct labcomm_decoder *d, + struct labcomm_decoder *registry, + int remote_index) { int result; int *local_index; @@ -349,7 +362,12 @@ static int decode_and_handle(struct labcomm_decoder *d, int remote_index) } return result; } -int labcomm_decoder_decode_one(struct labcomm_decoder *d) +int labcomm_decoder_decode_one(struct labcomm_decoder *d) +{ + return internal_decode_one(d,d); +} +int internal_decode_one(struct labcomm_decoder *d, + struct labcomm_decoder *registry) { int result, remote_index, length; @@ -370,21 +388,26 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) fprintf(stderr, "No VERSION %d %d\n", remote_index, length); result = -ECONNRESET; } else if (remote_index == LABCOMM_SAMPLE_DEF) { - result = decode_sample_def(d, remote_index); + result = decode_sample_def(d, d, remote_index); } else if (remote_index == LABCOMM_PRAGMA ){ - result = decode_pragma(d, length); + result = decode_pragma(d, d, length); } else if (remote_index < LABCOMM_USER) { //fprintf(stderr, "SKIP %d %d\n", remote_index, length); //result = remote_index; result = decoder_skip(d, length, remote_index); } else { - result = decode_and_handle(d, remote_index); + result = decode_and_handle(d, d, remote_index); } out: return result; } int labcomm_decoder_run(struct labcomm_decoder *d) +{ + return internal_decoder_run(d,d); +} +int internal_decoder_run(struct labcomm_decoder *d, + struct labcomm_decoder *registry) { int res; while ( (res=labcomm_decoder_decode_one(d)) > 0) {