LRAUV  revA
Handler Class Reference

Base class for "handlers" of Components. More...

#include <Handler.h>

Inheritance diagram for Handler:
Collaboration diagram for Handler:

Public Member Functions

 Handler (Component &inComponent, const Str &name, bool idleThread=false)
 Constructor. More...
 
virtual ~Handler ()
 Destructor. More...
 
virtual void run ()
 Run the component itself. More...
 
virtual bool continueLoop (void)
 Supplemental end conditions. More...
 
virtual void runOnce (void)
 Virtual function run only on first iteration of handler. More...
 
virtual void runBetween (void)
 Virtual function run after the first iteration of the handler. More...
 
virtual void shutdown (void)
 Stop the handler (and uninit the component) More...
 
virtual bool isRunning (void)
 True if handler is running. More...
 
const StrgetName ()
 
void setAsLogHandler (bool logHandler)
 
void setAsControlLoopHandler (bool controlLoopHandler)
 

Static Public Member Functions

static bool IsFastSimAllowed ()
 

Protected Attributes

Componentcomponent_
 The "handled" Component. More...
 
Timestamp componentStartTime_
 Keep track of when the component is supposed to start next. More...
 
Logger logger_
 
PCallerpCaller_
 Used for making protected calls. More...
 
bool running_
 

Static Protected Attributes

static const Timespan SMALL_INTERVAL = Timespan::FromMicros( 800 )
 

Private Member Functions

 Handler (const Handler &old)
 

Private Attributes

bool firstLoop_
 true at object initialization, false after the first iteration through the run() loop. More...
 
bool controlLoopHandler_
 
bool logHandler_
 

Detailed Description

Base class for "handlers" of Components.

Trying to make equivalence between Components which run within another thread (control, supervisor) and those that run in their own thread. ThreadHandler derives from this class. Decided that ThreadHandler would "have a" Component rather than "be a" Component.

Basic non-threaded component handler.

Essentially a glorified while(1) loop. Relies on the component to indicate when it's going to yield through Component::completed flag.

Should be moderately extensible through its virtual functions. Run() does the following:

  1. component.initialize()
  2. runOnce()
  3. component.run()
  4. check continueLoop(), if true continue, if false jump to end
  5. runBetween()
  6. component.run()
  7. check continueLoop()
  8. ...
  9. At end, component.uninitialize()

So runonce() can be used to initialize the Handler itself And runBetween() can be used to update the Handler, sleep, wait for a signal or condition variable, etc

Constructor & Destructor Documentation

Handler::Handler ( Component inComponent,
const Str name,
bool  idleThread = false 
)

Constructor.

Parameters
inComponentThe component being handled.
nameName of the component (fed to its logger_)
idleThreadIf true, run thread at idle priority
Handler::~Handler ( )
virtual

Destructor.

References pCaller_.

Handler::Handler ( const Handler old)
private

Member Function Documentation

bool Handler::continueLoop ( void  )
virtual

Supplemental end conditions.

Reimplemented in ThreadHandler.

References component_, and Component::isCompleted().

Referenced by ThreadHandler::continueLoop(), and run().

const Str& Handler::getName ( void  )
inline
static bool Handler::IsFastSimAllowed ( )
inlinestatic
virtual bool Handler::isRunning ( void  )
inlinevirtual

True if handler is running.

Reimplemented in MultiHandler.

References running_.

Referenced by ComponentRegistry::StartThreads().

void Handler::run ( void  )
virtual
void Handler::runOnce ( void  )
virtual

Virtual function run only on first iteration of handler.

Protected methods.

References componentStartTime_, and Timestamp::Now().

Referenced by run().

void Handler::setAsControlLoopHandler ( bool  controlLoopHandler)
inline
void Handler::setAsLogHandler ( bool  logHandler)
inline

References logHandler_.

Referenced by ComponentRegistry::Insert().

void Handler::shutdown ( void  )
virtual

Member Data Documentation

Timestamp Handler::componentStartTime_
protected

Keep track of when the component is supposed to start next.

Referenced by runBetween(), and runOnce().

bool Handler::controlLoopHandler_
private
bool Handler::firstLoop_
private

true at object initialization, false after the first iteration through the run() loop.

Referenced by run().

Logger Handler::logger_
protected
bool Handler::logHandler_
private

Referenced by runBetween(), and setAsLogHandler().

PCaller* Handler::pCaller_
protected

Used for making protected calls.

Referenced by MultiHandler::addComponent(), run(), MultiHandler::runNext(), MultiHandler::shutdown(), and ~Handler().

bool Handler::running_
protected

Referenced by isRunning(), and run().

const Timespan Handler::SMALL_INTERVAL = Timespan::FromMicros( 800 )
staticprotected

Referenced by runBetween().


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