Commit 74c192aa authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

refactored c decoder towards shared registries

parent f1cf1aa5
......@@ -299,6 +299,54 @@ out:
return result;
}
static labcomm_decoder_function lookup_h(struct labcomm_decoder *d,
struct call_handler_context *wrap,
int remote_index,
int **local_index)
{
labcomm_decoder_function do_decode = NULL;
labcomm_scheduler_data_lock(d->scheduler);
*local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
if (**local_index != 0) {
struct sample_entry *entry;
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry,
**local_index);
wrap->local_index = **local_index;
wrap->signature = entry->signature;
wrap->handler = entry->handler;
wrap->context = entry->context;
do_decode = entry->decode;
}
labcomm_scheduler_data_unlock(d->scheduler);
return do_decode;
}
static int decode_and_handle(struct labcomm_decoder *d, int remote_index)
{
int result;
int *local_index;
struct call_handler_context wrap = {
.reader = d->reader,
.remote_index = remote_index,
.signature = NULL,
.handler = NULL,
.context = NULL,
};
labcomm_decoder_function do_decode = lookup_h(d, &wrap, remote_index, &local_index);
result = *local_index;
if (do_decode) {
do_decode(d->reader, call_handler, &wrap);
if (d->reader->error < 0) {
result = d->reader->error;
}
} else {
result = -ENOENT;
}
return result;
}
int labcomm_decoder_decode_one(struct labcomm_decoder *d)
{
int result, remote_index, length;
......@@ -328,42 +376,7 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
//result = remote_index;
result = decoder_skip(d, length, remote_index);
} else {
int *local_index;
struct call_handler_context wrap = {
.reader = d->reader,
.remote_index = remote_index,
.signature = NULL,
.handler = NULL,
.context = NULL,
};
labcomm_decoder_function do_decode = NULL;
labcomm_scheduler_data_lock(d->scheduler);
local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
if (*local_index != 0) {
struct sample_entry *entry;
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry,
*local_index);
wrap.local_index = *local_index;
wrap.signature = entry->signature;
wrap.handler = entry->handler;
wrap.context = entry->context;
do_decode = entry->decode;
result = *local_index;
}
labcomm_scheduler_data_unlock(d->scheduler);
if (do_decode) {
do_decode(d->reader, call_handler, &wrap);
if (d->reader->error < 0) {
result = d->reader->error;
}
} else {
result = -ENOENT;
}
result = decode_and_handle(d, remote_index);
}
out:
return result;
......
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