ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
example_reconstructmesdk_error_handling.cpp

Content

This examples shows how correct error handling is done for the one minute example.

Each method in ReconstructMe SDK returns an error code based on reme_error_t. This can be used to determine the outcome of the last invocation. In addition, methods such as reme_context_bind_error_info provide more detailed error status information.

Besides polling for error messages, you can register a callback function for logging messages.

Boost is only used to generate examples and is not necessary for working with this SDK.

#include <boost/test/unit_test.hpp>
#include <stdio.h>
#include <stdlib.h> /* exit, EXIT_FAILURE */
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
// A simple macro that checks for any errors and exits if a method invocation failed.
#define OK(s) \
if (s != REME_ERROR_SUCCESS) { \
reme_context_print_errors(c); \
reme_context_destroy(&c); \
exit(-1); \
} \
BOOST_AUTO_TEST_CASE(error_handling_per_method) {
// Create a new context
// Compile for OpenCL device using defaults
// Create a new volume
OK(reme_volume_create(c, &v));
// ...
}
// Logging callback
void on_error(reme_log_severity_t sev, const char *msg, void *user_data) {
switch (sev) {
printf("INFO: %s\n", msg);
break;
}
printf("WARNING: %s\n", msg);
break;
}
printf("ERROR: %s\n", msg);
break;
}
}
}
BOOST_AUTO_TEST_CASE(error_handling_logging) {
// Create a new context
// Compile for OpenCL device using defaults
// ...
}
BOOST_AUTO_TEST_CASE(error_handling_critical_point) {
// Create a new context
// Compile for OpenCL device using defaults
// ...
// Access to all error messages is given through the generic options interface.
// Once the options object is bound it always reflects the current errors state.
reme_options_create(c, &errors);
int nerrors;
reme_options_get_repeated_count(c, errors, "messages", &nerrors);
printf("Number of errors %i \n", nerrors);
char msg[1024];
for (int i = 0; i < nerrors; ++i) {
reme_options_get(c, errors, "messages", msg, 1024, i);
printf("%i : %s \n", i, msg);
}
// A shortcut for the above code is to simply issue
// In order reset any errors you can invoke clear on the options object
reme_options_clear(c, errors);
reme_context_print_errors(c); // Will give you zero errors
// ...
}
BOOST_AUTO_TEST_SUITE_END()