Commit 64b9582f authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Cleanup of error handling.

parent 7d027c06
......@@ -88,39 +88,28 @@ struct labcomm_decoder_context {
void labcomm_register_error_handler_encoder(struct labcomm_encoder *encoder, labcomm_error_handler_callback callback)
{
encoder->on_error = callback;
encoder->writer->on_error = callback;
}
void labcomm_register_error_handler_decoder(struct labcomm_decoder *decoder, labcomm_error_handler_callback callback)
{
decoder->on_error = callback;
decoder->reader->on_error = callback;
}
/* Error strings. _must_ be the same order as in enum labcomm_error */
const char *labcomm_error_strings[] = {
"Enum begin guard. DO NO use this as an error.",
"Encoder has no registration for this signature.",
"Encoder is missing do_register",
"Encoder is missing do_encode",
"The labcomm buffer is full and it.",
"Decoder is missing do_register",
"Decoder is missing do_decode_one",
"Decoder: Unknown datatype",
"Decoder: index mismatch",
"Decoder: type not found",
"This function is not yet implemented.",
"User defined error.",
"Could not allocate memory.",
"Enum end guard. DO NO use this as an error."
}
static const char *labcomm_error_string[] = {
#define LABCOMM_ERROR(name, description) description ,
#include "labcomm_error.h"
#undef LABCOMM_ERROR
};
static const int labcomm_error_string_count = (sizeof(labcomm_error_string) /
sizeof(labcomm_error_string[0]));
const char *labcomm_error_get_str(enum labcomm_error error_id)
{
const char *error_str = NULL;
// Check if this is a known error ID.
if (error_id >= LABCOMM_ERROR_ENUM_BEGIN_GUARD && error_id <= LABCOMM_ERROR_ENUM_END_GUARD) {
error_str = labcomm_error_strings[error_id];
if (0 <= error_id && error_id < labcomm_error_string_count) {
error_str = labcomm_error_string[error_id];
}
return error_str;
}
......@@ -380,7 +369,6 @@ struct labcomm_encoder *labcomm_encoder_new(
result->writer->error = 0;
result->lock.action = lock;
result->lock.context = lock_context;
result->writer->on_error = on_error_fprintf;
result->on_error = on_error_fprintf;
result->writer->action->alloc(result->writer, LABCOMM_VERSION);
}
......@@ -567,7 +555,6 @@ struct labcomm_decoder *labcomm_decoder_new(
result->reader->data_size = 0;
result->reader->count = 0;
result->reader->pos = 0;
result->reader->on_error = on_error_fprintf;
result->lock.action = lock;
result->lock.context = lock_context;
result->on_error = on_error_fprintf;
......@@ -620,7 +607,6 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
.pos = 0,
.error = 0,
.action = labcomm_dynamic_buffer_writer_action,
.on_error = NULL
};
struct labcomm_signature signature;
struct labcomm_sample_entry *entry = NULL;
......
......@@ -3,6 +3,7 @@
#include <stdarg.h>
#include <unistd.h>
#include <labcomm_error.h>
/* Forward declaration */
struct labcomm_encoder;
......@@ -24,27 +25,6 @@ struct labcomm_signature {
* Error handling.
*/
/* Error IDs */
enum labcomm_error {
LABCOMM_ERROR_ENUM_BEGIN_GUARD, // _must_ be the first enum element. labcomm_error_get_str() depends on this.
LABCOMM_ERROR_ENC_NO_REG_SIGNATURE,
LABCOMM_ERROR_ENC_MISSING_DO_REG,
LABCOMM_ERROR_ENC_MISSING_DO_ENCODE,
LABCOMM_ERROR_ENC_BUF_FULL,
LABCOMM_ERROR_DEC_MISSING_DO_REG,
LABCOMM_ERROR_DEC_MISSING_DO_DECODE_ONE,
LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE,
LABCOMM_ERROR_DEC_INDEX_MISMATCH,
LABCOMM_ERROR_DEC_TYPE_NOT_FOUND,
LABCOMM_ERROR_UNIMPLEMENTED_FUNC,
LABCOMM_ERROR_MEMORY,
LABCOMM_ERROR_USER_DEF,
LABCOMM_ERROR_ENUM_END_GUARD // _must_ be the last enum element. labcomm_error_get_str() depends on this.
};
/* Error strings. _must_ be the same order as in enum labcomm_error */
extern const char *labcomm_error_strings[];
/* The callback prototype for error handling.
* First parameter is the error ID.
* The second paramters is the number of va_args that comes after this
......@@ -79,6 +59,7 @@ void labcomm_decoder_register_new_datatype_handler(struct labcomm_decoder *d,
/*
* Locking support (optional)
*/
struct labcomm_lock;
struct labcomm_lock_action {
int (*alloc)(void *context);
......
......@@ -71,7 +71,6 @@ struct labcomm_reader {
int count;
int pos;
int error;
labcomm_error_handler_callback on_error;
};
......@@ -201,7 +200,6 @@ struct labcomm_writer {
int count;
int pos;
int error;
labcomm_error_handler_callback on_error;
};
void labcomm_internal_encoder_register(
......
......@@ -15,7 +15,6 @@ static struct labcomm_writer writer = {
.pos = 0,
.error = 0,
.action = NULL,
.on_error = NULL,
};
static struct labcomm_reader reader = {
......@@ -25,7 +24,6 @@ static struct labcomm_reader reader = {
.count = 0,
.pos = 0,
.action = NULL,
.on_error = NULL,
};
typedef uint32_t packed32;
......
......@@ -118,7 +118,6 @@ static struct labcomm_writer buffer_writer = {
.pos = 0,
.error = 0,
.action = &writer_action,
.on_error = NULL,
};
void dump_encoder(struct labcomm_encoder *encoder)
......
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