Classes | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
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:
SurgSim::Input::DeviceInterface LabJackToPoseFilter SurgSim::Device::ForceScale SurgSim::Device::IdentityPoseDevice SurgSim::Device::KeyboardDevice SurgSim::Device::LabJackDevice SurgSim::Device::MouseDevice SurgSim::Device::NovintCommonDevice SurgSim::Device::PhantomDevice SurgSim::Device::PoseIntegrator SurgSim::Device::PoseTransform SurgSim::Device::RawMultiAxisDevice SurgSim::Device::SixenseDevice SurgSim::Device::TrackIRDevice

Classes

struct  State
 

Public Member Functions

 CommonDevice (const std::string &name)
 Constructor. More...
 
 CommonDevice (const std::string &name, const SurgSim::DataStructures::DataGroup &inputData)
 Constructor. More...
 
 CommonDevice (const std::string &name, SurgSim::DataStructures::DataGroup &&inputData)
 Constructor. More...
 
virtual ~CommonDevice ()
 Destructor. More...
 
virtual std::string getName () const override
 Return a (hopefully unique) device name. 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...
 
virtual bool addInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer) override
 Connect this device to an InputConsumerInterface, which will receive the data that comes from this device. More...
 
virtual bool removeInputConsumer (std::shared_ptr< InputConsumerInterface > inputConsumer) override
 Disconnect this device from an InputConsumerInterface, which will no longer receive data from this device. More...
 
virtual bool setOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer) override
 Connect this device to an OutputProducerInterface, which will send data to this device. More...
 
virtual bool removeOutputProducer (std::shared_ptr< OutputProducerInterface > outputProducer) override
 Disconnect this device from an OutputProducerInterface, which will no longer send data to this device. More...
 
virtual bool hasOutputProducer () override
 Getter for whether or not this device is connected with an OutputProducerInterface. More...
 
- Public Member Functions inherited from SurgSim::Input::DeviceInterface
virtual ~DeviceInterface ()
 Virtual destructor (empty). More...
 
virtual bool initialize ()=0
 Fully initialize the device. More...
 

Protected Member Functions

virtual void pushInput ()
 Push application input to consumers. More...
 
virtual bool pullOutput ()
 Pull application output from a producer. More...
 
SurgSim::DataStructures::DataGroupgetInputData ()
 Getter for the input data DataGroup. More...
 
const SurgSim::DataStructures::DataGroupgetOutputData () const
 Getter for the output data DataGroup. More...
 
- Protected Member Functions inherited from SurgSim::Input::DeviceInterface
virtual bool finalize ()=0
 Finalize (de-initialize) the device. More...
 

Private Attributes

const std::string m_name
 
std::string m_nameForCallback
 The name used for the callbacks, defaults to the device name. More...
 
SurgSim::DataStructures::DataGroup m_inputData
 The data the device is providing to its input consumers. More...
 
SurgSim::DataStructures::DataGroup m_outputData
 The data the output producer (if any) is providing to the device. More...
 
std::unique_ptr< Statem_state
 Struct to hide some of the private member variables, PImpl (Pointer to Implementation). More...
 

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

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

Constructor.

Sets the input data to an empty DataGroup.

Parameters
nameThe name associated with the input device.
SurgSim::Input::CommonDevice::CommonDevice ( const std::string &  name,
const SurgSim::DataStructures::DataGroup inputData 
)

Constructor.

Parameters
nameThe name associated with the input device.
inputDataAn 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,
SurgSim::DataStructures::DataGroup &&  inputData 
)

Constructor.

Parameters
nameThe name associated with the input device.
inputDataAn 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 ( )
virtual

Destructor.

Member Function Documentation

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

Connect this device to an InputConsumerInterface, which will receive the data that comes from this device.

Parameters
inputConsumerThe InputConsumerInterface to connect with.
Returns
true if successful

Implements SurgSim::Input::DeviceInterface.

Reimplemented in SurgSim::Device::IdentityPoseDevice.

SurgSim::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.
std::string SurgSim::Input::CommonDevice::getName ( ) const
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.

Returns
The name being used.
const SurgSim::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.
bool SurgSim::Input::CommonDevice::hasOutputProducer ( )
overridevirtual

Getter for whether or not this device is connected with an OutputProducerInterface.

Returns
true if an OutputProducerInterface is connected.

Implements SurgSim::Input::DeviceInterface.

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

Pull application output from a producer.

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

Push application input to consumers.

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

Disconnect this device from an InputConsumerInterface, which will no longer receive data from this device.

Parameters
inputConsumerThe InputConsumerInterface to disconnect from.
Returns
true if successful

Implements SurgSim::Input::DeviceInterface.

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

Disconnect this device from an OutputProducerInterface, which will no longer send data to this device.

Parameters
outputProducerThe OutputProducerInterface to disconnect from.
Returns
true if successful

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.

Parameters
nameThe name to be used.
bool SurgSim::Input::CommonDevice::setOutputProducer ( std::shared_ptr< OutputProducerInterface outputProducer)
overridevirtual

Connect this device to an OutputProducerInterface, which will send data to this device.

Parameters
outputProducerThe OutputProducerInterface to connect with.
Returns
true if successful

Implements SurgSim::Input::DeviceInterface.

Member Data Documentation

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

The data the device is providing to its input consumers.

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

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

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

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

std::unique_ptr<State> SurgSim::Input::CommonDevice::m_state
private

Struct to hide some of the private member variables, PImpl (Pointer to Implementation).

For CommonDevice, we are hiding:

  • The list of input consumers,
  • The output producer, if any, and
  • The mutex that protects the consumers and the producer. The PImpl idiom is being used so that subclasses of CommonDevice will never store device-specific datatypes in member variables. Instead they would store them in the PImpl object, so that the device-specific include file(s) are only included by the subclass's .cpp file. A benefit of this idiom is that any change to the device's API/SDK will not force a recompile of any file including the subclass's .h file. For historical reasons we are not currently using the PImpl object to store all this class's private member variables, as is commonly recommended.

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