SurgSim::Input::CommonDevice Class Reference

A class that implements some common management code on top of the DeviceInterface. More...

`#include <SurgSim/Input/CommonDevice.h>`

Inheritance diagram for SurgSim::Input::CommonDevice:

## 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...
Public Member Functions inherited from SurgSim::Input::DeviceInterface
virtual | ~DeviceInterface ()
| Virtual destructor (empty). More...
virtual bool | initialize ()=0
| Fully initialize the device. More...
virtual bool | isInitialized () const =0
Public Member Functions inherited from SurgSim::Framework::Accessible
| 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

Public Types inherited from SurgSim::Framework::Accessible
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
Public Types inherited from SurgSim::Framework::FactoryBase1< DeviceInterface, std::string >
typedef ObjectFactory1< DeviceInterface, std::string > | FactoryType
Static Public Member Functions inherited from SurgSim::Framework::FactoryBase1< DeviceInterface, std::string >
static FactoryType & | getFactory ()

## Detailed Description

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.

## Constructor & Destructor Documentation

## CommonDevice() [1/3]

SurgSim::Input::CommonDevice::CommonDevice | ( | const std::string & | name | ) |

explicit

Constructor.

Sets the input data to an empty DataGroup.

Parameters

  name | The name associated with the input device.

## CommonDevice() [2/3]

SurgSim::Input::CommonDevice::CommonDevice | ( | const std::string & | name,
|  | const DataStructures::DataGroup & | inputData
| ) |  |

Constructor.

Parameters

  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.

## CommonDevice() [3/3]

SurgSim::Input::CommonDevice::CommonDevice | ( | const std::string & | name,
|  | DataStructures::DataGroup && | inputData
| ) |  |

Constructor.

Parameters

  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.

## ~CommonDevice()

SurgSim::Input::CommonDevice::~CommonDevice | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## addInputConsumer()

bool SurgSim::Input::CommonDevice::addInputConsumer | ( | std::shared_ptr< InputConsumerInterface > | inputConsumer | ) |

override virtual

Adds an input consumer that will be notified when the application input state is updated.

Parameters

  inputConsumer | The input consumer to be added.

Returns
  true on success, false on failure.

Implements SurgSim::Input::DeviceInterface.

## clearInputConsumers()

void SurgSim::Input::CommonDevice::clearInputConsumers | ( |  | ) |

override virtual

Removes all InputConsumers.

Implements SurgSim::Input::DeviceInterface.

## clearOutputProducer()

void SurgSim::Input::CommonDevice::clearOutputProducer | ( |  | ) |

override virtual

Removes any OutputProducer.

Implements SurgSim::Input::DeviceInterface.

## getClassName()

std::string SurgSim::Input::CommonDevice::getClassName | ( |  | ) | const

override virtual

The class name for this class.

Note
  Use the SURGSIM_CLASSNAME macro in derived classes.

Returns
  The fully namespace qualified name of this class.

Implements SurgSim::Input::DeviceInterface.

## getInputData()

DataStructures::DataGroup & SurgSim::Input::CommonDevice::getInputData | ( |  | ) |

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.

Returns
  A reference to the input data.

## getName()

std::string SurgSim::Input::CommonDevice::getName | ( |  | ) | const

override virtual

Return a (hopefully unique) device name.

Implements SurgSim::Input::DeviceInterface.

## getNameForCallback()

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.

Returns
  The name being used.

## getOutputData()

const DataStructures::DataGroup & SurgSim::Input::CommonDevice::getOutputData | ( |  | ) | const

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.

Returns
  A reference to the output data.

## hasOutputProducer()

bool SurgSim::Input::CommonDevice::hasOutputProducer | ( |  | ) |

override virtual

Query if this object has output producer.

Returns
  true if there is an output producer, false if not.

Implements SurgSim::Input::DeviceInterface.

## pullOutput()

bool SurgSim::Input::CommonDevice::pullOutput | ( |  | ) |

protected virtual

Pull application output from a producer.

## pushInput()

void SurgSim::Input::CommonDevice::pushInput | ( |  | ) |

protected virtual

Push application input to consumers.

## removeInputConsumer()

bool SurgSim::Input::CommonDevice::removeInputConsumer | ( | std::shared_ptr< InputConsumerInterface > | inputConsumer | ) |

override virtual

Removes an input consumer previously added via addInputConsumer.

Parameters

  inputConsumer | The input consumer to be removed.

Implements SurgSim::Input::DeviceInterface.

## removeOutputProducer()

bool SurgSim::Input::CommonDevice::removeOutputProducer | ( | std::shared_ptr< OutputProducerInterface > | outputProducer | ) |

override virtual

Removes an output producer previously added via setOutputProducer.

Parameters

  outputProducer | The output producer to be removed.

Implements SurgSim::Input::DeviceInterface.

## setNameForCallback()

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.

Parameters

  name | The name to be used.

## setOutputProducer()

bool SurgSim::Input::CommonDevice::setOutputProducer | ( | std::shared_ptr< OutputProducerInterface > | outputProducer | ) |

override virtual

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.

Parameters

  outputProducer | The output producer to be added.

Returns
  true on success, false on failure.

Implements SurgSim::Input::DeviceInterface.

## Member Data Documentation

## m_consumerProducerMutex

boost::mutex SurgSim::Input::CommonDevice::m_consumerProducerMutex

private

The mutex that protects the consumers and the producer.

## m_inputConsumerList

std::vector<std::weak_ptr<InputConsumerInterface> > SurgSim::Input::CommonDevice::m_inputConsumerList

private

The list of input consumers.

## m_inputData

DataStructures::DataGroup SurgSim::Input::CommonDevice::m_inputData

private

The data the device is providing to its input consumers.

## m_name

const std::string SurgSim::Input::CommonDevice::m_name

private

## m_nameForCallback

std::string SurgSim::Input::CommonDevice::m_nameForCallback

private

The name used for the callbacks, defaults to the device name.

## m_outputData

DataStructures::DataGroup SurgSim::Input::CommonDevice::m_outputData

private

The data the output producer (if any) is providing to the device.

## m_outputProducer

std::weak_ptr<OutputProducerInterface> SurgSim::Input::CommonDevice::m_outputProducer

private

The output producer, if any.

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

- SurgSim/Input/CommonDevice.h
- SurgSim/Input/CommonDevice.cpp