![]() |
A class that implements some common management code on top of the DeviceInterface. More...
#include <SurgSim/Input/CommonDevice.h>
Public Member Functions | |
CommonDevice (const std::string &name) | |
Constructor. More... | |
CommonDevice (const std::string &name, const DataStructures::DataGroup &inputData) | |
Constructor. More... | |
CommonDevice (const std::string &name, DataStructures::DataGroup &&inputData) | |
Constructor. More... | |
virtual | ~CommonDevice () |
Destructor. More... | |
std::string | getName () const override |
Return a (hopefully unique) device name. More... | |
std::string | getClassName () const override |
The class name for this class. More... | |
void | setNameForCallback (const std::string &name) |
Set the name used for calling the input consumers and output producer. More... | |
std::string | getNameForCallback () const |
Get the name used for calling the input consumers and output producer. More... | |
bool | addInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer) override |
Adds an input consumer that will be notified when the application input state is updated. More... | |
bool | removeInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer) override |
Removes an input consumer previously added via addInputConsumer. More... | |
void | clearInputConsumers () override |
Removes all InputConsumers. More... | |
bool | setOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer) override |
Sets an output producer that will be asked for application output state when the device needs it. More... | |
bool | removeOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer) override |
Removes an output producer previously added via setOutputProducer. More... | |
bool | hasOutputProducer () override |
Query if this object has output producer. More... | |
void | clearOutputProducer () override |
Removes any OutputProducer. More... | |
![]() | |
virtual | ~DeviceInterface () |
Virtual destructor (empty). More... | |
virtual bool | initialize ()=0 |
Fully initialize the device. More... | |
virtual bool | isInitialized () const =0 |
![]() | |
Accessible () | |
Default Constructor. More... | |
~Accessible () | |
Destructor. More... | |
template<class T > | |
T | getValue (const std::string &name) const |
Retrieves the value with the name by executing the getter if it is found and tries to convert it to the given type. More... | |
boost::any | getValue (const std::string &name) const |
Retrieves the value with the name by executing the getter if it is found. More... | |
template<class T > | |
bool | getValue (const std::string &name, T *value) const |
Retrieves the value with the name by executing the getter if it is found, and converts it to the type of the output parameter. More... | |
void | setValue (const std::string &name, const boost::any &value) |
Sets a value of a property that has setter. More... | |
bool | isReadable (const std::string &name) const |
Check whether a property is readable. More... | |
bool | isWriteable (const std::string &name) const |
Check whether a property is writable. More... | |
void | setGetter (const std::string &name, GetterType func) |
Sets a getter for a given property. More... | |
void | setSetter (const std::string &name, SetterType func) |
Sets a setter for a given property. More... | |
void | setAccessors (const std::string &name, GetterType getter, SetterType setter) |
Sets the accessors getter and setter in one function. More... | |
void | removeAccessors (const std::string &name) |
Removes all the accessors (getter and setter) for a given property. More... | |
void | forwardProperty (const std::string &name, const Accessible &target, const std::string &targetProperty) |
Adds a property with the given name that uses the targets accessors, in effect forwarding the value to the target. More... | |
void | setSerializable (const std::string &name, EncoderType encoder, DecoderType decoder) |
Sets the functions used to convert data from and to a YAML::Node. More... | |
void | setDecoder (const std::string &name, DecoderType decoder) |
Sets the functions used to convert data from a YAML::Node. More... | |
YAML::Node | encode () const |
Encode this Accessible to a YAML::Node. More... | |
void | decode (const YAML::Node &node, const std::vector< std::string > &ignoredProperties=std::vector< std::string >()) |
Decode this Accessible from a YAML::Node, will throw an exception if the data type cannot be converted. More... | |
template<> | |
boost::any | getValue (const std::string &name) const |
Protected Member Functions | |
virtual void | pushInput () |
Push application input to consumers. More... | |
virtual bool | pullOutput () |
Pull application output from a producer. More... | |
DataStructures::DataGroup & | getInputData () |
Getter for the input data DataGroup. More... | |
const DataStructures::DataGroup & | getOutputData () const |
Getter for the output data DataGroup. More... | |
Private Attributes | |
const std::string | m_name |
std::string | m_nameForCallback |
The name used for the callbacks, defaults to the device name. More... | |
DataStructures::DataGroup | m_inputData |
The data the device is providing to its input consumers. More... | |
DataStructures::DataGroup | m_outputData |
The data the output producer (if any) is providing to the device. More... | |
std::vector< std::weak_ptr< InputConsumerInterface > > | m_inputConsumerList |
The list of input consumers. More... | |
std::weak_ptr< OutputProducerInterface > | m_outputProducer |
The output producer, if any. More... | |
boost::mutex | m_consumerProducerMutex |
The mutex that protects the consumers and the producer. More... | |
Additional Inherited Members | |
![]() | |
typedef std::function< boost::any(void)> | GetterType |
typedef std::function< void(boost::any)> | SetterType |
typedef std::function< YAML::Node(void)> | EncoderType |
typedef std::function< void(const YAML::Node *)> | DecoderType |
![]() | |
typedef ObjectFactory1< DeviceInterface, std::string > | FactoryType |
![]() | |
static FactoryType & | getFactory () |
A class that implements some common management code on top of the DeviceInterface.
Practically every class that implements DeviceInterface will likely want to inherit from CommonDevice.
|
explicit |
Constructor.
Sets the input data to an empty DataGroup.
name | The name associated with the input device. |
SurgSim::Input::CommonDevice::CommonDevice | ( | const std::string & | name, |
const DataStructures::DataGroup & | inputData | ||
) |
Constructor.
name | The name associated with the input device. |
inputData | An initial value for the application's input from the device (e.g. pose etc). The concrete device implementation should pass in a DataGroup whose contents has been set up, e.g. by using a DataGroupBuilder, to that device's supported values that it will push to the application. |
SurgSim::Input::CommonDevice::CommonDevice | ( | const std::string & | name, |
DataStructures::DataGroup && | inputData | ||
) |
Constructor.
name | The name associated with the input device. |
inputData | An initial value for the application's input from the device (e.g. pose etc). The concrete device implementation should pass in a DataGroup whose contents has been set up, e.g. by using a DataGroupBuilder, to that device's supported values that it will push to the application. |
|
virtual |
Destructor.
|
overridevirtual |
Adds an input consumer that will be notified when the application input state is updated.
inputConsumer | The input consumer to be added. |
Implements SurgSim::Input::DeviceInterface.
|
overridevirtual |
Removes all InputConsumers.
Implements SurgSim::Input::DeviceInterface.
|
overridevirtual |
Removes any OutputProducer.
Implements SurgSim::Input::DeviceInterface.
|
overridevirtual |
The class name for this class.
Implements SurgSim::Input::DeviceInterface.
|
protected |
Getter for the input data DataGroup.
This function is typically called by friend scaffolds, to get a DataGroup they can modify then set back to the device to send to the device's input consumers.
|
overridevirtual |
Return a (hopefully unique) device name.
Implements SurgSim::Input::DeviceInterface.
std::string SurgSim::Input::CommonDevice::getNameForCallback | ( | ) | const |
Get the name used for calling the input consumers and output producer.
By default, this will be the same as the name of the device that was passed to the constructor.
|
protected |
Getter for the output data DataGroup.
This function is typically called by friend scaffolds, to get the data that the output producer wants to send to the device (and then send that data through the device's SDK). Note that a writable variant is not provided, an output producer registered via setOutputProducer will set the output data.
|
overridevirtual |
Query if this object has output producer.
Implements SurgSim::Input::DeviceInterface.
|
protectedvirtual |
Pull application output from a producer.
|
protectedvirtual |
Push application input to consumers.
|
overridevirtual |
Removes an input consumer previously added via addInputConsumer.
inputConsumer | The input consumer to be removed. |
Implements SurgSim::Input::DeviceInterface.
|
overridevirtual |
Removes an output producer previously added via setOutputProducer.
outputProducer | The output producer to be removed. |
Implements SurgSim::Input::DeviceInterface.
void SurgSim::Input::CommonDevice::setNameForCallback | ( | const std::string & | name | ) |
Set the name used for calling the input consumers and output producer.
By default, this will be the same as the name of the device that was passed to the constructor.
name | The name to be used. |
|
overridevirtual |
Sets an output producer that will be asked for application output state when the device needs it.
Any previously set output producer will be removed.
outputProducer | The output producer to be added. |
Implements SurgSim::Input::DeviceInterface.
|
private |
The mutex that protects the consumers and the producer.
|
private |
The list of input consumers.
|
private |
The data the device is providing to its input consumers.
|
private |
|
private |
The name used for the callbacks, defaults to the device name.
|
private |
The data the output producer (if any) is providing to the device.
|
private |
The output producer, if any.