|
From: <rus...@us...> - 2008-11-07 02:02:34
|
Revision: 359
http://gearbox.svn.sourceforge.net/gearbox/?rev=359&view=rev
Author: russo2503v
Date: 2008-11-07 01:35:28 +0000 (Fri, 07 Nov 2008)
Log Message:
-----------
moved Tracer enums out of the class. added infrastructure state to Status.
Modified Paths:
--------------
gearbox/trunk/doc/history.dox
gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp
gearbox/trunk/src/gbxutilacfr/status.cpp
gearbox/trunk/src/gbxutilacfr/status.h
gearbox/trunk/src/gbxutilacfr/tracer.h
gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
gearbox/trunk/src/gbxutilacfr/trivialstatus.h
gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp
gearbox/trunk/src/gbxutilacfr/trivialtracer.h
Added Paths:
-----------
gearbox/trunk/src/gbxutilacfr/tracer.cpp
Modified: gearbox/trunk/doc/history.dox
===================================================================
--- gearbox/trunk/doc/history.dox 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/doc/history.dox 2008-11-07 01:35:28 UTC (rev 359)
@@ -31,9 +31,14 @@
- A bit more careful when dealing with chunks of buffer that can't be parsed, should be a bit more robust (AlexB).
- libGbxUtilAcfr
- - Changed interface for Tracer: when querying verbosity, default destination argument is 'ToAny' (AlexB).
+ - Changed interface for Tracer:
+ - when querying verbosity, default destination argument is 'ToAny' (AlexB).
+ - moved trace type and destination enums out of the class into the namespace (alexm)
- Changed implementation of TrivialTracer to allow multiple levels of tracing verbosity (AlexB).
- - Status now describes status of subsystems in two orthogonal dimensions: state and health. (alexm)
+ - Changed interface for Status:
+ - status of subsystems is described in two orthogonal dimensions: state and health. (alexm)
+ - added infrastructure state to the component status and functions to set it. (alexm)
+ - added message() which only changes the human-readable message (alexm)
@section gbx_doc_history_807 Changes in Release 8.07
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-11-07 01:35:28 UTC (rev 359)
@@ -257,7 +257,7 @@
// Debugging output
//
const int debugLevel = 10;
- if (tracer_.verbosity( gbxutilacfr::Tracer::DebugTrace, gbxutilacfr::Tracer::ToAny ) >= debugLevel)
+ if (tracer_.verbosity( gbxutilacfr::DebugTrace, gbxutilacfr::ToAny ) >= debugLevel)
{
stringstream ss;
for (unsigned int i=0; i<stringList.size(); i++)
Modified: gearbox/trunk/src/gbxutilacfr/status.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/status.cpp 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/status.cpp 2008-11-07 01:35:28 UTC (rev 359)
@@ -10,6 +10,7 @@
#include "status.h"
#include <sstream>
+#include <assert.h>
namespace gbxutilacfr {
@@ -26,9 +27,10 @@
case SubsystemIdle :
return "Idle";
case SubsystemShutdown :
- break;
+ return "Shutdown";
+ default:
+ assert( !"gbxutilacfr::toString(SubsystemState) should never get to default" );
}
- return "Shutdown";
}
std::string toString( SubsystemHealth health )
@@ -42,16 +44,19 @@
case SubsystemFault :
return "Fault";
case SubsystemStalled :
- break;
+ return "Stalled";
+ default:
+ assert( !"gbxutilacfr::toString(SubsystemHealth) should never get to default" );
}
- return "Stalled";
}
std::string toString( const SubsystemStatus& status )
{
std::stringstream ss;
- ss << "state="<<toString(status.state)<<" health="<<toString(status.health)
- << " msg='"<<status.message<<"' since hearbeat="<<status.sinceHeartbeat;
+ ss << "state="<<toString(status.state)
+ << " health="<<toString(status.health)
+ << " msg='"<<status.message<<"'"
+ << " since hearbeat="<<status.sinceHeartbeat;
return ss.str();
}
Modified: gearbox/trunk/src/gbxutilacfr/status.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/status.h 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/status.h 2008-11-07 01:35:28 UTC (rev 359)
@@ -191,6 +191,9 @@
//! Throws Exception when the specified subsystem does not exist.
virtual SubsystemStatus subsystemStatus( const std::string& subsystem )=0;
+ //! Returns state of the component infrastructure.
+ virtual SubsystemState infrastructureState()=0;
+
//! Modifies maximum expected interval between heartbeats (in seconds).
//! When time since the last heartbeat exceeds the specified value, the subsystem is considered stalled.
//! Negative interval means infinite interval.
@@ -252,6 +255,16 @@
virtual void message( const std::string& subsystem, const std::string& message )=0;
//
+ // INFRASTRUCTURE STATE CHANGES
+ //
+ //! Sets state of component infrastructure to Initialising.
+ virtual void compInitialising()=0;
+ //! Sets state of component infrastructure to Working.
+ virtual void compWorking()=0;
+ //! Sets state of component infrastructure to Finalising.
+ virtual void compFinalising()=0;
+
+ //
// Utility
//
Added: gearbox/trunk/src/gbxutilacfr/tracer.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/tracer.cpp (rev 0)
+++ gearbox/trunk/src/gbxutilacfr/tracer.cpp 2008-11-07 01:35:28 UTC (rev 359)
@@ -0,0 +1,37 @@
+/*
+ * 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 "tracer.h"
+#include <assert.h>
+
+namespace gbxutilacfr {
+
+std::string toString( TraceType type )
+{
+ switch ( type )
+ {
+ case InfoTrace :
+ return "info";
+ case WarningTrace :
+ return "warn";
+ case ErrorTrace :
+ return "error";
+ case DebugTrace :
+ return "debug";
+ case AnyTrace :
+ return "any";
+ case NumberOfTraceTypes :
+ return "number_of_trace_types";
+ default:
+ assert( !"gbxutilacfr::Tracer::toString() should never get to default" );
+ }
+}
+
+} // namespace
Modified: gearbox/trunk/src/gbxutilacfr/tracer.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/tracer.h 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/tracer.h 2008-11-07 01:35:28 UTC (rev 359)
@@ -15,6 +15,43 @@
namespace gbxutilacfr {
+//! Types of traced information
+enum TraceType {
+ //! Information
+ InfoTrace=0,
+ //! Warning
+ WarningTrace,
+ //! Error
+ ErrorTrace,
+ //! Debug statement
+ DebugTrace,
+ //! Use this index to find out the maximum verbosity among all trace types to
+ //! a particular destination.
+ AnyTrace,
+ //! Number of trace types
+ NumberOfTraceTypes,
+};
+
+//! Returns a string corresponding to the enum element.
+std::string toString( TraceType type );
+
+//! Types of destinations for traced information.
+enum DestinationType {
+ //! Write to stardard display
+ ToDisplay=0,
+ //! Send over the network, details specific to Tracer implementation
+ ToNetwork,
+ //! Write to SysLog on Unix, EventLog on windows
+ ToLog,
+ //! Write to a file
+ ToFile,
+ //! Use this index to request the maximum verbosity of a particular type among
+ //! all destinations
+ ToAny,
+ //! Number of destination types
+ NumberOfDestinationTypes
+};
+
//!
//! @brief Local and remote tracing.
//!
@@ -45,8 +82,8 @@
//! }
//! @endverbatim
//!
-//! Enum gbxutilacfr::Tracer::TraceType defines types of traced
-//! information. Enum gbxutilacfr::Tracer::DestinationType defines possible
+//! Enum gbxutilacfr::TraceType defines types of traced
+//! information. Enum gbxutilacfr::DestinationType defines possible
//! tracer destinations are. Verbosity levels range from 0 (nothing) to
//! 10 (everything). The built-in defaults are as follows:
//! @verbatim
@@ -64,44 +101,6 @@
public:
virtual ~Tracer() {};
- //! Types of traced information
- enum TraceType {
- //! Information
- InfoTrace=0,
- //! Warning
- WarningTrace,
- //! Error
- ErrorTrace,
- //! Debug statement
- DebugTrace,
- //! Use this index to find out the maximum verbosity among all trace types to
- //! a particular destination.
- AnyTrace,
- //! Number of trace types
- NumberOfTraceTypes,
- //! Other
- //! (not used by orcaice tracers, so it's verbosity level is not stored in
- //! our matrix, so it's safe to have it larger than NumberOfTraceTypes)
- OtherTrace
- };
-
- //! Types of destinations for traced information.
- enum DestinationType {
- //! Write to stardard display
- ToDisplay=0,
- //! Send over the network, details specific to Tracer implementation
- ToNetwork,
- //! Write to SysLog on Unix, EventLog on windows
- ToLog,
- //! Write to a file
- ToFile,
- //! Use this index to request the maximum verbosity of a particular type among
- //! all destinations
- ToAny,
- //! Number of destination types
- NumberOfDestinationTypes
- };
-
struct Config
{
//! array of verbosity levels
@@ -135,38 +134,6 @@
//! usage.
virtual int verbosity( TraceType traceType, DestinationType destType=ToAny ) const = 0;
- static std::string toString( Tracer::TraceType type )
- {
- switch ( type )
- {
- case Tracer::InfoTrace :
- return "info";
- case Tracer::WarningTrace :
- return "warn";
- case Tracer::ErrorTrace :
- return "error";
- case Tracer::DebugTrace :
- return "debug";
- default :
- return "other";
- }
- };
-
- static Tracer::TraceType toTraceType( const std::string& category )
- {
- if ( category==std::string("info") )
- return Tracer::InfoTrace;
- else if ( category==std::string("warn") )
- return Tracer::WarningTrace;
- else if ( category==std::string("error") )
- return Tracer::ErrorTrace;
- else if ( category==std::string("debug") )
- return Tracer::DebugTrace;
- else
- return Tracer::OtherTrace;
- };
-
-
//! @b EXPERIMENTAL. Sets debug level for an individual subsystem.
//! Only debug-to-display is supported.
virtual void setLevel( const std::string &subsystem, int level=0 ) {};
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.cpp 2008-11-07 01:35:28 UTC (rev 359)
@@ -53,6 +53,12 @@
throw Exception( ERROR_INFO, "TrivialStatus: this implementation of Status does not store status of the subsystems" );
}
+SubsystemState
+TrivialStatus::infrastructureState()
+{
+ throw Exception( ERROR_INFO, "TrivialStatus: this implementation of Status does not store infrastructure state" );
+}
+
void
TrivialStatus::setMaxHeartbeatInterval( const std::string& subsystem, double maxHeartbeatIntervalSec )
{
@@ -118,13 +124,13 @@
TrivialStatus::internalSetStatus( const std::string& subsystemName, gbxutilacfr::SubsystemState state,
gbxutilacfr::SubsystemHealth health, const std::string& msg )
{
+// cout<<"DEBUG: state="<<state<<" health="<<health<<" msg="<<msg<<endl;
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 )
@@ -144,8 +150,11 @@
// give tracer feedback on status
if ( traceHealth )
{
+ // ugly stuff because we don't remember our state.
+ string stateString = (state<0) ? "Unchanged" : gbxutilacfr::toString(state);
string trace = "Subsystem '"+subsystemName
- +"' status="+gbxutilacfr::toString(state)+"/"+gbxutilacfr::toString(health);
+ +"' status="+stateString+"/"+gbxutilacfr::toString(health);
+
if ( !msg.empty() )
trace =+ ": "+msg;
switch ( health )
@@ -174,4 +183,22 @@
// cannot determine stalls because we are not tracking subsystem status
}
+void
+TrivialStatus::compInitialising()
+{
+ tracer_.info( "Component infrastructure changed state to Initialising." );
}
+
+void
+TrivialStatus::compWorking()
+{
+ tracer_.info( "Component infrastructure changed state to Working." );
+}
+
+void
+TrivialStatus::compFinalising()
+{
+ tracer_.info( "Component infrastructure changed state to Finalising." );
+}
+
+}
Modified: gearbox/trunk/src/gbxutilacfr/trivialstatus.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/trivialstatus.h 2008-11-07 01:35:28 UTC (rev 359)
@@ -33,10 +33,12 @@
virtual void addSubsystem( const std::string& subsystem, double maxHeartbeatIntervalSec=-1.0 );
virtual void removeSubsystem( const std::string& subsystem );
- //! does not keep track of subsystems, returns empty vector.
+ //! Does not keep track of subsystems, returns empty vector.
virtual std::vector<std::string> subsystems();
- //! does not keep track of status, throws Exception on any query
+ //! Does not keep track of status, throws Exception on any query
virtual SubsystemStatus subsystemStatus( const std::string& subsystem );
+ //! Does not keep track of infrastructure state, throws Exception on any query
+ virtual SubsystemState infrastructureState();
virtual void setMaxHeartbeatInterval( const std::string& subsystem, double interval );
virtual void setSubsystemStatus( const std::string& subsystem, SubsystemState state, SubsystemHealth health, const std::string& msg="" );
@@ -51,6 +53,9 @@
virtual void heartbeat( const std::string& subsystem );
virtual void message( const std::string& subsystem, const std::string& msg );
+ virtual void compInitialising();
+ virtual void compWorking();
+ virtual void compFinalising();
virtual void process();
private:
Modified: gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp 2008-11-07 01:35:28 UTC (rev 359)
@@ -18,10 +18,10 @@
TrivialTracer::TrivialTracer( int debug, int info, int warn, int error )
{
- traceLevels_[Tracer::InfoTrace] = info;
- traceLevels_[Tracer::WarningTrace] = warn;
- traceLevels_[Tracer::ErrorTrace] = error;
- traceLevels_[Tracer::DebugTrace] = debug;
+ traceLevels_[InfoTrace] = info;
+ traceLevels_[WarningTrace] = warn;
+ traceLevels_[ErrorTrace] = error;
+ traceLevels_[DebugTrace] = debug;
}
void
@@ -33,35 +33,35 @@
void
TrivialTracer::info( const std::string &message, int level )
{
- if ( traceLevels_[Tracer::InfoTrace] >= level )
+ if ( traceLevels_[InfoTrace] >= level )
cout << "info: " << message << endl;
}
void
TrivialTracer::warning( const std::string &message, int level )
{
- if ( traceLevels_[Tracer::WarningTrace] >= level )
+ if ( traceLevels_[WarningTrace] >= level )
cout << "warn: " << message << endl;
}
void
TrivialTracer::error( const std::string &message, int level )
{
- if ( traceLevels_[Tracer::ErrorTrace] >= level )
+ if ( traceLevels_[ErrorTrace] >= level )
cout << "error: " << message << endl;
}
void
TrivialTracer::debug( const std::string &message, int level )
{
- if ( traceLevels_[Tracer::DebugTrace] >= level )
+ if ( traceLevels_[DebugTrace] >= level )
cout << "debug: " << message << endl;
}
int
TrivialTracer::verbosity( TraceType traceType, DestinationType destType ) const
{
- assert( traceType >= 0 && traceType <= Tracer::NumberOfTraceTypes );
+ assert( traceType >= 0 && traceType <= NumberOfTraceTypes );
return traceLevels_[traceType];
}
Modified: gearbox/trunk/src/gbxutilacfr/trivialtracer.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialtracer.h 2008-10-30 07:10:32 UTC (rev 358)
+++ gearbox/trunk/src/gbxutilacfr/trivialtracer.h 2008-11-07 01:35:28 UTC (rev 359)
@@ -37,11 +37,11 @@
virtual void warning( const std::string &message, int level=1 );
virtual void error( const std::string &message, int level=1 );
virtual void debug( const std::string &message, int level=1 );
- virtual int verbosity( TraceType traceType, DestinationType destType=Tracer::ToAny ) const;
+ virtual int verbosity( TraceType traceType, DestinationType destType=ToAny ) const;
private:
- int traceLevels_[Tracer::NumberOfTraceTypes];
+ int traceLevels_[NumberOfTraceTypes];
};
} // namespace
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|