|
From: <rus...@us...> - 2008-10-27 12:18:58
|
Revision: 345
http://gearbox.svn.sourceforge.net/gearbox/?rev=345&view=rev
Author: russo2503v
Date: 2008-10-27 12:18:47 +0000 (Mon, 27 Oct 2008)
Log Message:
-----------
status describes state and health of subsystems
Modified Paths:
--------------
gearbox/trunk/src/gbxutilacfr/status.h
gearbox/trunk/src/gbxutilacfr/substatus.h
gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
gearbox/trunk/src/gbxutilacfr/trivialstatus.h
Added Paths:
-----------
gearbox/trunk/src/gbxutilacfr/status.cpp
Added: gearbox/trunk/src/gbxutilacfr/status.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/status.cpp (rev 0)
+++ gearbox/trunk/src/gbxutilacfr/status.cpp 2008-10-27 12:18:47 UTC (rev 345)
@@ -0,0 +1,49 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp
+ *
+ * This distribution is licensed to you under the terms described in
+ * the LICENSE file included in this distribution.
+ *
+ */
+
+#include "status.h"
+
+namespace gbxutilacfr {
+
+std::string toString( SubsystemState state )
+{
+ switch ( state )
+ {
+ case SubsystemInitialising :
+ return "Initialising";
+ case SubsystemWorking :
+ return "Working";
+ case SubsystemFinalising :
+ return "Finalising";
+ case SubsystemIdle :
+ return "Idle";
+ case SubsystemShutdown :
+ break;
+ }
+ return "Shutdown";
+}
+
+std::string toString( SubsystemHealth health )
+{
+ switch ( health )
+ {
+ case SubsystemOk :
+ return "Ok";
+ case SubsystemWarning :
+ return "Warning";
+ case SubsystemFault :
+ return "Fault";
+ case SubsystemStalled :
+ break;
+ }
+ return "Stalled";
+}
+
+} // namespace
Modified: gearbox/trunk/src/gbxutilacfr/status.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/status.h 2008-10-26 03:45:15 UTC (rev 344)
+++ gearbox/trunk/src/gbxutilacfr/status.h 2008-10-27 12:18:47 UTC (rev 345)
@@ -17,26 +17,40 @@
namespace gbxutilacfr {
//! Possible subsystem status values
-enum SubsystemStatusType
+enum SubsystemState
{
- //! Subsystem is initialising -- it's not exactly OK yet, but there's also no fault yet.
- SubsystemStatusInitialising,
+ SubsystemIdle,
+ SubsystemInitialising,
+ SubsystemWorking,
+ SubsystemFinalising,
+ SubsystemShutdown
+};
+
+std::string toString( SubsystemState state );
+
+//! Possible subsystem status values
+enum SubsystemHealth
+{
//! Subsystem is OK
- SubsystemStatusOk,
+ SubsystemOk,
//! Subsystem has encountered an abnormal but non-fault condition
- SubsystemStatusWarning,
+ SubsystemWarning,
//! Subsystem has declared a fault
- SubsystemStatusFault,
+ SubsystemFault,
//! Subsystem has not been heard from for an abnormally long time
- SubsystemStatusStalled
+ SubsystemStalled
};
+std::string toString( SubsystemHealth health );
+
//! Status for a single subsystem
struct SubsystemStatus
{
//! Machine-readable status description
- SubsystemStatusType type;
+ SubsystemState state;
+ SubsystemHealth health;
+
//! Human-readable status description
std::string message;
@@ -119,29 +133,55 @@
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void setMaxHeartbeatInterval( const std::string& subsystem, double intervalSec )=0;
- //! Sets subsystem status to Initialising. Note that empty message is assumed if none is supplied.
+ //
+ // BOTH STATE AND HEALTH CHANGES
+ //
+
+ //! Sets the status of a subsystem (both state and health) in an atomic operation. Use this method
+ //! when both state and health have changed.
+ virtual void setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& message="" )=0;
+
+ //
+ // STATE CHANGES
+ //
+
+ //! Sets state of the subsystem to Initialising. Note that empty message is assumed if none is supplied.
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void initialising( const std::string& subsystem, const std::string& message="" )=0;
+ virtual void working( const std::string& subsystem, const std::string& message="" )=0;
+ virtual void finalising( const std::string& subsystem, const std::string& message="" )=0;
- //! Sets subsystem status to Ok. Note that empty message is assumed if none is supplied.
+ //
+ // HEALTH CHANGES
+ //
+
+ //! Sets subsystem health to Ok. Note that empty message is assumed if none is supplied.
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void ok( const std::string& subsystem, const std::string& message="" )=0;
- //! Sets subsystem status to Warning.
+ //! Sets subsystem health to Warning.
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void warning( const std::string& subsystem, const std::string& message )=0;
- //! Sets subsystem status to Fault.
+ //! Sets subsystem health to Fault.
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void fault( const std::string& subsystem, const std::string& message )=0;
+ //
+ // NO CHANGE
+ //
+
//! Record heartbeat from a subsystem: let Status know the subsystem is alive without
//! modifying its status.
//! Throws gbxutilacfr::Exception if the subsystem does not exist.
virtual void heartbeat( const std::string& subsystem )=0;
- //! Some thread should call this function periodically in order for
- //! status publishing to happen.
+ //
+ // Utility
+ //
+
+ //! Some thread must call this function periodically in order for
+ //! status publishing to happen and stalls identified.
virtual void process()=0;
};
Modified: gearbox/trunk/src/gbxutilacfr/substatus.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/substatus.h 2008-10-26 03:45:15 UTC (rev 344)
+++ gearbox/trunk/src/gbxutilacfr/substatus.h 2008-10-27 12:18:47 UTC (rev 345)
@@ -20,13 +20,8 @@
//!
//! @par Overview
//!
-//! SubStatus provides a machine-readable interface such that other components can
-//! monitor this component's status.
+//! Provides a convenient interface for setting status information for one subsystem.
//!
-//! A single SubStatus object is meant to be shared by all threads in the component so the
-//! implementation must be thread-safe.
-//!
-//!
//! @sa Status
//!
class SubStatus
@@ -58,6 +53,12 @@
void initialising( const std::string& message="" ) { status_.initialising( subsysName_, message ); };
//! Passes this information to the system Status.
+ void working( const std::string& message="" ) { status_.working( subsysName_, message ); };
+
+ //! Passes this information to the system Status.
+ void finalising( const std::string& message="" ) { status_.finalising( subsysName_, message ); };
+
+ //! Passes this information to the system Status.
void ok( const std::string& message="" ) { status_.ok( subsysName_, message ); };
//! Passes this information to the system Status.
@@ -66,6 +67,9 @@
//! Passes this information to the system Status.
void fault( const std::string& message ) { status_.fault( subsysName_, message ); };
+ //! Returns system Status object
+ Status& status() { return status_; };
+
//! Returns subsystem's name
std::string name() const { return subsysName_; };
private:
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-10-26 03:45:15 UTC (rev 344)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-10-27 12:18:47 UTC (rev 345)
@@ -12,19 +12,20 @@
#include <sstream>
#include "trivialstatus.h"
#include "exceptions.h"
+#include <assert.h>
using namespace std;
namespace gbxutilacfr {
TrivialStatus::TrivialStatus( Tracer& tracer,
- bool heartbeat, bool ok, bool init, bool warn, bool fault ) :
+ bool stateChange, bool ok, bool warn, bool fault, bool heartbeat ) :
tracer_(tracer),
- heartbeat_(heartbeat),
+ stateChange_(stateChange),
ok_(ok),
- init_(init),
warn_(warn),
- fault_(fault)
+ fault_(fault),
+ heartbeat_(heartbeat)
{
}
@@ -62,13 +63,48 @@
}
void
+TrivialStatus::setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& message )
+{
+ string trace = "TrivialStatus: subsystem "+subsystem+" changed state to "+gbxutilacfr::toString(state)+" with health "+gbxutilacfr::toString(health);
+ if (!message.empty() )
+ trace =+ ": '" + message + "'";
+ tracer_.info( trace );
+}
+
+void
TrivialStatus::initialising( const std::string& subsystem, const std::string& message )
{
- if ( init_ && !message.empty() )
- tracer_.info( "TrivialStatus: initialising subsystem "+subsystem+": '"+message+"'" );
+ if ( stateChange_ ) {
+ string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Initialising";
+ if (!message.empty() )
+ trace =+ " and message: '" + message + "'";
+ tracer_.info( trace );
+ }
}
void
+TrivialStatus::working( const std::string& subsystem, const std::string& message )
+{
+ if ( stateChange_ ) {
+ string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Working";
+ if (!message.empty() )
+ trace =+ ": '" + message + "'";
+ tracer_.info( trace );
+ }
+}
+
+void
+TrivialStatus::finalising( const std::string& subsystem, const std::string& message )
+{
+ if ( stateChange_ ) {
+ string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Finalising";
+ if (!message.empty() )
+ trace =+ ": '" + message + "'";
+ tracer_.info( trace );
+ }
+}
+
+void
TrivialStatus::ok( const std::string& subsystem, const std::string& message )
{
if ( ok_ && !message.empty() )
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-10-26 03:45:15 UTC (rev 344)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-10-27 12:18:47 UTC (rev 345)
@@ -18,8 +18,10 @@
//!
-//! @brief A trivial implementation of the status API which prints to cout.
+//! @brief A trivial implementation of the status API which does not assemble information.
//!
+//! System status information is not assembled but all changes are traced to Tracer.
+//!
//! @see Status
//!
class TrivialStatus : public Status
@@ -27,7 +29,7 @@
public:
TrivialStatus( Tracer& tracer,
- bool heartbeat=false, bool ok=false, bool init=false, bool warn=true, bool fault=true );
+ bool stateChange=true, bool ok=false, bool warn=true, bool fault=true, bool heartbeat=false );
virtual void addSubsystem( const std::string& subsystem, double maxHeartbeatIntervalSec=-1.0 );
virtual void removeSubsystem( const std::string& subsystem );
@@ -36,22 +38,29 @@
//! does not keep track of status, throws Exception on any query
virtual SubsystemStatus subsystemStatus( const std::string& subsystem );
virtual void setMaxHeartbeatInterval( const std::string& subsystem, double interval );
+
+ virtual void setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& message="" );
+
virtual void initialising( const std::string& subsystem, const std::string& message="" );
+ virtual void working( const std::string& subsystem, const std::string& message="" );
+ virtual void finalising( const std::string& subsystem, const std::string& message="" );
+
virtual void ok( const std::string& subsystem, const std::string& message="" );
virtual void warning( const std::string& subsystem, const std::string& message );
virtual void fault( const std::string& subsystem, const std::string& message );
virtual void heartbeat( const std::string& subsystem );
+
virtual void process();
private:
Tracer& tracer_;
- bool heartbeat_;
+ bool stateChange_;
bool ok_;
- bool init_;
bool warn_;
bool fault_;
+ bool heartbeat_;
};
} // namespace
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|