This example demonstrates how to configure the DiCE API.
- Error handling
Detecting failures depends on the particular method in question.
Some methods indicate their success or failure by an integral return value, e.g., mi::neuraylib::INeuray::start(), as already seen in the previous example. The general rule is that 0 indicates success, and all other values indicate failure.
Methods returning interface pointers indicate failure by a NULL
pointer. Therefore you should check returned pointers for NULL
. If you use the provided handle class, you can do so by calling mi::base::Handle::is_valid_interface().
In this and the following examples we use a helper macro called check_success()
to check for errors. If the condition is not true, the macro just prints an error message and exits. Of course, in real code proper error-handling needs to be done. This has been omitted in the examples for simplicity.
- Configuration of the DiCE API
The behavior of the DiCE library can be configured through several interfaces which can be obtained from mi::neuraylib::INeuray::get_api_component(). See Configuration Interfaces for a list of these interfaces. Almost all of the configuration has to happen before DiCE has been started.
In this example we demonstrate how to configure the logging behavior of DiCE.
You can customize the logging behavior of DiCE by providing your own logging object. This object has to implement the mi::base::ILogger interface. A very minimal implementation that prints all messages to stderr
is shown in this example. A similar implementation is used by default if you do not provide your own implementation.
#include "example_shared.h"
{
public:
void message(
{
const char* log_level = get_log_level( level);
fprintf( stderr, "Log level = '%s', module:category = '%s', message = '%s'\n",
log_level, module_category, message);
exit( EXIT_FAILURE);
}
private:
{
switch( level) {
return "FATAL";
return "ERROR";
return "WARNING";
return "INFO";
return "VERBOSE";
return "DEBUG";
default:
return "";
}
}
};
int main( int , char* [])
{
check_success( neuray.is_valid_interface());
{
logging_configuration->set_receiving_logger( logger.get());
check_start_success( result);
}
check_success( neuray->shutdown() == 0);
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
This interface is used for configuring the logging for the DiCE library.
Definition: ilogging_configuration.h:68
@ STARTED
The library or the cluster is ready for operation.
Definition: ineuray.h:98
@ SHUTDOWN
The library or the cluster has been shut down.
Definition: ineuray.h:102
@ PRE_STARTING
The library or the cluster has not yet been started.
Definition: ineuray.h:94
Message_severity
Constants for possible message severities.
Definition: enums.h:31
@ MESSAGE_SEVERITY_FATAL
A fatal error has occurred.
Definition: enums.h:33
@ MESSAGE_SEVERITY_DEBUG
This is debug message.
Definition: enums.h:43
@ MESSAGE_SEVERITY_WARNING
A warning has occurred.
Definition: enums.h:37
@ MESSAGE_SEVERITY_INFO
This is a normal operational message.
Definition: enums.h:39
@ MESSAGE_SEVERITY_VERBOSE
This is a more verbose message.
Definition: enums.h:41
@ MESSAGE_SEVERITY_ERROR
An error has occurred.
Definition: enums.h:35
signed int Sint32
32-bit signed integer.
Definition: types.h:46
Structured details to log messages.
Definition: ilogger.h:71