Commit 9b875283 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

handling for type_bindings in C

parent 17d3b32c
......@@ -21,7 +21,11 @@ static void handle_test_theSecondInt(int *v,void *context) {
}
static void handle_typedef(struct labcomm_raw_typedef *v,void *context) {
printf("Got typedef. (%d) %s\n", v->index, v->name);
printf("Got typedef. (0x%x) %s\n", v->index, v->name);
}
static void handle_type_binding(struct labcomm_type_binding *v,void *context) {
printf("Got type binding. 0x%x --> 0x%x\n", v->sample_index, v->type_index);
}
static void handle_test_twoLines(test_twoLines *v,void *context) {
......@@ -54,6 +58,7 @@ int main(int argc, char *argv[]) {
labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context);
labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
labcomm_decoder_register_labcomm_typedef(decoder, handle_typedef, context);
labcomm_decoder_register_labcomm_type_binding(decoder, handle_type_binding, context);
printf("Decoding:\n");
labcomm_decoder_run(decoder);
......
......@@ -182,6 +182,7 @@ static int decoder_skip(struct labcomm_decoder *d, int len, int tag)
return tag;
}
#ifdef OLD_TYPEDEF_DECODING_TEST_CODE
static int decode_type_binding(struct labcomm_decoder *d, int kind)
{
int result;
......@@ -199,7 +200,7 @@ static int decode_type_binding(struct labcomm_decoder *d, int kind)
out:
return result;
}
#ifdef OLD_TYPEDEF_DECODING_TEST_CODE
static int decode_type_def(struct labcomm_decoder *d, int kind){
int i, remote_index, result;
char *name;
......@@ -455,7 +456,15 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
#endif
}
} else if (remote_index == LABCOMM_TYPE_BINDING) {
result = decode_type_binding(d, LABCOMM_TYPE_BINDING);
result = decode_and_handle(d, d, remote_index);
if(result == -ENOENT) {
//No handler for type_bindings, skip
#ifdef OLD_TYPEDEF_DECODING_TEST_CODE
result = decode_type_binding(d, LABCOMM_TYPE_BINDING);
#else
result = decoder_skip(d, length, remote_index);
#endif
}
} else if (remote_index == LABCOMM_PRAGMA) {
result = decode_pragma(d, d, length);
} else if (remote_index < LABCOMM_USER) {
......@@ -550,25 +559,17 @@ static void decode_raw_typedef(
{
struct labcomm_raw_typedef v;
v.index = labcomm_read_packed32(r);
if (r->error < 0) {
goto out;
}
if (r->error < 0) { goto out; }
v.name = labcomm_read_string(r);
if (r->error < 0) {
goto free_name;
}
if (r->error < 0) { goto free_name; }
v.length = labcomm_read_packed32(r);
if (r->error < 0) {
goto free_name;
}
if (r->error < 0) { goto free_name; }
int i;
v.signature_data = labcomm_memory_alloc(r->memory, 1, v.length);
if(v.signature_data) {
for(i=0; i<v.length; i++) {
v.signature_data[i] = labcomm_read_byte(r);
if (r->error < 0) {
goto free_sig;
}
if (r->error < 0) { goto free_sig; }
}
handle(&v, context);
}
......@@ -579,7 +580,6 @@ free_name:
out:
return;
}
int labcomm_decoder_register_labcomm_typedef(
struct labcomm_decoder *d,
void (*handler)(
......@@ -598,7 +598,7 @@ int labcomm_decoder_register_labcomm_typedef(
d->local, struct sample_entry,
tag);
if (entry == NULL) { tag = -ENOMEM; goto unlock; }
entry->remote_index = LABCOMM_TYPE_DEF;
entry->remote_index = tag;
entry->signature = NULL;
entry->decode = (labcomm_decoder_function) decode_raw_typedef;
entry->handler =(labcomm_handler_function) handler;
......@@ -614,6 +614,60 @@ unlock:
return tag;
}
static void decode_type_binding(
struct labcomm_reader *r,
void (*handle)(
struct labcomm_type_binding *v,
void *context
),
void *context
)
{
struct labcomm_type_binding v;
v.sample_index = labcomm_read_packed32(r);
if (r->error < 0) { goto out; }
v.type_index = labcomm_read_packed32(r);
if (r->error < 0) { goto out; }
handle(&v, context);
out:
return;
}
int labcomm_decoder_register_labcomm_type_binding(
struct labcomm_decoder *d,
void (*handler)(
struct labcomm_type_binding *v,
void *context
),
void *context
)
{
int tag = LABCOMM_TYPE_BINDING;
struct sample_entry *entry;
int *remote_to_local;
labcomm_scheduler_data_lock(d->scheduler);
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry,
tag);
if (entry == NULL) { tag = -ENOMEM; goto unlock; }
entry->remote_index = tag;
entry->signature = NULL;
entry->decode = (labcomm_decoder_function) decode_type_binding;
entry->handler =(labcomm_handler_function) handler;
entry->context = context;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
tag);
*remote_to_local = tag;
unlock:
labcomm_scheduler_data_unlock(d->scheduler);
return tag;
}
//// End typedef handling
#endif
......
......@@ -72,12 +72,20 @@ struct labcomm_raw_typedef {
char *signature_data;
};
/* a struct for type bindings
*/
struct labcomm_type_binding {
int sample_index;
int type_index;
};
/*
* functions
*/
/* register a handler for typedefs
/* register a handler for typedefs and type bindings
*/
int labcomm_decoder_register_labcomm_typedef(
......@@ -88,6 +96,16 @@ int labcomm_decoder_register_labcomm_typedef(
),
void *context
);
int labcomm_decoder_register_labcomm_type_binding(
struct labcomm_decoder *d,
void (*handler)(
struct labcomm_type_binding *v,
void *context
),
void *context
);
/* Dump signature bytes on stdout
*/
......
Markdown is supported
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