Add manual error tracing
Error messages and function names/line numbers are traced via __func__ or __FUNCTION__, __LINE__, etc (or just "unknown" if not available). A manual stack is kept onto which these values are pushed which can then be dumped to stderr/stdout. stderr is used to report this information since no other facility appears to be provided.
This commit is contained in:
+56
-27
@@ -10,12 +10,25 @@
|
||||
#include "plugin.h"
|
||||
|
||||
|
||||
/* XDS does not provide an error callback facility, so just write to stderr for now */
|
||||
/* generally regarded as poor practice */
|
||||
#define ERROR_OUTPUT stderr
|
||||
|
||||
|
||||
static hid_t file_id = 0;
|
||||
static struct data_description_t data_desc = {0};
|
||||
static struct dataset_properties_t ds_prop = {0};
|
||||
static int *mask_buffer = NULL;
|
||||
|
||||
|
||||
void fill_info_array(int info[1024]) {
|
||||
info[0] = DLS_CUSTOMER_ID;
|
||||
info[1] = VERSION_MAJOR;
|
||||
info[2] = VERSION_MINOR;
|
||||
info[3] = VERSION_PATCH;
|
||||
info[4] = VERSION_TIMESTAMP;
|
||||
}
|
||||
|
||||
void apply_mask(int *data, int *mask, int size) {
|
||||
int *dptr, *mptr;
|
||||
dptr = data;
|
||||
@@ -39,36 +52,39 @@ void plugin_open(
|
||||
const char *filename,
|
||||
int info[1024],
|
||||
int *error_flag) {
|
||||
int err = 0;
|
||||
info[0] = DLS_CUSTOMER_ID;
|
||||
info[1] = VERSION_MAJOR;
|
||||
info[2] = VERSION_MINOR;
|
||||
info[3] = VERSION_PATCH;
|
||||
info[4] = VERSION_TIMESTAMP;
|
||||
int retval = 0;
|
||||
*error_flag = 0;
|
||||
fill_info_array(info);
|
||||
file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
if (file_id < 0) {
|
||||
/* TODO: backtrace */
|
||||
*error_flag = -4;
|
||||
return;
|
||||
char message[128] = {0};
|
||||
sprintf(message, "Could not open %.100s", filename);
|
||||
ERROR_JUMP(-4, done, message);
|
||||
}
|
||||
|
||||
err = extract_detector_info(file_id, &data_desc, &ds_prop);
|
||||
if (err < 0) {
|
||||
*error_flag = -4;
|
||||
return;
|
||||
reset_error_stack();
|
||||
retval = extract_detector_info(file_id, &data_desc, &ds_prop);
|
||||
if (retval < 0) {
|
||||
ERROR_JUMP(-4, done, "");
|
||||
}
|
||||
|
||||
mask_buffer = malloc(ds_prop.dims[1] * ds_prop.dims[2] * sizeof(int));
|
||||
if (mask_buffer) {
|
||||
err = data_desc.get_pixel_mask(&data_desc, mask_buffer);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "WARNING: Could not read pixel mask - no masking will be applied\n");
|
||||
retval = data_desc.get_pixel_mask(&data_desc, mask_buffer);
|
||||
if (retval < 0) {
|
||||
fprintf(ERROR_OUTPUT, "WARNING: Could not read pixel mask - no masking will be applied\n");
|
||||
dump_error_stack(ERROR_OUTPUT);
|
||||
free(mask_buffer);
|
||||
mask_buffer = NULL;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
|
||||
*error_flag = 0;
|
||||
done:
|
||||
*error_flag = retval;
|
||||
if (retval < 0) {
|
||||
dump_error_stack(ERROR_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,12 +96,14 @@ void plugin_get_header(
|
||||
int info[1024],
|
||||
int *error_flag) {
|
||||
int err = 0;
|
||||
int retval = 0;
|
||||
double x_pixel_size, y_pixel_size;
|
||||
reset_error_stack();
|
||||
fill_info_array(info);
|
||||
|
||||
err = data_desc.get_pixel_properties(&data_desc, &x_pixel_size, &y_pixel_size);
|
||||
if (err < 0) {
|
||||
*error_flag = -4;
|
||||
return;
|
||||
ERROR_JUMP(err, done, "Failed to retrieve pixel information");
|
||||
}
|
||||
|
||||
*nx = ds_prop.dims[2];
|
||||
@@ -94,7 +112,12 @@ void plugin_get_header(
|
||||
*number_of_frames = ds_prop.dims[0];
|
||||
*qx = (float) x_pixel_size;
|
||||
*qy = (float) y_pixel_size;
|
||||
*error_flag = 0;
|
||||
|
||||
done:
|
||||
*error_flag = retval;
|
||||
if (retval < 0) {
|
||||
dump_error_stack(ERROR_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,17 +127,23 @@ void plugin_get_data(
|
||||
int *data_array,
|
||||
int info[1024],
|
||||
int *error_flag) {
|
||||
int err = 0;
|
||||
err = data_desc.get_data_frame(&data_desc, &ds_prop, *frame_number, sizeof(int), data_array);
|
||||
if (err < 0) {
|
||||
*error_flag = -2;
|
||||
return;
|
||||
int retval = 0;
|
||||
reset_error_stack();
|
||||
fill_info_array(info);
|
||||
if (data_desc.get_data_frame(&data_desc, &ds_prop, *frame_number, sizeof(int), data_array) < 0) {
|
||||
char message[64] = {0};
|
||||
sprintf(message, "Failed to retrieve data for frame %d", *frame_number);
|
||||
ERROR_JUMP(-2, done, message);
|
||||
}
|
||||
if (mask_buffer) {
|
||||
apply_mask(data_array, mask_buffer, ds_prop.dims[1] * ds_prop.dims[2]);
|
||||
}
|
||||
*error_flag = 0;
|
||||
return;
|
||||
|
||||
done:
|
||||
*error_flag = retval;
|
||||
if (retval < 0) {
|
||||
dump_error_stack(ERROR_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user