TwirreLink
 All Classes Functions Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
twirre::Actuator Class Referenceabstract

Actuator is the base class for all 'actuator'-type devices. More...

#include <Actuator.h>

Inheritance diagram for twirre::Actuator:
Inheritance graph
[legend]
Collaboration diagram for twirre::Actuator:
Collaboration graph
[legend]

Public Member Functions

 Actuator (const std::string name, const std::string description)
 Create an actuator. More...
 
 Actuator (const Actuator &)=delete
 
 Actuator (Actuator &&)=delete
 
Actuatoroperator= (const Actuator &)=delete
 
Actuatoroperator= (Actuator &&)=delete
 
std::vector< std::string > getAvailableParameters ()
 Get the names of all available parameters. More...
 
bool haveParameter (std::string name)
 Check if a parameter exists. More...
 
bool haveParameters (std::vector< std::string > names)
 Check if multiple parameters exist. More...
 
virtual ParameterGetParameter (const std::string &name)
 Get a parameter by name. More...
 
virtual Parameteroperator[] (const std::string &name)
 this forwards to GetParameter(name) More...
 
virtual std::map< std::string,
Parameter * > 
GetParameters (const std::vector< std::string > &names)
 Get multiple parameters by name. More...
 
void Actuate ()
 Apply the updated parameters. More...
 
void clearActuateLoggerCallback ()
 
void setActuateLoggerCallback (std::function< void(Actuator *, std::map< std::string, Parameter * > &)> cbfn)
 
- Public Member Functions inherited from twirre::Device
 Device (const std::string name, const std::string description)
 
virtual const std::string & getName () const
 
virtual const std::string & getDescription () const
 
virtual std::string ToString (void)
 

Protected Member Functions

virtual void ActuateImpl ()=0
 Update this Actuator using the modified parameters. More...
 
void registerParameter (Parameter *val)
 
void registerParameters (std::vector< Parameter * > parms)
 
void logActuation ()
 

Protected Attributes

std::map< std::string,
Parameter * > 
_parametersList
 
owned_mutex _actuateMutex
 
std::function< void(Actuator
*, std::map< std::string,
Parameter * > &)> 
_actuateLoggerCallback
 
bool _actuateLoggerSet
 
- Protected Attributes inherited from twirre::Device
const std::string _name
 
const std::string _description
 

Detailed Description

Actuator is the base class for all 'actuator'-type devices.

Actuator is thread-safe in such a way that multiple threads can interact with it without requiring external synchronisation. The Actuator will never see an inconsistent/mixed state of parameters.

This safety is implemented using an 'owned_mutex', which keeps track of which thread has currently locked it. Upon setting the first parameter, the thread will take 'ownership' of the mutex, or, if the mutex is already owned by a different thread, wait until ownership is released. Once a thread has ownership, it is free to set additional parameters as required. Upon calling the Actuate() function, ownership is released allowing another thread to interact with the actuator.

Essentially, the Actuator will be locked by a specific thread between setting the first parameter and calling the Actuate() function. Because of this, it is recommended to keep the delay between setting parameters and calling Actuate() as short as possible.

Constructor & Destructor Documentation

twirre::Actuator::Actuator ( const std::string  name,
const std::string  description 
)

Create an actuator.

Parameters
namethe name this instance will get in TwirreLink
descriptiona short description of the type of device this actuator represents

Member Function Documentation

void twirre::Actuator::Actuate ( )

Apply the updated parameters.

The Actuator will get notified that one or more parameters have been updated, giving it the opportunity to react on those changes

virtual void twirre::Actuator::ActuateImpl ( )
protectedpure virtual

Update this Actuator using the modified parameters.

This function must be implemented by a derived class. It will be called inside of the Actuate() function.

Implemented in twirre::SerialActuator.

vector< string > twirre::Actuator::getAvailableParameters ( )

Get the names of all available parameters.

Returns
an array with all available parameter names
Parameter & twirre::Actuator::GetParameter ( const std::string &  name)
virtual

Get a parameter by name.

Parameters
namethe name of the parameter to get
Returns
a reference to the requested parameter (if name is valid), a reference to ErrorValue otherwise
std::map< std::string, Parameter * > twirre::Actuator::GetParameters ( const std::vector< std::string > &  names)
virtual

Get multiple parameters by name.

Parameters
namesthe names of the parameters to get
Returns
a map of names to parameter-pointers is returned. For each requested name, an entry will be present. If no parameter exists with a given name, that name will be mapped to a pointer to ErrorValue in the result.
bool twirre::Actuator::haveParameter ( std::string  name)

Check if a parameter exists.

Parameters
namethe name of the parameter to check
Returns
true if a parameter with that name exists, false otherwise
bool twirre::Actuator::haveParameters ( std::vector< std::string >  names)

Check if multiple parameters exist.

Parameters
namesthe names of the parameters to check
Returns
true if all names exist, false otherwise
Parameter & twirre::Actuator::operator[] ( const std::string &  name)
virtual

this forwards to GetParameter(name)

See Also
GetParameter()

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