SurgSim::Devices::FilteredDevice Class Reference

A DeviceInterface connected in series with one or more DeviceFilters. Useful for serialization. More...

`#include <SurgSim/Devices/DeviceFilters/FilteredDevice.h>`

Inheritance diagram for SurgSim::Devices::FilteredDevice:

## Public Member Functions

| FilteredDevice (const std::string &name)
| Constructor. More...
| SURGSIM_CLASSNAME (SurgSim::Devices::FilteredDevice)
virtual | ~FilteredDevice ()
| Destructor. More...
std::string | getName () const override
| Return a (hopefully unique) device name. More...
bool | initialize () override
| Fully initialize the device. More...
bool | isInitialized () const override
bool | addInputConsumer (std::shared_ptr< Input::InputConsumerInterface > inputConsumer) override
bool | removeInputConsumer (std::shared_ptr< Input::InputConsumerInterface > inputConsumer) override
void | clearInputConsumers () override
| Removes all InputConsumers. More...
bool | setOutputProducer (std::shared_ptr< Input::OutputProducerInterface > outputProducer) override
bool | removeOutputProducer (std::shared_ptr< Input::OutputProducerInterface > outputProducer) override
bool | hasOutputProducer () override
| Query if this object has output producer. More...
void | clearOutputProducer () override
| Removes any OutputProducer. More...
void | setDevice (std::shared_ptr< Input::DeviceInterface > device)
| Sets the raw/base device. More...
void | addFilter (std::shared_ptr< DeviceFilter > filter)
| Adds a DeviceFilter. More...
const std::vector< std::shared_ptr< Input::DeviceInterface > > & | getDevices () const
bool | setDevices (const std::vector< std::shared_ptr< Input::DeviceInterface >> &devices)
| Sets the devices. More...
Public Member Functions inherited from SurgSim::Input::DeviceInterface
virtual | ~DeviceInterface ()
| Virtual destructor (empty). More...
virtual std::string | getClassName () const =0
| The class name for this class. More...
virtual bool | addInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer)=0
| Adds an input consumer that will be notified when the application input state is updated. More...
virtual bool | removeInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer)=0
| Removes an input consumer previously added via addInputConsumer. More...
virtual bool | setOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer)=0
| Sets an output producer that will be asked for application output state when the device needs it. More...
virtual bool | removeOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer)=0
| Removes an output producer previously added via setOutputProducer. More...
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

## Private Member Functions

bool | finalize () override
| Finalize (de-initialize) the device. More...
void | doFinalize ()
| Implements the finalize functionality. More...

## Private Attributes

std::string | m_name
| The name of this device. More...
bool | m_initialized
| true if initialized and not finalized. More...
std::vector< std::shared_ptr< Input::DeviceInterface > > | m_devices
| The devices. More...
boost::shared_mutex | m_deviceMutex
| The mutex to protect access to the devices. More...
std::shared_ptr< Framework::Logger > | m_logger
| The logger. 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 DeviceInterface connected in series with one or more DeviceFilters. Useful for serialization.

## Constructor & Destructor Documentation

## FilteredDevice()

SurgSim::Devices::FilteredDevice::FilteredDevice | ( | const std::string & | name | ) |

explicit

Constructor.

Parameters

  name | Name of this device.

## ~FilteredDevice()

SurgSim::Devices::FilteredDevice::~FilteredDevice | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## addFilter()

void SurgSim::Devices::FilteredDevice::addFilter | ( | std::shared_ptr< DeviceFilter > | filter | ) |

Adds a DeviceFilter.

The first filter that is added will be connected to the raw/base device. The last filter that is added will interface with InputConsumers and/or an OutputProducer. Any filters added in-between will be connected in order.

Parameters

  filter | A DeviceFilter.

## addInputConsumer()

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

override

## clearInputConsumers()

void SurgSim::Devices::FilteredDevice::clearInputConsumers | ( |  | ) |

override virtual

Removes all InputConsumers.

Implements SurgSim::Input::DeviceInterface.

## clearOutputProducer()

void SurgSim::Devices::FilteredDevice::clearOutputProducer | ( |  | ) |

override virtual

Removes any OutputProducer.

Implements SurgSim::Input::DeviceInterface.

## doFinalize()

void SurgSim::Devices::FilteredDevice::doFinalize | ( |  | ) |

private

Implements the finalize functionality.

## finalize()

bool SurgSim::Devices::FilteredDevice::finalize | ( |  | ) |

override private virtual

Finalize (de-initialize) the device.

Implements SurgSim::Input::DeviceInterface.

## getDevices()

const std::vector< std::shared_ptr< Input::DeviceInterface > > & SurgSim::Devices::FilteredDevice::getDevices | ( |  | ) | const

Returns
  All devices.

## getName()

std::string SurgSim::Devices::FilteredDevice::getName | ( |  | ) | const

override virtual

Return a (hopefully unique) device name.

Implements SurgSim::Input::DeviceInterface.

## hasOutputProducer()

bool SurgSim::Devices::FilteredDevice::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.

## initialize()

bool SurgSim::Devices::FilteredDevice::initialize | ( |  | ) |

override virtual

Fully initialize the device.

When the manager object creates the device, the internal state of the device usually isn't fully initialized yet. This method performs any needed initialization.

Implements SurgSim::Input::DeviceInterface.

## isInitialized()

bool SurgSim::Devices::FilteredDevice::isInitialized | ( |  | ) | const

override virtual

Returns
  true if the device has been initialized and has not yet been finalized.

Implements SurgSim::Input::DeviceInterface.

## removeInputConsumer()

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

override

## removeOutputProducer()

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

override

## setDevice()

void SurgSim::Devices::FilteredDevice::setDevice | ( | std::shared_ptr< Input::DeviceInterface > | device | ) |

Sets the raw/base device.

Parameters

  device | The device connected to the filter(s).

## setDevices()

bool SurgSim::Devices::FilteredDevice::setDevices | ( | const std::vector< std::shared_ptr< Input::DeviceInterface >> & | devices | ) |

Sets the devices.

Parameters

  devices | All the devices.

Returns
  true on success

## setOutputProducer()

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

override

## SURGSIM_CLASSNAME()

SurgSim::Devices::FilteredDevice::SURGSIM_CLASSNAME | ( | SurgSim::Devices::FilteredDevice |  | ) |

## Member Data Documentation

## m_deviceMutex

boost::shared_mutex SurgSim::Devices::FilteredDevice::m_deviceMutex

private

The mutex to protect access to the devices.

## m_devices

std::vector<std::shared_ptr<Input::DeviceInterface> > SurgSim::Devices::FilteredDevice::m_devices

private

The devices.

m_devices.back() will be connected to any InputComponent or OutputComponent. m_devices.front() is the raw/base device to be filtered. If this contains more than one element, all but the front element are DeviceFilters.

## m_initialized

bool SurgSim::Devices::FilteredDevice::m_initialized

private

true if initialized and not finalized.

## m_logger

std::shared_ptr<Framework::Logger> SurgSim::Devices::FilteredDevice::m_logger

private

The logger.

## m_name

std::string SurgSim::Devices::FilteredDevice::m_name

private

The name of this device.

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

- SurgSim/Devices/DeviceFilters/FilteredDevice.h
- SurgSim/Devices/DeviceFilters/FilteredDevice.cpp