Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
driver_base::Driver Class Referenceabstract

#include <driver.h>

Public Types

typedef char state_t
 

Public Member Functions

void clearRecoveryComplete ()
 
bool close ()
 
 Driver ()
 
virtual std::string getID ()=0
 
bool getRecoveryComplete ()
 
state_t getState ()
 
const std::string getStateName ()
 
const std::string getStatusMessage ()
 
bool getStatusOk ()
 
bool goClosed ()
 
bool goOpened ()
 
bool goRunning ()
 
bool goState (state_t target)
 
bool isClosed ()
 
bool isOpened ()
 
bool isRunning ()
 
bool isStopped ()
 
bool lowerState (state_t target)
 
bool open ()
 
bool raiseState (state_t target)
 
void setPostOpenHook (hookFunction f)
 
void setStatusMessage (const std::string &msg, bool ok=false, bool recovery_complete=false)
 
void setStatusMessagef (const char *format,...)
 
bool start ()
 
bool stop ()
 
virtual ~Driver ()
 

Static Public Member Functions

static const std::stringgetStateName (state_t s)
 

Public Attributes

boost::recursive_mutex mutex_
 

Static Public Attributes

static const state_t CLOSED = 0
 
static const state_t OPENED = 1
 
static const state_t RUNNING = 2
 

Protected Types

typedef boost::function< void() > hookFunction
 

Protected Member Functions

virtual void doClose ()=0
 
virtual void doOpen ()=0
 
virtual void doStart ()=0
 
virtual void doStop ()=0
 

Protected Attributes

hookFunction postOpenHook
 
state_t state_
 

Private Member Functions

const std::stringgetTransitionName (void(Driver::*transition)())
 
bool tryTransition (state_t target, void(Driver::*transition)())
 

Private Attributes

std::string status_message_
 
boost::mutex status_message_mutex_
 
bool status_ok_
 
bool status_recovery_complete_
 

Detailed Description

State transition functions assume that they are called from the correct state. It is the caller's responsibility to check that the state is correct. The Driver mutex_ should always be locked by the caller before checking the current state and throughout the call to the transition function.

State should not change between calls to the transition function except for transitions from RUNNING to STOPPED. The device must hold its lock while doing this transition to allow the caller to enforce that stop is only called from the RUNNING state.

Transitions may fail. It is the caller's responsibility to check success by looking at the device's state_. After a failure, the device can set itself into any state. For example, if a call to start() fails, the device may end up in the CLOSED state.

Definition at line 100 of file driver.h.

Member Typedef Documentation

◆ hookFunction

typedef boost::function< void() > driver_base::Driver::hookFunction
protected

Definition at line 145 of file driver.h.

◆ state_t

Definition at line 135 of file driver.h.

Constructor & Destructor Documentation

◆ Driver()

driver_base::Driver::Driver ( )
inline

Definition at line 308 of file driver.h.

◆ ~Driver()

virtual driver_base::Driver::~Driver ( )
inlinevirtual

Definition at line 309 of file driver.h.

Member Function Documentation

◆ clearRecoveryComplete()

void driver_base::Driver::clearRecoveryComplete ( )
inline

Definition at line 321 of file driver.h.

◆ close()

bool driver_base::Driver::close ( )
inline

Definition at line 257 of file driver.h.

◆ doClose()

virtual void driver_base::Driver::doClose ( )
protectedpure virtual

◆ doOpen()

virtual void driver_base::Driver::doOpen ( )
protectedpure virtual

◆ doStart()

virtual void driver_base::Driver::doStart ( )
protectedpure virtual

◆ doStop()

virtual void driver_base::Driver::doStop ( )
protectedpure virtual

◆ getID()

virtual std::string driver_base::Driver::getID ( )
pure virtual

◆ getRecoveryComplete()

bool driver_base::Driver::getRecoveryComplete ( )
inline

Definition at line 316 of file driver.h.

◆ getState()

state_t driver_base::Driver::getState ( )
inline

Definition at line 283 of file driver.h.

◆ getStateName() [1/2]

const std::string driver_base::Driver::getStateName ( )
inline

Definition at line 288 of file driver.h.

◆ getStateName() [2/2]

static const std::string& driver_base::Driver::getStateName ( state_t  s)
inlinestatic

Definition at line 293 of file driver.h.

◆ getStatusMessage()

const std::string driver_base::Driver::getStatusMessage ( )
inline

Definition at line 326 of file driver.h.

◆ getStatusOk()

bool driver_base::Driver::getStatusOk ( )
inline

Definition at line 311 of file driver.h.

◆ getTransitionName()

const std::string& driver_base::Driver::getTransitionName ( void(Driver::*)()  transition)
inlineprivate

Definition at line 356 of file driver.h.

◆ goClosed()

bool driver_base::Driver::goClosed ( )
inline

Definition at line 237 of file driver.h.

◆ goOpened()

bool driver_base::Driver::goOpened ( )
inline

Definition at line 232 of file driver.h.

◆ goRunning()

bool driver_base::Driver::goRunning ( )
inline

Definition at line 227 of file driver.h.

◆ goState()

bool driver_base::Driver::goState ( state_t  target)
inline

Definition at line 168 of file driver.h.

◆ isClosed()

bool driver_base::Driver::isClosed ( )
inline

Definition at line 272 of file driver.h.

◆ isOpened()

bool driver_base::Driver::isOpened ( )
inline

Definition at line 267 of file driver.h.

◆ isRunning()

bool driver_base::Driver::isRunning ( )
inline

Definition at line 262 of file driver.h.

◆ isStopped()

bool driver_base::Driver::isStopped ( )
inline

Definition at line 277 of file driver.h.

◆ lowerState()

bool driver_base::Driver::lowerState ( state_t  target)
inline

Definition at line 204 of file driver.h.

◆ open()

bool driver_base::Driver::open ( )
inline

Definition at line 252 of file driver.h.

◆ raiseState()

bool driver_base::Driver::raiseState ( state_t  target)
inline

Definition at line 181 of file driver.h.

◆ setPostOpenHook()

void driver_base::Driver::setPostOpenHook ( hookFunction  f)
inline

Definition at line 155 of file driver.h.

◆ setStatusMessage()

void driver_base::Driver::setStatusMessage ( const std::string msg,
bool  ok = false,
bool  recovery_complete = false 
)
inline

Definition at line 335 of file driver.h.

◆ setStatusMessagef()

void driver_base::Driver::setStatusMessagef ( const char *  format,
  ... 
)
inline

Definition at line 344 of file driver.h.

◆ start()

bool driver_base::Driver::start ( )
inline

Definition at line 247 of file driver.h.

◆ stop()

bool driver_base::Driver::stop ( )
inline

Definition at line 242 of file driver.h.

◆ tryTransition()

bool driver_base::Driver::tryTransition ( state_t  target,
void(Driver::*)()  transition 
)
inlineprivate
Todo:
print the exception message better.

Definition at line 376 of file driver.h.

Member Data Documentation

◆ CLOSED

const state_t driver_base::Driver::CLOSED = 0
static
Todo:
should this be protected?

Definition at line 164 of file driver.h.

◆ mutex_

boost::recursive_mutex driver_base::Driver::mutex_

Definition at line 162 of file driver.h.

◆ OPENED

const state_t driver_base::Driver::OPENED = 1
static

Definition at line 165 of file driver.h.

◆ postOpenHook

hookFunction driver_base::Driver::postOpenHook
protected

Definition at line 146 of file driver.h.

◆ RUNNING

const state_t driver_base::Driver::RUNNING = 2
static

Definition at line 166 of file driver.h.

◆ state_

state_t driver_base::Driver::state_
protected

Definition at line 138 of file driver.h.

◆ status_message_

std::string driver_base::Driver::status_message_
private

Definition at line 149 of file driver.h.

◆ status_message_mutex_

boost::mutex driver_base::Driver::status_message_mutex_
private

Definition at line 150 of file driver.h.

◆ status_ok_

bool driver_base::Driver::status_ok_
private

Definition at line 151 of file driver.h.

◆ status_recovery_complete_

bool driver_base::Driver::status_recovery_complete_
private

Definition at line 152 of file driver.h.


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


driver_base
Author(s): Blaise Gassend
autogenerated on Wed Mar 2 2022 00:11:50