8#ifndef META_OCEAN_BASE_MESSENGER_H
9#define META_OCEAN_BASE_MESSENGER_H
142 using Message = std::pair<std::string, std::string>;
166 bool popDebug(std::string& location, std::string& message,
bool* isNew =
nullptr);
175 bool popInformation(std::string& location, std::string& message,
bool* isNew =
nullptr);
184 bool popWarning(std::string& location, std::string& message,
bool* isNew =
nullptr);
193 bool popError(std::string& location, std::string& message,
bool* isNew =
nullptr);
295 inline size_t errors()
const;
309 inline bool empty()
const;
350#ifdef OCEAN_PLATFORM_BUILD_ANDROID
362#ifdef OCEAN_PLATFORM_BUILD_APPLE
423#ifdef OCEAN_DEACTIVATED_MESSENGER
446template <
bool tActive>
791class OCEAN_BASE_EXPORT
Log
811 template <
typename TStream>
818 template <
typename TObject,
typename =
void>
822 static constexpr bool value =
false;
830 template <
typename TObject>
831 struct ShiftOperatorChecker<TObject, std::void_t<decltype( std::declval<TStream&>() << std::declval<TObject>())>>
834 static constexpr bool value = true;
851 static inline DebugMessageObject debug();
857 static inline MessageObject info();
863 static inline MessageObject warning();
869 static inline MessageObject error();
894 template <typename T, typename TStream = MessageObject>
895 static constexpr bool isSupported();
898inline Messenger::MessageOutput Messenger::outputType() const
900 const ScopedLock scopedLock(lock_);
904inline size_t Messenger::informations() const
906 const ScopedLock scopedLock(lock_);
907 return informationMessageQueue_.size();
910inline size_t Messenger::warnings() const
912 const ScopedLock scopedLock(lock_);
913 return warningMessageQueue_.size();
916inline size_t Messenger::errors() const
918 const ScopedLock scopedLock(lock_);
919 return errorMessageQueue_.size();
922inline bool Messenger::integrateDateTime() const
924 const ScopedLock scopedLock(lock_);
925 return integrateDateTime_;
928inline bool Messenger::empty() const
930 const ScopedLock scopedLock(lock_);
931 return informationMessageQueue_.empty() && warningMessageQueue_.empty() && errorMessageQueue_.empty();
934template <bool tActive>
935inline MessageObject<tActive>::MessageObject(const MessageType type) :
941template <bool tActive>
942inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location) :
943 location_(std::move(location)),
949template <bool tActive>
950inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location, std::string&& message) :
951 message_(std::move(message)),
952 location_(std::move(location)),
958template <bool tActive>
959inline MessageObject<tActive>::~MessageObject()
961 if (!message_.empty())
963 Messenger::get().push(type_, std::move(location_), std::move(message_));
967template <bool tActive>
968inline MessageObject<tActive>& MessageObject<tActive>::newLine(const bool condition)
978template <bool tActive>
979inline MessageObject<tActive>& MessageObject<tActive>::operator<<(std::string&& message)
981 if (message_.empty())
983 message_ = std::move(message);
993template <bool tActive>
994inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const std::string& message)
1000template <bool tActive>
1001inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const char* message)
1003 if (message != nullptr)
1005 message_ += std::string(message);
1011template <bool tActive>
1012inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const double message)
1014 message_ += String::toAString(message);
1018template <bool tActive>
1019inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const float message)
1021 message_ += String::toAString(message);
1025template <bool tActive>
1026inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const int message)
1028 message_ += String::toAString(message);
1032template <bool tActive>
1033inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned int message)
1035 message_ += String::toAString(message);
1039template <bool tActive>
1040inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long message)
1042 message_ += String::toAString(message);
1046template <bool tActive>
1047inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long long message)
1049 message_ += String::toAString(message);
1053template <bool tActive>
1054inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned long long message)
1056 message_ += String::toAString(message);
1060template <bool tActive>
1061inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long unsigned int message)
1063 message_ += String::toAString(message);
1067template <bool tActive>
1068inline void MessageObject<tActive>::operator<<(const MessageObject<tActive>& messageObject)
1070 ocean_assert_and_suppress_unused(messageObject.type_ == Messenger::TYPE_UNDEFINED, messageObject);
1072 if (!message_.empty())
1074 Messenger::get().push(type_, std::string(location_), std::move(message_));
1080inline Log::DebugMessageObject Log::debug()
1082 return DebugMessageObject(Messenger::TYPE_DEBUG);
1085inline Log::MessageObject Log::info()
1087 return MessageObject(Messenger::TYPE_INFORMATION);
1090inline Log::MessageObject Log::warning()
1092 return MessageObject(Messenger::TYPE_WARNING);
1095inline Log::MessageObject Log::error()
1097 return MessageObject(Messenger::TYPE_ERROR);
1100template <typename T, typename TStream>
1101constexpr bool Log::isSupported()
1103 return StreamHelper<TStream>::template ShiftOperatorChecker<T>::value;
This class implements a recursive lock object.
Definition Lock.h:31
This class provides access to three different Message objects, e.g., for regular information,...
Definition Messenger.h:792
Ocean::MessageObject< Messenger::isActive()> MessageObject
Definition of a default message object, only active if Messenger::isActive() == true.
Definition Messenger.h:798
Ocean::MessageObject< Messenger::isActive() &&Messenger::isDebugBuild()> DebugMessageObject
Definition of a debug message object, only active on debug builds and if Messenger::isActive() == tru...
Definition Messenger.h:803
MessageObject & operator<<(std::string &&)
Pushes another information message.
Definition Messenger.h:667
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject & newLine(const bool)
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:658
MessageObject(const MessageType)
Creates a new message object.
Definition Messenger.h:621
MessageObject & operator<<(const long long)
Pushes another information message.
Definition Messenger.h:739
MessageObject & operator<<(const long unsigned int)
Pushes another information message.
Definition Messenger.h:757
void operator<<(const MessageObject &)
Pushes another information message.
Definition Messenger.h:765
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
MessageObject & operator<<(const long)
Pushes another information message.
Definition Messenger.h:730
MessageObject & operator<<(const float)
Pushes another information message.
Definition Messenger.h:703
MessageObject & operator<<(const std::string &)
Pushes another information message.
Definition Messenger.h:676
MessageObject & newLine()
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:649
MessageObject & operator<<(const int)
Pushes another information message.
Definition Messenger.h:712
Messenger::MessageType MessageType
Re-definition of MessageType.
Definition Messenger.h:614
~MessageObject()=default
Destructs a message object.
MessageObject & operator<<(const char *)
Pushes another information message.
Definition Messenger.h:685
MessageObject(const MessageType, std::string &&)
Creates a new message object.
Definition Messenger.h:629
MessageObject & operator<<(const double)
Pushes another information message.
Definition Messenger.h:694
MessageObject(const MessageType, std::string &&, std::string &&)
Creates a new message object.
Definition Messenger.h:781
MessageObject & operator<<(const unsigned long long)
Pushes another information message.
Definition Messenger.h:748
MessageObject & operator<<(const unsigned int)
Pushes another information message.
Definition Messenger.h:721
Messenger object, one object for each message.
Definition Messenger.h:448
MessageObject & operator<<(const unsigned long long message)
Pushes another information message.
Definition Messenger.h:1054
MessageObject & operator<<(const unsigned int message)
Pushes another information message.
Definition Messenger.h:1033
void operator<<(const MessageObject &message)
Pushes another information message.
Definition Messenger.h:1068
std::string message_
Definition Messenger.h:591
MessageObject & operator<<(const std::string &message)
Pushes another information message.
Definition Messenger.h:994
MessageObject & operator<<(const double message)
Pushes another information message.
Definition Messenger.h:1012
std::string location_
Definition Messenger.h:594
MessageObject & operator<<(const char *message)
Pushes another information message.
Definition Messenger.h:1001
MessageObject & newLine(const bool condition=true)
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:968
MessageObject & operator<<(std::string &&message)
Pushes another information message.
Definition Messenger.h:979
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject & operator<<(const long unsigned int message)
Pushes another information message.
Definition Messenger.h:1061
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
Messenger::MessageType MessageType
Re-definition of MessageType.
Definition Messenger.h:454
MessageObject & operator<<(const long long message)
Pushes another information message.
Definition Messenger.h:1047
MessageObject & operator<<(const int message)
Pushes another information message.
Definition Messenger.h:1026
MessageObject(const MessageType type)
Creates a new message object.
Definition Messenger.h:935
MessageObject & operator<<(const float message)
Pushes another information message.
Definition Messenger.h:1019
MessageObject(const MessageType type, std::string &&location, std::string &&message)
Creates a new message object.
Definition Messenger.h:950
~MessageObject()
Destructs a message object.
Definition Messenger.h:959
MessageObject & operator<<(const long message)
Pushes another information message.
Definition Messenger.h:1040
Messenger::MessageType type_
Definition Messenger.h:597
MessageObject(const MessageType type, std::string &&location)
Creates a new message object.
Definition Messenger.h:942
static void writeMessageToLogApple(const MessageType messageType, const std::string &message)
Writes a message to Apple's log system.
size_t warnings() const
Returns the number of waiting information messages.
Definition Messenger.h:910
static constexpr bool isActive()
Returns whether the messenger is active on this build.
Definition Messenger.h:421
void queueMessage(const MessageType messageType, std::string &&locationAndTime, std::string &&message)
Queues a message.
static constexpr unsigned int maxMessages_
Maximum number of messages.
Definition Messenger.h:418
std::string lastErrorMessage_
Last error message.
Definition Messenger.h:403
bool empty() const
Returns whether no message exists.
Definition Messenger.h:928
static constexpr bool isDebugBuild()
Returns whether the messenger is used on a debug build.
Definition Messenger.h:430
MessageQueue informationMessageQueue_
Information message queue.
Definition Messenger.h:388
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.
Lock lock_
Messenger lock.
Definition Messenger.h:415
MessageQueue errorMessageQueue_
Error message queue.
Definition Messenger.h:394
void setIntegrateDateTime(const bool state)
Enables or disables the integration of local date/time information into the location information of m...
void clearInformations()
Clears the information message queue.
void clearWarnings()
Clears the warning message queue.
bool popDebug(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first debug message from the message queue.
MessageOutput
Definition of different message output types.
Definition Messenger.h:120
@ OUTPUT_FILE
All messages are directed to a file immediately.
Definition Messenger.h:130
@ OUTPUT_QUEUED
All messages are queued and must be popped from the message stack explicitly.
Definition Messenger.h:126
@ OUTPUT_STANDARD
All messages are directed to the standard output immediately.
Definition Messenger.h:124
@ OUTPUT_DEBUG_WINDOW
All messages are directed to a debug window.
Definition Messenger.h:128
@ OUTPUT_STREAM
All messages are directed to an arbitrary stream immediately.
Definition Messenger.h:132
@ OUTPUT_DISCARDED
All messages will be discarded.
Definition Messenger.h:122
@ OUTPUT_MAINTENANCE
All messages are directed to the maintenance manager.
Definition Messenger.h:134
std::string lastWarningMessage_
Last warning message.
Definition Messenger.h:400
bool setOutputStream(std::ostream &stream)
Sets the message output to an output stream.
void clear()
Clears all message queues.
std::queue< Message > MessageQueue
Definition of a message queue.
Definition Messenger.h:147
std::ofstream fileOutputStream_
File output stream.
Definition Messenger.h:406
MessageQueue debugMessageQueue_
Debug message queue.
Definition Messenger.h:381
std::pair< std::string, std::string > Message
Definition of a message.
Definition Messenger.h:142
static void writeToDebugOutput(const std::string &message)
Writes a message to the most suitable debug output of the current platform.
MessageOutput outputType() const
Returns the output type of the messenger.
Definition Messenger.h:898
MessageQueue warningMessageQueue_
Warning message queue.
Definition Messenger.h:391
MessageType
Definition of different message types.
Definition Messenger.h:103
@ TYPE_INFORMATION
Information message.
Definition Messenger.h:109
@ TYPE_WARNING
Warning message.
Definition Messenger.h:111
@ TYPE_DEBUG
Debug message, which are not used on release builds (optimized out of the code).
Definition Messenger.h:107
@ TYPE_ERROR
Error message.
Definition Messenger.h:113
@ TYPE_UNDEFINED
Invalid message type.
Definition Messenger.h:105
std::string popMessage(const MessageType type=TYPE_UNDEFINED, bool *isNew=nullptr)
Pops the oldest message available of a specified type.
~Messenger()
Destructs a messenger object.
std::string lastDebugMessage_
Last debug message.
Definition Messenger.h:384
std::ostream * outputStream_
Explicit output stream, if any.
Definition Messenger.h:409
void flush(std::ostream &stream)
Flushes the current message stack to a given output stream, the output type is unchanged.
void push(const MessageType type, std::string &&location, std::string &&message)
Pushes a new message into the message queue.
bool setOutputType(const MessageOutput type)
Sets the output type of the messenger.
size_t errors() const
Returns the number of waiting information messages.
Definition Messenger.h:916
bool popWarning(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first warning message from the message queue.
MessageOutput outputType_
Message output type.
Definition Messenger.h:376
bool setFileOutput(const std::string &filename)
Sets the message output to a file.
bool integrateDateTime_
Date and time integration state.
Definition Messenger.h:412
void clearErrors()
Clears the error message queue.
bool integrateDateTime() const
Returns whether the date/time integration is activated.
Definition Messenger.h:922
size_t informations() const
Returns the number of waiting information messages.
Definition Messenger.h:904
Messenger()
Creates a new messenger object queuing all messages as default.
std::string lastInformationMessage_
Last information message.
Definition Messenger.h:397
bool popInformation(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first information message from the message queue.
static void writeMessageToLogAndroid(const MessageType messageType, const std::string &locationAndTime, const std::string &message)
Writes a message to the Android log system (logcat).
bool popError(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first error message from the message queue.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Helper class to check whether a message object or a stream provides a shift operator for an object wi...
Definition Messenger.h:820
static constexpr bool value
False, if the message object or stream does not provide a shift operator for the data type 'TObject'.
Definition Messenger.h:822
Helper class allowing to specify a specific message object or stream type.
Definition Messenger.h:813