Actuator is the base class for all 'actuator'-type devices. More...
#include <Actuator.h>
Public Member Functions | |
Actuator (const std::string name, const std::string description) | |
Create an actuator. More... | |
Actuator (const Actuator &)=delete | |
Actuator (Actuator &&)=delete | |
Actuator & | operator= (const Actuator &)=delete |
Actuator & | operator= (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 Parameter & | GetParameter (const std::string &name) |
Get a parameter by name. More... | |
virtual Parameter & | operator[] (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) |
![]() | |
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 |
![]() | |
const std::string | _name |
const std::string | _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.
twirre::Actuator::Actuator | ( | const std::string | name, |
const std::string | description | ||
) |
Create an actuator.
name | the name this instance will get in TwirreLink |
description | a short description of the type of device this actuator represents |
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
|
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.
|
virtual |
Get a parameter by name.
name | the name of the parameter to get |
|
virtual |
Get multiple parameters by name.
names | the names of the parameters to get |
bool twirre::Actuator::haveParameter | ( | std::string | name | ) |
Check if a parameter exists.
name | the name of the parameter to check |
bool twirre::Actuator::haveParameters | ( | std::vector< std::string > | names | ) |
Check if multiple parameters exist.
names | the names of the parameters to check |
|
virtual |
this forwards to GetParameter(name)