MeVisLab Toolbox Reference
|
Class to handle all ML debug prints, errors, warnings, and information. More...
#include <mlErrorOutput.h>
Public Types | |
typedef void | ErrorOutputCB(void *usrData, const char *errStr, const ErrorOutputInfos &infos) |
Function type which can be passed to the ErrorOutput class. | |
typedef char * | DumpCB(const void *dumpObj, const RuntimeType *dumpObjRT) |
Definition of a callback type which can be registered at the ML C-API. | |
Public Member Functions | |
ErrorOutput () | |
Constructor. | |
~ErrorOutput () | |
Destructor. | |
void | reset () |
Resets instance to construction state. | |
Initialization and destruction of the ErrorOutput class. | |
void | init () |
Only to force an access to instances of this class to make the objects automatically initialized during dll initialization to be sure that error handler exists surely before other global objects. | |
void | destroy () |
Destroys global settings; to be called during ML or mlUtils destruction, not to be called by applications. | |
The way how the ML shall handle messages. | |
For each message type an ML termination mode can be defined. Default is continue for all message types except of fatal errors where an abort is used in debug and in release mode. | |
void | setTerminationType (MLMessageType level, MLTerminator term) |
Sets the way how the ML shall handle a specific message type, note that ML_ALL_MESSAGES is not a valid parameter. | |
MLTerminator | getTerminationType (MLMessageType level) const |
Return the way how the ML shall handle messages. | |
Specifies which kinds of messages are handled y the ErrorOutput class. | |
void | setMessageFilter (MLuint32 messageType) |
Sets messages to be handled by MLErrorOutput as set bits in messageType. | |
MLuint32 | getMessageFilter () |
Returns the bit mask specifying the message filter which is composed from binary ORed MLMessageTypes enums. | |
Handling/setting/getting runtime dump callbacks. | |
void | setDumpCB (DumpCB *dumpCB) |
Registers a dump function dumpCB which will be called by the ML to dump object structures e.g., to a log file or something like that. | |
DumpCB * | getDumpCB () const |
Returns the currently registered dump callback. Default is NULL. | |
Enables/Disables/Queries whether debug printing is enabled. | |
If Otherwise only selective debug prints are passed to the output. By default debug printing is off. Note that during ML initialization the variable ML_DEBUG_ALL is evaluated which might lead to enabled full debug printing. | |
void | setFullDebuggingOn (bool on) |
Enables/disables full debugging by passing true / false as on . | |
bool | isFullDebuggingOn () const |
Returns true if full debugging is enabled, otherwise false . | |
Management of callback functions for (error) message handling. | |
void | addErrorOutputCB (void *userData, ErrorOutputCB *callback) |
Registers a function called when any message is sent MLErrorOutput. | |
void | removeErrorOutputCB (void *userData, ErrorOutputCB *callback) |
Removes error print function from function list if both parameters are identical with their corresponding registered versions. | |
bool | hasErrorOutputCB (void *userData, ErrorOutputCB *callback) const |
Returns true if the output function is registered, i.e., if both parameters are identical with their corresponding registered versions otherwise false is returned. | |
void | removeAllErrorOutputCBs () |
Removes all registered error print functions from list. | |
size_t | getNumOutputCBs () const |
Returns the number of registered callbacks. | |
void | addDebugEnvName (const std::string &envName) |
Adds debug environment string whose information shall be printed. | |
void | removeDebugEnvName (const std::string &envName) |
Removes a registered debug environment string whose information shall not be printed any more. | |
bool | hasDebugEnvName (const std::string &envName) const |
Returns true if the debug environment name exists. | |
const std::vector< std::string > & | getDebugEnvNames () const |
Returns a list of debug environment names. | |
void | removeAllDebugEnvNames () |
Removes all registered debug environment strings from list. | |
size_t | getNumDebugEnvNames () const |
Return number of registered debug environment names. | |
Sending messages to Visual Studio. | |
void | setOutputMessagesInVisualStudio (bool flag) |
Sets if messages should be printed in Visual Studio (turned on by default in debug mode). | |
bool | shouldOutputMessagesInVisualStudio () const |
Returns wheter messages should be printed in Visual Studio. | |
Sending messages to std::cout or std::cerr. | |
bool | areMessagesSentToCout () const |
Messages are only sent to std::cout if this flag is true. | |
void | sendMessagesToCout (bool on) |
If on is passed as true , message sending to std::cout is enabled. | |
bool | areMessagesSentToCerr () const |
Messages are only sent to std::cerr if this flag is true. | |
void | sendMessagesToCerr (bool on) |
If on is passed as true message sending to std::cerr is enabled. | |
Specification of trace information outputs on errors. | |
MLuint32 | getMaxNumTraceListDumps () const |
Reutrns the maximum number of trace list entries to be shown on fatal error outputs. | |
void | setMaxNumTraceListDumps (MLGlobalTraceBufferType num) |
Sets the maximum number of trace list entries to be shown on fatal error outputs. | |
MLuint32 | getMaxNumTraceStackDumps () const |
Returns the maximum number of trace stack entries to be shown on fatal error outputs. | |
void | setMaxNumTraceStackDumps (MLGlobalTraceBufferType num) |
Sets the maximum number of trace stack entries to be shown on fatal error outputs. | |
MLuint32 | getTraceDumpMessageBits () const |
Returns the bit mask describing all message types which shall lead to a trace list and trace stack dump. | |
void | setTraceDumpMessageBits (MLuint32 bitMask) |
Sets the bit mask describing all message types which shall lead to a trace list and trace stack dump. | |
HIDDEN STUFF WHICH IS REQUIRED TO BE PUBLIC FOR MACRO USAGE | |
The following functions are called by macros and therefore they need to be public. Nevertheless these functions should not be called directly by any user or application. | |
void | printAndNotify (MLMessageType messageType, const std::string &libraryPrefix, const std::string &fPrefix, const std::string &functionName, const std::string &reason, const std::string &handling="", const std::string &file="", int line=-1, const void *dumpObj=nullptr, const RuntimeType *dumpObjRT=nullptr, MLErrorCode errCode=ML_RESULT_OK) const |
Core error printing function used by all other functions. | |
void | printAndNotify (MLMessageType messageType, const std::string &libraryPrefix, const std::string &fPrefix, const std::string &functionName, MLErrorCode reason, const std::string &handling="", const std::string &file="", int line=-1, const void *dumpObj=nullptr, const RuntimeType *dumpObjRT=nullptr) const |
Like the other printAndNotify() function with the difference that reason is an MLErrorCode which is automatically translated to a string so that it is not needed to pass it manually as last parameter. | |
void | handleDebugPrint (const std::string &envVar, const std::string &libraryPrefix, std::stringstream &reason, const char *file, int line) const |
Function called from mlDebugPrint. | |
void | handleDebugPrint (const std::string &envVar, const std::string &libraryPrefix, const char *reason, const char *file, int line) const |
Function called from mlDebugPrint. | |
Protected Member Functions | |
ErrorOutput (const ErrorOutput &errorOutput) | |
Copy constructor, only to be used by state class of ML. | |
ErrorOutput & | operator= (const ErrorOutput &errorOutput) |
Assignment operator, only to be used by state class of ML. | |
Friends | |
class | ml::State |
Allows access to ErrorOutput only to save/restore state of ML. | |
std::ostream & | std::operator<< (std::ostream &s, const ErrorOutput &errorOutput) |
Makes stream output of ErrorOutput class a friend to provide access to internals. | |
Class to handle all ML debug prints, errors, warnings, and information.
Thread-safety: This class is not thread-safe, but offers a thread-safe printAndNotify() method. Changing the state of an ErrorOutput instance while another thread is inside printAndNotify() can lead to undesired behavior and crashes. If this proves to be a problem (currently the global ErrorOutput instance is not changed while other threads are running), the whole API should be made thread-safe.
The class ErrorOutput is the central error handle and redirection class for the ML. It contains a set of methods to print debug and trace log information, information, warnings, errors and fatal errors.
It also offers a registration mechanism where the application can register itself to be notified when an error, tracing, warning, information or debug information shall be printed or handled.
Some methods are available to control the error output of the ML. They permit registering functions to notify the application, to control a set of debug environment variables.
The ML provides a global instance MLErrorOutput of this class which is normally used. Creating an instance on your own is not necessary.
Definition at line 93 of file mlErrorOutput.h.
Definition of a callback type which can be registered at the ML C-API.
If such a callback type is registered there then it will be called after some ML (fatal) errors or warnings if the error is caused by a runtime type object. The callback then has the chance to dump the runtime typed object into a log file, to a mail or to an output channel where developers can analyze it. If any of both parameters is NULL the call shall be ignored.
dumpObj | runtimeTypeObject is a pointer to the runtime typed object causing this error and which shall be dumped and returned as string. If NULL is passed then NULL is returned. |
dumpObjRT | is the runtime type of the object which shall be dumped or NULL. If NULL is passed then NULL is returned. |
Definition at line 121 of file mlErrorOutput.h.
typedef void ml::ErrorOutput::ErrorOutputCB(void *usrData, const char *errStr, const ErrorOutputInfos &infos) |
Function type which can be passed to the ErrorOutput class.
So any application can register itself to receive debug or error information or a callback to handle a request to kill or restart the application.
Definition at line 102 of file mlErrorOutput.h.
ml::ErrorOutput::ErrorOutput | ( | ) |
Constructor.
ml::ErrorOutput::~ErrorOutput | ( | ) |
Destructor.
|
protected |
Copy constructor, only to be used by state class of ML.
Adds debug environment string whose information shall be printed.
void ml::ErrorOutput::addErrorOutputCB | ( | void * | userData, |
ErrorOutputCB * | callback ) |
Registers a function called when any message is sent MLErrorOutput.
Note that this callback may be called from any thread, not only the main thread. Thus the callback has to support being called from multiple threads. Since a lock is used internally, it is safe to assume that the callback will not be called from multiple threads at the same time.
|
inline |
Messages are only sent to std::cerr if this flag is true.
Definition at line 299 of file mlErrorOutput.h.
|
inline |
Messages are only sent to std::cout if this flag is true.
Definition at line 292 of file mlErrorOutput.h.
void ml::ErrorOutput::destroy | ( | ) |
Destroys global settings; to be called during ML or mlUtils destruction, not to be called by applications.
const std::vector< std::string > & ml::ErrorOutput::getDebugEnvNames | ( | ) | const |
Returns a list of debug environment names.
DumpCB * ml::ErrorOutput::getDumpCB | ( | ) | const |
Returns the currently registered dump callback. Default is NULL.
|
inline |
Reutrns the maximum number of trace list entries to be shown on fatal error outputs.
Definition at line 311 of file mlErrorOutput.h.
|
inline |
Returns the maximum number of trace stack entries to be shown on fatal error outputs.
Definition at line 317 of file mlErrorOutput.h.
MLuint32 ml::ErrorOutput::getMessageFilter | ( | ) |
Returns the bit mask specifying the message filter which is composed from binary ORed MLMessageTypes enums.
size_t ml::ErrorOutput::getNumDebugEnvNames | ( | ) | const |
Return number of registered debug environment names.
|
inline |
Returns the number of registered callbacks.
Definition at line 245 of file mlErrorOutput.h.
MLTerminator ml::ErrorOutput::getTerminationType | ( | MLMessageType | level | ) | const |
Return the way how the ML shall handle messages.
|
inline |
Returns the bit mask describing all message types which shall lead to a trace list and trace stack dump.
Default is ML_FATAL.
Definition at line 324 of file mlErrorOutput.h.
Returns true
if the debug environment name exists.
bool ml::ErrorOutput::hasErrorOutputCB | ( | void * | userData, |
ErrorOutputCB * | callback ) const |
Returns true
if the output function is registered, i.e., if both parameters are identical with their corresponding registered versions otherwise false
is returned.
void ml::ErrorOutput::init | ( | ) |
Only to force an access to instances of this class to make the objects automatically initialized during dll initialization to be sure that error handler exists surely before other global objects.
Does nothing special. to be called when ML or mlUtils dlls are initialized, not to be called by applications.
bool ml::ErrorOutput::isFullDebuggingOn | ( | ) | const |
Returns true
if full debugging is enabled, otherwise false
.
|
protected |
Assignment operator, only to be used by state class of ML.
void ml::ErrorOutput::removeAllDebugEnvNames | ( | ) |
Removes all registered debug environment strings from list.
Avoid using this because all registered functions from other applications or modules are also removed.
void ml::ErrorOutput::removeAllErrorOutputCBs | ( | ) |
Removes all registered error print functions from list.
Avoid using this because all registered functions from other applications or modules are also removed.
Removes a registered debug environment string whose information shall not be printed any more.
void ml::ErrorOutput::removeErrorOutputCB | ( | void * | userData, |
ErrorOutputCB * | callback ) |
Removes error print function from function list if both parameters are identical with their corresponding registered versions.
void ml::ErrorOutput::reset | ( | ) |
Resets instance to construction state.
If on
is passed as true
message sending to std::cerr is enabled.
Otherwise nothing is sent to that stream.
If on
is passed as true
, message sending to std::cout is enabled.
Otherwise nothing is sent to that stream.
Registers a dump function dumpCB which will be called by the ML to dump object structures e.g., to a log file or something like that.
Resetting the function can be done by passing NULL.
Enables/disables full debugging by passing true / false as on
.
void ml::ErrorOutput::setMaxNumTraceListDumps | ( | MLGlobalTraceBufferType | num | ) |
Sets the maximum number of trace list entries to be shown on fatal error outputs.
void ml::ErrorOutput::setMaxNumTraceStackDumps | ( | MLGlobalTraceBufferType | num | ) |
Sets the maximum number of trace stack entries to be shown on fatal error outputs.
Sets messages to be handled by MLErrorOutput as set bits in messageType.
Binary adds of MLMessageTypes are allowed e.g., messageType = ML_FATAL | ML_ERROR handles all ML_FATAL and \ ML_ERROR messages by calling the registered callback functions.
Sets if messages should be printed in Visual Studio (turned on by default in debug mode).
Definition at line 279 of file mlErrorOutput.h.
References mlrange_cast().
void ml::ErrorOutput::setTerminationType | ( | MLMessageType | level, |
MLTerminator | term ) |
Sets the way how the ML shall handle a specific message type, note that ML_ALL_MESSAGES is not a valid parameter.
Sets the bit mask describing all message types which shall lead to a trace list and trace stack dump.
Default is ML_FATAL.
|
inline |
Returns wheter messages should be printed in Visual Studio.
Definition at line 282 of file mlErrorOutput.h.
Allows access to ErrorOutput only to save/restore state of ML.
Definition at line 443 of file mlErrorOutput.h.
|
friend |
Makes stream output of ErrorOutput class a friend to provide access to internals.