Ocean
|
This class implements a messenger for information, warning or error messages. More...
Public Types | |
enum | MessageType : uint32_t { TYPE_UNDEFINED = 0u , TYPE_DEBUG , TYPE_INFORMATION , TYPE_WARNING , TYPE_ERROR } |
Definition of different message types. More... | |
enum | MessageOutput : uint32_t { OUTPUT_DISCARDED = 0u , OUTPUT_STANDARD = 1u << 0u , OUTPUT_QUEUED = 1u << 1u , OUTPUT_DEBUG_WINDOW = 1u << 2u , OUTPUT_FILE = 1u << 3u , OUTPUT_STREAM = 1u << 4u , OUTPUT_MAINTENANCE = 1u << 5u } |
Definition of different message output types. More... | |
Public Member Functions | |
void | push (const MessageType type, std::string &&location, std::string &&message) |
Pushes a new message into the message queue. More... | |
bool | popDebug (std::string &location, std::string &message, bool *isNew=nullptr) |
Pops the first debug message from the message queue. More... | |
bool | popInformation (std::string &location, std::string &message, bool *isNew=nullptr) |
Pops the first information message from the message queue. More... | |
bool | popWarning (std::string &location, std::string &message, bool *isNew=nullptr) |
Pops the first warning message from the message queue. More... | |
bool | popError (std::string &location, std::string &message, bool *isNew=nullptr) |
Pops the first error message from the message queue. More... | |
bool | popMessage (MessageType &type, std::string &location, std::string &message, bool *isNew=nullptr) |
Pops any first message available of a given type or of any type. More... | |
std::string | popMessage (const MessageType type=TYPE_UNDEFINED, bool *isNew=nullptr) |
Pops the oldest message available of a specified type. More... | |
bool | setOutputType (const MessageOutput type) |
Sets the output type of the messenger. More... | |
bool | setFileOutput (const std::string &filename) |
Sets the message output to a file. More... | |
bool | setOutputStream (std::ostream &stream) |
Sets the message output to an output stream. More... | |
void | setIntegrateDateTime (const bool state) |
Enables or disables the integration of local date/time information into the location information of messages. More... | |
void | flush (std::ostream &stream) |
Flushes the current message stack to a given output stream, the output type is unchanged. More... | |
void | clear () |
Clears all message queues. More... | |
void | clearInformations () |
Clears the information message queue. More... | |
void | clearWarnings () |
Clears the warning message queue. More... | |
void | clearErrors () |
Clears the error message queue. More... | |
MessageOutput | outputType () const |
Returns the output type of the messenger. More... | |
size_t | informations () const |
Returns the number of waiting information messages. More... | |
size_t | warnings () const |
Returns the number of waiting information messages. More... | |
size_t | errors () const |
Returns the number of waiting information messages. More... | |
bool | integrateDateTime () const |
Returns whether the date/time integration is activated. More... | |
bool | empty () const |
Returns whether no message exists. More... | |
Static Public Member Functions | |
static void | writeToDebugOutput (const std::string &message) |
Writes a message to the most suitable debug output of the current platform. More... | |
static constexpr bool | isActive () |
Returns whether the messenger is active on this build. More... | |
static constexpr bool | isDebugBuild () |
Returns whether the messenger is used on a debug build. More... | |
Static Public Member Functions inherited from Ocean::Singleton< Messenger > | |
static Messenger & | get () |
Returns a reference to the unique object. More... | |
Protected Types | |
typedef std::pair< std::string, std::string > | Message |
Definition of a message. More... | |
typedef std::queue< Message > | MessageQueue |
Definition of a message queue. More... | |
Protected Member Functions | |
Messenger () | |
Creates a new messenger object queuing all messages as default. More... | |
~Messenger () | |
Destructs a messenger object. More... | |
Protected Member Functions inherited from Ocean::Singleton< Messenger > | |
Singleton ()=default | |
Default constructor. More... | |
Static Protected Member Functions | |
static void | writeMessageToDebugWindowApple (const std::string &message) |
Write message to Apple-specific log facility. More... | |
Protected Attributes | |
MessageOutput | outputType_ = OUTPUT_STANDARD |
Message output type. More... | |
MessageQueue | debugMessageQueue_ |
Debug message queue. More... | |
std::string | lastDebugMessage_ |
Last debug message. More... | |
MessageQueue | informationMessageQueue_ |
Information message queue. More... | |
MessageQueue | warningMessageQueue_ |
Warning message queue. More... | |
MessageQueue | errorMessageQueue_ |
Error message queue. More... | |
std::string | lastInformationMessage_ |
Last information message. More... | |
std::string | lastWarningMessage_ |
Last warning message. More... | |
std::string | lastErrorMessage_ |
Last error message. More... | |
std::ofstream | fileOutputStream_ |
File output stream. More... | |
std::ostream * | outputStream_ = nullptr |
Explicit output stream, if any. More... | |
bool | integrateDateTime_ = false |
Date and time integration state. More... | |
Lock | lock_ |
Messenger lock. More... | |
Static Protected Attributes | |
static constexpr unsigned int | maxMessages_ = 5000u |
Maximum number of messages. More... | |
Friends | |
class | Singleton< Messenger > |
Friend class. More... | |
This class implements a messenger for information, warning or error messages.
Posted messages are stored in internal message queues or referred to a specified output file.
Therefore, applications interested in live messaging have to pop the queued messages recurrently.
There different message types are supported dividing all messages related to their magnitude: Error messages hold critical informations which influence the major program progress directly.
Warning messages hold informations which can influence minor program progresses, however they are not critical.
Information messages hold interesting informations for the user only.
Meaning that error messages should be informed to the user immediately, instead information messages can be informed to the user.
Additionally, each message can provide a location specifying e.g. the sender module.
Applications interested in messages use the Messenger object implemented as singleton to receive messages. Modules use the MessageObject objects to post new messages.
Three basic message types are defined: error, warning and info.
Tutorial explaining the usage on application side:
Tutorial explaining the usage on module side:
|
protected |
Definition of a message.
|
protected |
Definition of a message queue.
enum Ocean::Messenger::MessageOutput : uint32_t |
Definition of different message output types.
enum Ocean::Messenger::MessageType : uint32_t |
|
protected |
Creates a new messenger object queuing all messages as default.
|
protected |
Destructs a messenger object.
void Ocean::Messenger::clear | ( | ) |
Clears all message queues.
void Ocean::Messenger::clearErrors | ( | ) |
Clears the error message queue.
void Ocean::Messenger::clearInformations | ( | ) |
Clears the information message queue.
void Ocean::Messenger::clearWarnings | ( | ) |
Clears the warning message queue.
|
inline |
Returns whether no message exists.
|
inline |
Returns the number of waiting information messages.
void Ocean::Messenger::flush | ( | std::ostream & | stream | ) |
Flushes the current message stack to a given output stream, the output type is unchanged.
stream | Output stream |
|
inline |
Returns the number of waiting information messages.
|
inline |
Returns whether the date/time integration is activated.
By default the date time integration is deactivated.
|
staticconstexpr |
Returns whether the messenger is active on this build.
|
staticconstexpr |
Returns whether the messenger is used on a debug build.
|
inline |
Returns the output type of the messenger.
bool Ocean::Messenger::popDebug | ( | std::string & | location, |
std::string & | message, | ||
bool * | isNew = nullptr |
||
) |
Pops the first debug message from the message queue.
location | The resulting location of the message |
message | The resulting text message |
isNew | Optional returning flag determining whether this message is not identical to the last one |
bool Ocean::Messenger::popError | ( | std::string & | location, |
std::string & | message, | ||
bool * | isNew = nullptr |
||
) |
Pops the first error message from the message queue.
location | The resulting location of the message |
message | The resulting text message |
isNew | Returning flag determining whether this message is not identical to the last one |
bool Ocean::Messenger::popInformation | ( | std::string & | location, |
std::string & | message, | ||
bool * | isNew = nullptr |
||
) |
Pops the first information message from the message queue.
location | The resulting location of the message |
message | The resulting text message |
isNew | Optional returning flag determining whether this message is not identical to the last one |
std::string Ocean::Messenger::popMessage | ( | const MessageType | type = TYPE_UNDEFINED , |
bool * | isNew = nullptr |
||
) |
Pops the oldest message available of a specified type.
type | The type of the message to return, TYPE_UNDEFINED to return a message with any type |
isNew | Optional resulting state determining whether the message is not identical to the previous one |
bool Ocean::Messenger::popMessage | ( | MessageType & | type, |
std::string & | location, | ||
std::string & | message, | ||
bool * | isNew = nullptr |
||
) |
Pops any first message available of a given type or of any type.
If several messages with different types are available and an undefined type is defined the pop order is: errors, warnings, informations.
type | The type of the message to pop, may be TYPE_UNDEFINED to return any message while 'type' will be set to the type of the message which is returned |
location | The resulting location of the message |
message | The resulting text message |
isNew | Optional returning flag determining whether this message is not identical to the previous one |
bool Ocean::Messenger::popWarning | ( | std::string & | location, |
std::string & | message, | ||
bool * | isNew = nullptr |
||
) |
Pops the first warning message from the message queue.
location | The resulting location of the message |
message | The resulting test message |
isNew | Returning flag determining whether this message is not identical to the last one |
void Ocean::Messenger::push | ( | const MessageType | type, |
std::string && | location, | ||
std::string && | message | ||
) |
Pushes a new message into the message queue.
type | The type of the message |
location | The location of the message |
message | The text message |
bool Ocean::Messenger::setFileOutput | ( | const std::string & | filename | ) |
Sets the message output to a file.
All messages will be redirected to the specified file instead of inserted into the message queue.
filename | Name of the output file, use an empty filename to disable file output |
void Ocean::Messenger::setIntegrateDateTime | ( | const bool | state | ) |
Enables or disables the integration of local date/time information into the location information of messages.
state | True, to enable the integration of the date/time information |
bool Ocean::Messenger::setOutputStream | ( | std::ostream & | stream | ) |
Sets the message output to an output stream.
All messages will be redirected to the specified output stream instead of inserted into the message queue.
stream | Output stream |
bool Ocean::Messenger::setOutputType | ( | const MessageOutput | type | ) |
Sets the output type of the messenger.
type | Output type to set |
|
inline |
Returns the number of waiting information messages.
|
staticprotected |
Write message to Apple-specific log facility.
message | The message to be written into NSLog |
|
static |
Writes a message to the most suitable debug output of the current platform.
This function is just a simple way to create a debug message without needing to configure the Messenger.
message | The message to write |
|
protected |
Debug message queue.
|
protected |
Error message queue.
|
protected |
File output stream.
|
protected |
Information message queue.
|
protected |
Date and time integration state.
|
protected |
Last debug message.
|
protected |
Last error message.
|
protected |
Last information message.
|
protected |
Last warning message.
|
staticconstexprprotected |
Maximum number of messages.
|
protected |
Explicit output stream, if any.
|
protected |
Message output type.
|
protected |
Warning message queue.