AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agx::LoggerSubscriber Class Reference

Class for polling messages from the LOGGER system in a Subscriber pattern. More...

#include <LoggerSubscriber.h>

+ Inheritance diagram for agx::LoggerSubscriber:

Classes

class  LogCallback
 

Public Types

typedef std::pair< int,
agx::String > 
Message
 
typedef agx::Vector< Message > MessageVector
 

Public Member Functions

 LoggerSubscriber (int levelMask=agx::Notify::NOTIFY_INFO|agx::Notify::NOTIFY_WARNING|agx::Notify::NOTIFY_ERROR)
 Constructor for a logger mailbox. More...
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
void clear (int levelMask=ALL_LEVELS)
 Remove all messages. More...
 
bool empty (int levelMask=ALL_LEVELS) const
 
bool getEnable () const
 
bool getMessages (MessageVector &messages, bool clearMessages, int levelMask=ALL_LEVELS)
 Get a copy of all messages matching the specified notify level levelMask in the message queue. More...
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
std::string pop (int levelMask=ALL_LEVELS)
 Get all available messages and then remove them. More...
 
size_t pop (agx::StringVector &outMessages, int levelMask=ALL_LEVELS)
 Get all available messages and then remove them. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void setEnable (bool flag)
 Enable/disable the capturing of messages. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Static Public Attributes

static int ALL_LEVELS
 

Protected Member Functions

virtual ~LoggerSubscriber ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
void message (const agx::String &msg, int notifyLevel)
 Callback that will be called when a new message is present. More...
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Class for polling messages from the LOGGER system in a Subscriber pattern.

Messages is stored until the message pop() is called. The class is reentrant thread safe.

There are a message queue for each NotifyLevel. So all methods can use a bitmask to filter out which queue that is requested.

Definition at line 33 of file LoggerSubscriber.h.

Member Typedef Documentation

Definition at line 87 of file LoggerSubscriber.h.

Constructor & Destructor Documentation

agx::LoggerSubscriber::LoggerSubscriber ( int  levelMask = agx::Notify::NOTIFY_INFO|agx::Notify::NOTIFY_WARNING|agx::Notify::NOTIFY_ERROR)

Constructor for a logger mailbox.

Parameters
levelMask- Specifies which levels of messages that will be captured. Default is all messages with equal or higher level that NOTIFY_INFO.
virtual agx::LoggerSubscriber::~LoggerSubscriber ( )
protectedvirtual

Destructor.

Member Function Documentation

void agx::Referenced::allocateObserverVector ( ) const
protectedinherited
template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), and agx::InternalData::getOrCreate().

template<typename T >
const T* agx::Referenced::as ( ) const
inherited
template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited
void agx::LoggerSubscriber::clear ( int  levelMask = ALL_LEVELS)

Remove all messages.

Parameters
levelMask- Specifies which levels of messages that should be cleared, by default all levels
void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited
bool agx::LoggerSubscriber::empty ( int  levelMask = ALL_LEVELS) const
Parameters
levelMask- Specifies which levels of messages that should be checked for, by default all levels
Returns
true if no messages are present
static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.
bool agx::LoggerSubscriber::getEnable ( ) const
Returns
true if messages are being captured
bool agx::LoggerSubscriber::getMessages ( MessageVector &  messages,
bool  clearMessages,
int  levelMask = ALL_LEVELS 
)

Get a copy of all messages matching the specified notify level levelMask in the message queue.

Each message contains a pair of: NOTIFY level (INFO, WARNING, ERROR) and the message string in chronological order

Parameters
messages- Reference to a message queue that will be populated with all the matching messages
clearMessages- If true, the message queue will be cleared from the matching messages
Returns
true if any messages were awailable.
int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.
template<typename T >
bool agx::Referenced::is ( ) const
inherited
void agx::LoggerSubscriber::message ( const agx::String &  msg,
int  notifyLevel 
)
protected

Callback that will be called when a new message is present.

std::string agx::LoggerSubscriber::pop ( int  levelMask = ALL_LEVELS)

Get all available messages and then remove them.

Parameters
levelMask- Specifies which levels of messages that should be checked for.
Returns
all messages concatenated into a string. Messages will be separated with a newline
size_t agx::LoggerSubscriber::pop ( agx::StringVector &  outMessages,
int  levelMask = ALL_LEVELS 
)

Get all available messages and then remove them.

Parameters
[out]outMessages- Where messages will be stored
levelMask- Specifies which levels of messages that should be captured.
Returns
the number of available messages
void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

Referenced by agxData::Val< UInt >::Val().

static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

void agx::LoggerSubscriber::setEnable ( bool  flag)

Enable/disable the capturing of messages.

Parameters
flag- If true messages will be captured
void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

Member Data Documentation

int agx::LoggerSubscriber::ALL_LEVELS
static

Definition at line 38 of file LoggerSubscriber.h.

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.


The documentation for this class was generated from the following file: