MIRA
Public Types | Public Member Functions | Protected Attributes | List of all members
DiagnosticsModule Class Reference

Base class for modules that want to use diagnostics and set the current status. More...

#include <fw/Status.h>

Inheritance diagram for DiagnosticsModule:
Inheritance graph
[legend]

Public Types

typedef std::map< std::string, StatusStatusMap
 

Public Member Functions

 DiagnosticsModule (const std::string &name="")
 
virtual ~DiagnosticsModule ()
 
void setHeartbeatInterval (const Duration &interval)
 Set the watchdog interval. More...
 
void setName (const std::string &name)
 
Duration getHeartbeatInterval () const
 Return the watchdog interval. More...
 
void heartbeat ()
 When called for the first time heartbeat usage will be enabled. More...
 
bool hasHeartbeatTimeout () const
 Returns true if heartbeat usage is enabled (by first call to heartbeat()) and last heartbeat was more than heartbeat interval time ago. More...
 
void bootup (const std::string &message, const std::string &trText="")
 Signal that the module is booting up. More...
 
void bootupFinished ()
 Signal that the module has finished booting up (There can still be errors but booting up is finished) More...
 
void recoverFinished ()
 Signal that the module has finished recovering (There can still be errors but recovering is finished) More...
 
void recover (const std::string &message, const std::string &trText="")
 Signal that the module is recovering. More...
 
void ok (const std::string &category="")
 Signal that a category contains no more errors. More...
 
bool warning (const std::string &category, const std::string &message, const std::string &trText="")
 Signal a warning in a category. More...
 
bool error (const std::string &category, const std::string &message, const std::string &trText="")
 Signal an error in a category. More...
 
bool setStatus (Status::StatusMode mode, const std::string &category, const std::string &message, const std::string &trText="")
 Set the status of a given category. More...
 
Status::StatusMode getStatus () const
 Get the status mode defined by the status of the watchdog (if used) and the bootup, error and warning methods. More...
 
StatusMap getStatusMap () const
 Gets the current status map containing all errors, warnings and bootup messages. More...
 

Protected Attributes

boost::optional< StatusmBootUpStatus
 
boost::optional< StatusmRecoverStatus
 
Duration mHeartbeatInterval
 
boost::optional< TimemLastHeartbeat
 
StatusMap mStatusMap
 
std::string mName
 

Detailed Description

Base class for modules that want to use diagnostics and set the current status.

Classes inheriting this class can be added to the StatusManager for obtaining an overall state of one or multiple diagnostic modules.

Member Typedef Documentation

◆ StatusMap

typedef std::map<std::string, Status> StatusMap

Constructor & Destructor Documentation

◆ DiagnosticsModule()

DiagnosticsModule ( const std::string &  name = "")
inline

◆ ~DiagnosticsModule()

virtual ~DiagnosticsModule ( )
inlinevirtual

Member Function Documentation

◆ setHeartbeatInterval()

void setHeartbeatInterval ( const Duration interval)
inline

Set the watchdog interval.

◆ setName()

void setName ( const std::string &  name)
inline

◆ getHeartbeatInterval()

Duration getHeartbeatInterval ( ) const
inline

Return the watchdog interval.

◆ heartbeat()

void heartbeat ( )
inline

When called for the first time heartbeat usage will be enabled.

This resets the watchdog and signal that everything is working. If you call heartbeat in an interval < watchdog interval the status will be OK (if no other error is set) If a module blocks or fails and does not call heartbeat again until the watchdog interval passed the status will be ERROR

◆ hasHeartbeatTimeout()

bool hasHeartbeatTimeout ( ) const
inline

Returns true if heartbeat usage is enabled (by first call to heartbeat()) and last heartbeat was more than heartbeat interval time ago.

◆ bootup()

void bootup ( const std::string &  message,
const std::string &  trText = "" 
)

Signal that the module is booting up.

Optional a message text and a text used for translation can be specified

◆ bootupFinished()

void bootupFinished ( )

Signal that the module has finished booting up (There can still be errors but booting up is finished)

◆ recoverFinished()

void recoverFinished ( )

Signal that the module has finished recovering (There can still be errors but recovering is finished)

◆ recover()

void recover ( const std::string &  message,
const std::string &  trText = "" 
)

Signal that the module is recovering.

Optional a message text and a text used for translation can be specified

◆ ok()

void ok ( const std::string &  category = "")

Signal that a category contains no more errors.

If no category is set all categories are cleared (except boot up).

◆ warning()

bool warning ( const std::string &  category,
const std::string &  message,
const std::string &  trText = "" 
)

Signal a warning in a category.

A message and an optional text for translation can be given. Additionally, the message is written to the error log.

Returns
true if warning was set, false if a warning with same text was already set

◆ error()

bool error ( const std::string &  category,
const std::string &  message,
const std::string &  trText = "" 
)

Signal an error in a category.

A message and an optional text for translation can be given. Additionally, the error message is written to the error log.

Returns
true if error was set, false if a error with same text was already set

◆ setStatus()

bool setStatus ( Status::StatusMode  mode,
const std::string &  category,
const std::string &  message,
const std::string &  trText = "" 
)

Set the status of a given category.

This method can be used to set the warning or error status of the specified category. a message and an optional text for translation can be given. This method essentially does the same as the above warning() and error() methods. In contrast to those two methods, this method does NOT write the error message to the error/warning log. Hence, it can be used to set the error and warning status silently. In all other cases the warning() and error() methods should be used, which are more convenient.

Returns
true if error was set, false if a error with same text was already set

◆ getStatus()

Status::StatusMode getStatus ( ) const

Get the status mode defined by the status of the watchdog (if used) and the bootup, error and warning methods.

If the watchdog is used (watchdog is enabled when calling heartbeat() for the first time) this method tests if the latest reset of the watchdog was inside the specified watchdog interval. If not it will return ERROR.

◆ getStatusMap()

StatusMap getStatusMap ( ) const

Gets the current status map containing all errors, warnings and bootup messages.

Member Data Documentation

◆ mBootUpStatus

boost::optional<Status> mBootUpStatus
protected

◆ mRecoverStatus

boost::optional<Status> mRecoverStatus
protected

◆ mHeartbeatInterval

Duration mHeartbeatInterval
protected

◆ mLastHeartbeat

boost::optional<Time> mLastHeartbeat
protected

◆ mStatusMap

StatusMap mStatusMap
protected

◆ mName

std::string mName
protected

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