INTRODUCTION Overview Download and Install Quick Start Documentation Publications NONFRAMEWORK CODE Driver Interfaces Drivers Libraries Utilities FRAMEWORK CODE Interfaces Components Libraries Utilities Full Software Listings DEVELOPER Tutorials Examples Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
libs/orcasystemstatusutil/statusconsumerImpl.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef ORCASYSTEMSTATUSUTIL_STATUS_CONSUMER_IMPL_H 00012 #define ORCASYSTEMSTATUSUTIL_STATUS_CONSUMER_IMPL_H 00013 00014 #include <orcaice/context.h> 00015 #include <orcaifaceimpl/consumerImpl.h> 00016 #include <orca/systemstatus.h> 00017 #include <IceUtil/Mutex.h> 00018 00019 namespace orcasystemstatusutil { 00020 00062 class StatusConsumerImpl : 00063 public orcaifaceimpl::ConsumerImpl<orca::Status,orca::StatusConsumer,orca::StatusData> 00064 { 00065 public: 00066 00067 struct Config 00068 { 00069 Config() 00070 { 00071 resubscribeTimeoutInactive=0; 00072 resubscribeIntervalInactive=15; 00073 resubscribeTimeoutReporting=45; 00074 resubscribeIntervalReporting=5; 00075 resubscribeTimeoutStale=0; 00076 resubscribeIntervalStale=10; 00077 staleTimeout=60; 00078 giveUpTimeout=-1; 00079 } 00080 // If we don't hear for longer than this timeout [sec], try to re-subscribe. 00081 // State dependent. 00082 int resubscribeTimeoutInactive; 00083 int resubscribeTimeoutReporting; 00084 int resubscribeTimeoutStale; 00085 // Don't try to resubscribe more frequently than this interval [sec] 00086 // State dependent. 00087 int resubscribeIntervalInactive; 00088 int resubscribeIntervalReporting; 00089 int resubscribeIntervalStale; 00090 // If we don't hear for longer than this timeout [sec], flag an Stale. 00091 int staleTimeout; 00092 // If we don't hear for longer than this timeout [sec], flag an Inactive. 00093 // TODO: 00094 // assert that if (giveUpTimeout>0), then (giveUpTimeout>staleTimeout) 00095 int giveUpTimeout; 00096 }; 00097 00099 StatusConsumerImpl( const orca::FQComponentName& fqCompName, 00100 const Config& config, 00101 const orcaice::Context& context ); 00102 00104 void subscribe(); 00105 00111 void checkStatus(); 00112 00113 00114 // Polling interface 00115 00118 orca::EstimatedComponentStatus estimatedStatus() const; 00119 00122 orca::FQComponentName name() const; 00123 00124 // bool isResubscribeRequested() const; 00125 00126 // from orcaifaceimpl::ConsumerImpl 00127 // Not part of API of this class. 00128 // 00129 // sends internal events about status changes. 00130 virtual void dataEvent( const orca::StatusData& data ); 00131 00132 protected: 00133 00134 // Event-driven interface to be used by the derived classes 00135 00136 // generated events 00137 00139 virtual void statusRecievedEvent( const orca::FQComponentName& name, const orca::StatusData& ) {}; 00140 00143 virtual void estimateChangedEvent( const orca::EstimatedComponentStatus& ) {}; 00144 00146 virtual void resubscribeRequestedEvent( const orca::EstimatedComponentStatus& ) {}; 00147 00148 private: 00149 // internal state machine transitions 00150 // not thread safe! 00151 void received(); 00152 void timedOut(); 00153 void gaveUp(); 00154 00155 // internal actions 00156 void checkStatus_Inactive( int timeSinceLastReceiveSec, int timeSinceLastSubscribeSec ); 00157 void checkStatus_Reporting( int timeSinceLastReceiveSec, int timeSinceLastSubscribeSec ); 00158 void checkStatus_Stale( int timeSinceLastReceiveSec, int timeSinceLastSubscribeSec ); 00159 00160 // not using Store because we want read/write/evaluate acess to all this data to be atomic. 00161 IceUtil::Mutex dataMutex_; 00162 orca::EstimatedComponentStatus estCompStatus_; 00163 // this is different from the time stamp in statusData_ because it's recorded with the local clock. 00164 IceUtil::Time lastRecieveTime_; 00165 IceUtil::Time lastSubscribeTime_; 00166 00167 Config config_; 00168 }; 00169 typedef IceUtil::Handle<StatusConsumerImpl> StatusConsumerImplPtr; 00170 00171 } 00172 00173 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)