Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
SurgSim::Input::InputManager Class Reference

Manager to handle InputComponent and OutputComponent, SceneElement can add these to get input from devices, or even write output to devices. More...

#include <SurgSim/Input/InputManager.h>

Inheritance diagram for SurgSim::Input::InputManager:
SurgSim::Framework::ComponentManager SurgSim::Framework::BasicThread

Public Member Functions

 InputManager ()
 
virtual ~InputManager ()
 
bool addDevice (std::shared_ptr< SurgSim::Input::DeviceInterface > device)
 Adds a device to the manager. More...
 
bool removeDevice (std::shared_ptr< SurgSim::Input::DeviceInterface > device)
 Removes the device described by device. More...
 
int getType () const override
 Returns the type of Manager. More...
 
- Public Member Functions inherited from SurgSim::Framework::ComponentManager
 ComponentManager (const std::string &name="Unknown Component Manager")
 
virtual ~ComponentManager ()
 
bool enqueueAddComponent (const std::shared_ptr< Component > &component)
 Queues a component to be added later. More...
 
bool enqueueRemoveComponent (const std::shared_ptr< Component > &component)
 Queues a component to be removed. More...
 
std::shared_ptr< RuntimegetRuntime () const
 
void setRuntime (std::shared_ptr< Runtime > val)
 
- Public Member Functions inherited from SurgSim::Framework::BasicThread
 BasicThread (const std::string &name="Unknown Thread")
 
virtual ~BasicThread () noexcept(false)
 C++11 introduced noexcept. More...
 
void start (std::shared_ptr< Barrier > startupBarrier=nullptr, bool isSynchronous=false)
 C++11 introduced noexcept. More...
 
void stop ()
 Stopping the execution, blocks until the running thread has actually stopped,. More...
 
void setIdle (bool isIdle)
 Set/Unset the thread in an idle state (doUpdate() called or not in the update() method) More...
 
bool isIdle ()
 Query if this thread is in idle state or not. More...
 
bool isInitialized ()
 Query if this object is initialized. More...
 
bool isRunning () const
 Query if this object is running. More...
 
void operator() ()
 This is what boost::thread executes on thread creation. More...
 
boost::thread & getThread ()
 
std::string getName () const
 
void setRate (double val)
 Set the update rate of the thread. More...
 
bool setSynchronous (bool val)
 Sets the thread to synchronized execution in concert with the startup barrier, the startup barrier has to exist for this call to succeed. More...
 
bool isSynchronous ()
 Query if this object is synchronized. More...
 
double getCpuTime () const
 
size_t getUpdateCount () const
 
void resetCpuTimeAndUpdateCount ()
 Reset the cpu time and the update count to 0. More...
 

Private Member Functions

bool doInitialize () override
 
bool doStartUp () override
 
bool doUpdate (double dt) override
 Implementation of actual work function for this thread, this has a default implementation to handle destruction better, as it could be called while the thread is under destruction, if left unimplemented this would trigger a call to a pure virtual function. More...
 
void doBeforeStop () override
 Prepares the thread for its execution to be stopped. More...
 
bool executeAdditions (const std::shared_ptr< SurgSim::Framework::Component > &component) override
 Adds a component, this can be either input or output, it will call the appropriate function in the device. More...
 
bool executeRemovals (const std::shared_ptr< SurgSim::Framework::Component > &component) override
 Removes the component described by component. More...
 
bool addInputComponent (const std::shared_ptr< InputComponent > &input)
 Specific call for input components. More...
 
bool addOutputComponent (const std::shared_ptr< OutputComponent > &output)
 Specific call for output components. More...
 
bool tryFindDevice (const std::string &name, DeviceInterface **device)
 Returns a device with the given name, if one is available. More...
 

Private Attributes

std::vector< std::shared_ptr< InputComponent > > m_inputs
 Collection of all input components. More...
 
std::vector< std::shared_ptr< OutputComponent > > m_outputs
 Collection of all output components. More...
 
std::unordered_map< std::string, std::shared_ptr< SurgSim::Input::DeviceInterface > > m_devices
 Collection of all devices that have been added to the input manager key is the name, no two devices with the same name can be added to the input manager. More...
 
boost::mutex m_mutex
 Protect critical sections. More...
 

Friends

class InputManagerTest
 

Additional Inherited Members

- Protected Member Functions inherited from SurgSim::Framework::ComponentManager
template<class T >
std::shared_ptr< T > tryAddComponent (std::shared_ptr< SurgSim::Framework::Component > component, std::vector< std::shared_ptr< T >> *container)
 Template version of the addComponent method. More...
 
template<class T >
bool tryRemoveComponent (std::shared_ptr< SurgSim::Framework::Component > component, std::vector< std::shared_ptr< T >> *container)
 Template version of the removeComponent method. More...
 
void processComponents ()
 Processes all the components that are scheduled for addition or removal, this needs to be called inside the doUpdate() function. More...
 
void processBehaviors (const double dt)
 Processes behaviors This needs to be called inside doUpdate() function in each 'sub' manager. More...
 
void copyScheduledComponents (std::vector< std::shared_ptr< Component >> *inflightAdditions, std::vector< std::shared_ptr< Component >> *inflightRemovals, std::vector< std::shared_ptr< SceneElement >> *inflightElements)
 Helper, blocks access to the additions and removal queue and copies the components from there to the intermediate inflight queues, after this call, the incoming queues will be empty. More...
 
std::shared_ptr< SurgSim::Framework::LoggergetLogger () const
 Returns this manager's logger. More...
 
template<class T >
void retireComponents (const std::vector< std::shared_ptr< T >> &container)
 
- Protected Member Functions inherited from SurgSim::Framework::BasicThread
bool initialize ()
 Trigger the initialization of this object, this will be called before all other threads doStartup() are called. More...
 
bool startUp ()
 Trigger the startup of this object, this will be called after all other threads doInit() was called the thread will only enter the run loop triggering upated() if all threads doInit() and doStartup() returned true. More...
 
bool waitForBarrier (bool success)
 
- Protected Attributes inherited from SurgSim::Framework::ComponentManager
boost::mutex m_componentMutex
 Blocks protects addition and removal queues. More...
 
std::vector< std::shared_ptr< SurgSim::Framework::Behavior > > m_behaviors
 Collection of behaviors. More...
 
std::vector< std::shared_ptr< Component > > m_componentAdditions
 
std::vector< std::shared_ptr< Component > > m_componentRemovals
 
std::vector< std::shared_ptr< SceneElement > > m_elementCache
 
- Protected Attributes inherited from SurgSim::Framework::BasicThread
Timer m_timer
 Timer to measure the actual time taken to doUpdate. More...
 
std::shared_ptr< SurgSim::Framework::Loggerm_logger
 Logger for this thread. More...
 

Detailed Description

Manager to handle InputComponent and OutputComponent, SceneElement can add these to get input from devices, or even write output to devices.

The devices have to be added to this class before components can be added to it.

Constructor & Destructor Documentation

◆ InputManager()

SurgSim::Input::InputManager::InputManager ( )

◆ ~InputManager()

SurgSim::Input::InputManager::~InputManager ( )
virtual

Member Function Documentation

◆ addDevice()

bool SurgSim::Input::InputManager::addDevice ( std::shared_ptr< SurgSim::Input::DeviceInterface device)

Adds a device to the manager.

Parameters
deviceThe device.
Returns
true if it succeeds, false if the device already exists in the manager.

◆ addInputComponent()

bool SurgSim::Input::InputManager::addInputComponent ( const std::shared_ptr< InputComponent > &  input)
private

Specific call for input components.

Link input consumer to input device Data produced by device will then be consumed by input consumer

◆ addOutputComponent()

bool SurgSim::Input::InputManager::addOutputComponent ( const std::shared_ptr< OutputComponent > &  output)
private

Specific call for output components.

◆ doBeforeStop()

void SurgSim::Input::InputManager::doBeforeStop ( )
overrideprivatevirtual

Prepares the thread for its execution to be stopped.

Note
Called from this thread before joined

Reimplemented from SurgSim::Framework::ComponentManager.

◆ doInitialize()

bool SurgSim::Input::InputManager::doInitialize ( )
overrideprivatevirtual

◆ doStartUp()

bool SurgSim::Input::InputManager::doStartUp ( )
overrideprivatevirtual

◆ doUpdate()

bool SurgSim::Input::InputManager::doUpdate ( double  dt)
overrideprivatevirtual

Implementation of actual work function for this thread, this has a default implementation to handle destruction better, as it could be called while the thread is under destruction, if left unimplemented this would trigger a call to a pure virtual function.

Returns
false when the thread is done, this will stop execution

Reimplemented from SurgSim::Framework::BasicThread.

◆ executeAdditions()

bool SurgSim::Input::InputManager::executeAdditions ( const std::shared_ptr< SurgSim::Framework::Component > &  component)
overrideprivatevirtual

Adds a component, this can be either input or output, it will call the appropriate function in the device.

For an InputComonent this will succeed if the device name inside the component is known to the InputManager and if the component has not been added as an input yet. For an OutputComponent the call will fail if the device does not exist or the device has already been assigned an output.

Parameters
componentThe component.
Returns
true if it succeeds, it will fail if the device cannot be found to the component has already been added to the manager, and return false.

Implements SurgSim::Framework::ComponentManager.

◆ executeRemovals()

bool SurgSim::Input::InputManager::executeRemovals ( const std::shared_ptr< SurgSim::Framework::Component > &  component)
overrideprivatevirtual

Removes the component described by component.

Parameters
componentThe component.
Returns
true if it succeeds, it will fail if the component cannot be found and return false.

Implements SurgSim::Framework::ComponentManager.

◆ getType()

int SurgSim::Input::InputManager::getType ( ) const
overridevirtual

Returns the type of Manager.

Implements SurgSim::Framework::ComponentManager.

◆ removeDevice()

bool SurgSim::Input::InputManager::removeDevice ( std::shared_ptr< SurgSim::Input::DeviceInterface device)

Removes the device described by device.

Parameters
deviceThe device.
Returns
true if it succeeds, false if the device is not in.

◆ tryFindDevice()

bool SurgSim::Input::InputManager::tryFindDevice ( const std::string &  name,
DeviceInterface **  device 
)
private

Returns a device with the given name, if one is available.

Parameters
nameThe name of the device.
device[out] The device. Unchanged if the return value is false.
Returns
true if the device was found.

Friends And Related Function Documentation

◆ InputManagerTest

friend class InputManagerTest
friend

Member Data Documentation

◆ m_devices

std::unordered_map<std::string, std::shared_ptr<SurgSim::Input::DeviceInterface> > SurgSim::Input::InputManager::m_devices
private

Collection of all devices that have been added to the input manager key is the name, no two devices with the same name can be added to the input manager.

◆ m_inputs

std::vector<std::shared_ptr<InputComponent> > SurgSim::Input::InputManager::m_inputs
private

Collection of all input components.

◆ m_mutex

boost::mutex SurgSim::Input::InputManager::m_mutex
private

Protect critical sections.

◆ m_outputs

std::vector<std::shared_ptr<OutputComponent> > SurgSim::Input::InputManager::m_outputs
private

Collection of all output components.


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