|
From: <rus...@us...> - 2008-10-30 07:10:44
|
Revision: 358
http://gearbox.svn.sourceforge.net/gearbox/?rev=358&view=rev
Author: russo2503v
Date: 2008-10-30 07:10:32 +0000 (Thu, 30 Oct 2008)
Log Message:
-----------
more docco, more standard outpout, new tests
Modified Paths:
--------------
gearbox/trunk/src/gbxutilacfr/status.h
gearbox/trunk/src/gbxutilacfr/test/CMakeLists.txt
gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
gearbox/trunk/src/gbxutilacfr/trivialstatus.h
Added Paths:
-----------
gearbox/trunk/src/gbxutilacfr/test/trivialstatustest.cpp
gearbox/trunk/src/gbxutilacfr/test/trivialtracertest.cpp
Modified: gearbox/trunk/src/gbxutilacfr/status.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/status.h 2008-10-29 12:25:17 UTC (rev 357)
+++ gearbox/trunk/src/gbxutilacfr/status.h 2008-10-30 07:10:32 UTC (rev 358)
@@ -167,35 +167,34 @@
virtual ~Status() {};
/*!
- Adds subsystem to the system status monitor. This command must be called before any
- other. I.e. all other status commands are ignored unless a subsystem with that name
- already exists. When trying to add a subsystem with an existing name, the existing
- subsystem is left unchanged and warning trace is produced.
+ Adds a new subsystem to the system status descriptor. This command must be called before actually
+ modifying the subsystem status, i.e. all other status commands will raise an exception if a subsystem with
+ that name does not already exists.
+
+ An Exception is also raised when trying to add a subsystem with an existing name.
- May also specify the maximum expected interval between heartbeats.
- When time since last heartbeat exceeds this, an alarm is raised. Heartbeat interval is normally
- positive, measured in seconds. Negative interval means infinite interval, this is the default behavior.
+ It is also possible to specify the maximum expected interval between heartbeats. See setMaxHeartbeatInterval()
+ for details.
- The initial state of the subsystem is Initialising.
+ The initial status of the new subsystem is the same as produced by the empty constructor of SubsystemStatus.
*/
virtual void addSubsystem( const std::string& subsystem, double maxHeartbeatIntervalSec=-1.0 )=0;
- //! Removes subsystem from the status monitor. This should be done for example, if one of
- //! the thread is shutting down or restarting.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+ //! Removes a subsystem from the status descriptor.
+ //! Throws Exception if the subsystem does not exist.
virtual void removeSubsystem( const std::string& subsystem )=0;
//! Returns a list of subsystem names.
virtual std::vector<std::string> subsystems()=0;
- //! Returns status of subsystem with the given name.
- //! Throws gbxutilacfr::Exception when the specified subsystem does not exist.
+ //! Returns status of the subsystem with the given name.
+ //! Throws Exception when the specified subsystem does not exist.
virtual SubsystemStatus subsystemStatus( const std::string& subsystem )=0;
//! Modifies maximum expected interval between heartbeats (in seconds).
- //! When time since last heartbeat exceeds this, alarm is raised.
+ //! When time since the last heartbeat exceeds the specified value, the subsystem is considered stalled.
//! Negative interval means infinite interval.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+ //! Throws Exception if the subsystem does not exist.
virtual void setMaxHeartbeatInterval( const std::string& subsystem, double intervalSec )=0;
//
@@ -204,36 +203,39 @@
//! Sets the status of a subsystem (both state and health) in an atomic operation. Use this method
//! when both state and health have changed.
+ //! Throws Exception if the subsystem does not exist.
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.
+ //! Sets state of the subsystem to Initialising. The old message is cleared if a new one is not supplied.
+ //! Throws Exception if the subsystem does not exist.
virtual void initialising( const std::string& subsystem, const std::string& message="" )=0;
- //! Sets state of the subsystem to Working. Note that empty message is assumed if none is supplied.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+
+ //! Sets state of the subsystem to Working. The old message is cleared if a new one is not supplied.
+ //! Throws Exception if the subsystem does not exist.
virtual void working( const std::string& subsystem, const std::string& message="" )=0;
- //! Sets state of the subsystem to Finalising. Note that empty message is assumed if none is supplied.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+
+ //! Sets state of the subsystem to Finalising. The old message is cleared if a new one is not supplied.
+ //! Throws Exception if the subsystem does not exist.
virtual void finalising( const std::string& subsystem, const std::string& message="" )=0;
//
// 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.
+ //! Sets subsystem health to Ok. The old message is cleared if a new one is not supplied.
+ //! Throws Exception if the subsystem does not exist.
virtual void ok( const std::string& subsystem, const std::string& message="" )=0;
//! Sets subsystem health to Warning.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+ //! Throws Exception if the subsystem does not exist.
virtual void warning( const std::string& subsystem, const std::string& message )=0;
//! Sets subsystem health to Fault.
- //! Throws gbxutilacfr::Exception if the subsystem does not exist.
+ //! Throws Exception if the subsystem does not exist.
virtual void fault( const std::string& subsystem, const std::string& message )=0;
//
@@ -242,15 +244,19 @@
//! 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.
+ //! Throws Exception if the subsystem does not exist.
virtual void heartbeat( const std::string& subsystem )=0;
+ //! Change the human-readable message for a subsystem but keep the previous state and health information.
+ //! Throws Exception if the subsystem does not exist.
+ virtual void message( const std::string& subsystem, const std::string& message )=0;
+
//
// Utility
//
- //! Some thread must call this function periodically in order for
- //! status publishing to happen and stalls identified.
+ //! This function must be called periodically in order for
+ //! status publishing to happen and stalled susbsystems identified.
virtual void process()=0;
};
Modified: gearbox/trunk/src/gbxutilacfr/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxutilacfr/test/CMakeLists.txt 2008-10-29 12:25:17 UTC (rev 357)
+++ gearbox/trunk/src/gbxutilacfr/test/CMakeLists.txt 2008-10-30 07:10:32 UTC (rev 358)
@@ -7,3 +7,9 @@
ADD_EXECUTABLE( tokenisetest tokenisetest.cpp )
GBX_ADD_TEST( GbxUtilAcfrTokeniseTest tokenisetest )
+
+ADD_EXECUTABLE( trivialtracertest trivialtracertest.cpp )
+GBX_ADD_TEST( GbxUtilAcfrTrivialTracerTest trivialtracertest )
+
+ADD_EXECUTABLE( trivialstatustest trivialstatustest.cpp )
+GBX_ADD_TEST( GbxUtilAcfrTrivialStatusTest trivialstatustest )
Added: gearbox/trunk/src/gbxutilacfr/test/trivialstatustest.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/test/trivialstatustest.cpp (rev 0)
+++ gearbox/trunk/src/gbxutilacfr/test/trivialstatustest.cpp 2008-10-30 07:10:32 UTC (rev 358)
@@ -0,0 +1,72 @@
+/*
+ * 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 <iostream>
+#include <cstdlib>
+#include <gbxutilacfr/trivialtracer.h>
+#include <gbxutilacfr/trivialstatus.h>
+#include <gbxutilacfr/exceptions.h>
+
+using namespace std;
+
+int main(int argc, char * argv[])
+{
+ gbxutilacfr::TrivialTracer tracer;
+
+ gbxutilacfr::TrivialStatus status( tracer );
+
+ cout<<"setMaxHeartbeatInterval on non-existent subsystems ...";
+ try {
+ status.setMaxHeartbeatInterval( "core", 10 );
+ }
+ catch ( const gbxutilacfr::Exception& e ) {
+ // ok
+ }
+ cout<<"ok"<<endl;
+
+ cout<<"adding subsystem ...";
+ status.addSubsystem( "core", 10 );
+
+ // not calling subsystems(), it throws
+
+ // not calling subsystemStatus(), it throws
+
+ status.setMaxHeartbeatInterval( "core", 20 );
+ status.initialising( "core", "holding fingers crossed" );
+
+ // this one should not appear
+ status.initialising( "core", "holding fingers crossed" );
+ status.initialising( "core", "still holding fingers crossed" );
+ status.heartbeat( "core" );
+
+ status.warning( "core", "all is weird" );
+ status.warning( "core", "all is weird" );
+ status.warning( "core", "still all is weird" );
+
+ status.fault( "core", "all is bad" );
+ status.fault( "core", "all is bad" );
+ status.fault( "core", "still all is bad" );
+
+ status.ok( "core", "all is good again" );
+ status.ok( "core" );
+ // this one will not get traced!
+ status.ok( "core" );
+
+ status.working( "core" );
+
+ status.finalising( "core" );
+
+ // should delete and start complaining again
+ cout<<"removing existing subsystem ...";
+ status.removeSubsystem( "core" );
+ cout<<"ok"<<endl;
+
+ return EXIT_SUCCESS;
+}
Added: gearbox/trunk/src/gbxutilacfr/test/trivialtracertest.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/test/trivialtracertest.cpp (rev 0)
+++ gearbox/trunk/src/gbxutilacfr/test/trivialtracertest.cpp 2008-10-30 07:10:32 UTC (rev 358)
@@ -0,0 +1,32 @@
+/*
+ * 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 <iostream>
+#include <cstdlib>
+#include <gbxutilacfr/trivialtracer.h>
+
+using namespace std;
+
+int main(int argc, char * argv[])
+{
+ cout<<"testing TrivialTracer() without props ..."<<endl;
+ gbxutilacfr::TrivialTracer tracer;
+ cout<<"ok"<<endl;
+
+ string message = "when you don't have anything nice to say...";
+
+ tracer.print( message );
+ tracer.info( message );
+ tracer.warning( message );
+ tracer.error( message );
+ tracer.debug( message );
+
+ return EXIT_SUCCESS;
+}
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-10-29 12:25:17 UTC (rev 357)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-10-30 07:10:32 UTC (rev 358)
@@ -32,17 +32,13 @@
void
TrivialStatus::addSubsystem( const std::string& subsystem, double maxHeartbeatIntervalSec )
{
- stringstream ss;
- ss << "TrivialStatus::setMaxHeartbeatInterval(): Adding new subsystem: '"<<subsystem<<"'";
- tracer_.debug( ss.str() );
+ tracer_.warning( "TrivialStatus: this implementation of Status does not store status of the subsystems" );
}
void
TrivialStatus::removeSubsystem( const std::string& subsystem )
{
- stringstream ss;
- ss << "TrivialStatus::removeSubsystem(): Removing existing subsystem: '"<<subsystem<<"'";
- tracer_.debug( ss.str() );
+ tracer_.warning( "TrivialStatus: this implementation of Status does not store status of the subsystems" );
}
std::vector<std::string>
@@ -54,87 +50,128 @@
SubsystemStatus
TrivialStatus::subsystemStatus( const std::string& subsystem )
{
- throw Exception( ERROR_INFO, "This implementation of Status does not store status of the subsystems" );
+ throw Exception( ERROR_INFO, "TrivialStatus: this implementation of Status does not store status of the subsystems" );
}
void
TrivialStatus::setMaxHeartbeatInterval( const std::string& subsystem, double maxHeartbeatIntervalSec )
{
+ // does nothing
}
void
-TrivialStatus::setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& message )
+TrivialStatus::setSubsystemStatus( const std::string& subsystem, gbxutilacfr::SubsystemState state,
+ gbxutilacfr::SubsystemHealth health, const std::string& msg )
{
- string trace = "TrivialStatus: subsystem "+subsystem+" changed state to "+gbxutilacfr::toString(state)+" with health "+gbxutilacfr::toString(health);
- if (!message.empty() )
- trace =+ ": '" + message + "'";
- tracer_.info( trace );
+ internalSetStatus( subsystem, state, health, msg );
}
void
-TrivialStatus::initialising( const std::string& subsystem, const std::string& message )
+TrivialStatus::initialising( const std::string& subsystem, const std::string& msg )
{
- if ( stateChange_ ) {
- string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Initialising";
- if (!message.empty() )
- trace =+ " and message: '" + message + "'";
- tracer_.info( trace );
- }
+ internalSetStatus( subsystem, gbxutilacfr::SubsystemInitialising, (gbxutilacfr::SubsystemHealth)-1, msg );
}
void
-TrivialStatus::working( const std::string& subsystem, const std::string& message )
+TrivialStatus::working( const std::string& subsystem, const std::string& msg )
{
- if ( stateChange_ ) {
- string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Working";
- if (!message.empty() )
- trace =+ ": '" + message + "'";
- tracer_.info( trace );
- }
+ internalSetStatus( subsystem, gbxutilacfr::SubsystemWorking, (gbxutilacfr::SubsystemHealth)-1, msg );
}
void
-TrivialStatus::finalising( const std::string& subsystem, const std::string& message )
+TrivialStatus::finalising( const std::string& subsystem, const std::string& msg )
{
- if ( stateChange_ ) {
- string trace = "TrivialStatus: subsystem "+subsystem+" changed state to Finalising";
- if (!message.empty() )
- trace =+ ": '" + message + "'";
- tracer_.info( trace );
- }
+ internalSetStatus( subsystem, gbxutilacfr::SubsystemFinalising, (gbxutilacfr::SubsystemHealth)-1, msg );
}
void
-TrivialStatus::ok( const std::string& subsystem, const std::string& message )
+TrivialStatus::ok( const std::string& subsystem, const std::string& msg )
{
- if ( ok_ && !message.empty() )
- tracer_.info( "TrivialStatus: "+subsystem+" is ok : '"+message+"'" );
+ internalSetStatus( subsystem, (gbxutilacfr::SubsystemState)-1, gbxutilacfr::SubsystemOk, msg );
}
void
-TrivialStatus::warning( const std::string& subsystem, const std::string& message )
+TrivialStatus::warning( const std::string& subsystem, const std::string& msg )
{
- if ( warn_ )
- tracer_.warning( "TrivialStatus: "+subsystem+" issued warning : '"+message+"'" );
+ internalSetStatus( subsystem, (gbxutilacfr::SubsystemState)-1, gbxutilacfr::SubsystemWarning, msg );
}
void
-TrivialStatus::fault( const std::string& subsystem, const std::string& message )
+TrivialStatus::fault( const std::string& subsystem, const std::string& msg )
{
- if ( fault_ )
- tracer_.error( "TrivialStatus: "+subsystem+" issued fault : '"+message+"'" );
+ internalSetStatus( subsystem, (gbxutilacfr::SubsystemState)-1, gbxutilacfr::SubsystemFault, msg );
}
void
TrivialStatus::heartbeat( const std::string& subsystem )
{
- if ( heartbeat_ )
- tracer_.info( "TrivialStatus: heartbeat for subsystem "+subsystem );
+ internalSetStatus( subsystem, (gbxutilacfr::SubsystemState)-1, (gbxutilacfr::SubsystemHealth)-1 );
}
+
+void
+TrivialStatus::message( const std::string& subsystem, const std::string& msg )
+{
+ internalSetStatus( subsystem, (gbxutilacfr::SubsystemState)-1, (gbxutilacfr::SubsystemHealth)-1, msg );
+}
void
+TrivialStatus::internalSetStatus( const std::string& subsystemName, gbxutilacfr::SubsystemState state,
+ gbxutilacfr::SubsystemHealth health, const std::string& msg )
+{
+ assert( state!=gbxutilacfr::SubsystemIdle && "Idle state should not be reported from within the subsystem" );
+ assert( health!=gbxutilacfr::SubsystemStalled && "Stalled health should not be reported from within the subsystem" );
+
+ // if this is a heartbeat, do nothing else
+ if ( state<0 && health<0 && msg.empty() )
+ return;
+
+ bool traceState = true;
+ // don't trace if we don't know it
+ if ( state < 0 )
+ traceState = false;
+
+ bool traceHealth = true;
+ // don't trace if we don't know it
+ if ( health < 0 )
+ traceHealth = false;
+
+// bool publishStatus = false;
+
+ // give tracer feedback on state
+ if ( traceState )
+ tracer_.info( "Subsystem '"+subsystemName+"' changed state to "+gbxutilacfr::toString(state) );
+
+ // give tracer feedback on status
+ if ( traceHealth )
+ {
+ string trace = "Subsystem '"+subsystemName
+ +"' status="+gbxutilacfr::toString(state)+"/"+gbxutilacfr::toString(health);
+ if ( !msg.empty() )
+ trace =+ ": "+msg;
+ switch ( health )
+ {
+ case gbxutilacfr::SubsystemOk :
+ tracer_.info( trace );
+ break;
+ case gbxutilacfr::SubsystemWarning :
+ tracer_.warning( trace );
+ break;
+ case gbxutilacfr::SubsystemFault :
+ case gbxutilacfr::SubsystemStalled :
+ tracer_.error( trace );
+ break;
+ }
+ }
+
+ // publish updated status
+// if ( publishStatus )
+// localPublish();
+}
+
+void
TrivialStatus::process()
{
+ // cannot determine stalls because we are not tracking subsystem status
}
}
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-10-29 12:25:17 UTC (rev 357)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-10-30 07:10:32 UTC (rev 358)
@@ -39,21 +39,25 @@
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 setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& msg="" );
- 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 initialising( const std::string& subsystem, const std::string& msg="" );
+ virtual void working( const std::string& subsystem, const std::string& msg="" );
+ virtual void finalising( const std::string& subsystem, const std::string& msg="" );
- 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 ok( const std::string& subsystem, const std::string& msg="" );
+ virtual void warning( const std::string& subsystem, const std::string& msg );
+ virtual void fault( const std::string& subsystem, const std::string& msg );
virtual void heartbeat( const std::string& subsystem );
+ virtual void message( const std::string& subsystem, const std::string& msg );
virtual void process();
private:
+ void internalSetStatus( const std::string& subsystem, gbxutilacfr::SubsystemState state,
+ gbxutilacfr::SubsystemHealth health, const std::string& msg="" );
+
Tracer& tracer_;
bool stateChange_;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|