InputManager.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_INPUT_INPUTMANAGER_H
#define SURGSIM_INPUT_INPUTMANAGER_H
#include <boost/thread/mutex.hpp>
#include <memory>
#include <unordered_map>
#include <vector>
#include "SurgSim/Framework/ComponentManager.h"
namespace SurgSim
{
namespace Input
{
class DeviceInterface;
class InputComponent;
class OutputComponent;
class InputManager : public SurgSim::Framework::ComponentManager
{
public:
InputManager();
virtual ~InputManager();
friend class InputManagerTest;
bool addDevice(std::shared_ptr<SurgSim::Input::DeviceInterface> device);
bool removeDevice(std::shared_ptr<SurgSim::Input::DeviceInterface> device);
int getType() const override;
private:
bool doInitialize() override;
bool doStartUp() override;
bool doUpdate(double dt) override;
void doBeforeStop() override;
bool executeAdditions(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
bool executeRemovals(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
bool addInputComponent(const std::shared_ptr<InputComponent>& input);
bool addOutputComponent(const std::shared_ptr<OutputComponent>& output);
bool tryFindDevice(const std::string& name, DeviceInterface** device);
std::vector<std::shared_ptr<InputComponent>> m_inputs;
std::vector<std::shared_ptr<OutputComponent>> m_outputs;
std::unordered_map<std::string, std::shared_ptr<SurgSim::Input::DeviceInterface>> m_devices;
boost::mutex m_mutex;
};
}; //namespace Input
}; //namespace SurgSim
#endif
SurgSim::Input::InputManager::tryFindDevice
bool tryFindDevice(const std::string &name, DeviceInterface **device)
Returns a device with the given name, if one is available.
Definition: InputManager.cpp:207
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Input::InputManager::doInitialize
bool doInitialize() override
Definition: InputManager.cpp:37
SurgSim::Input::InputManager::InputManagerTest
friend class InputManagerTest
Definition: InputManager.h:43
SurgSim::Input::InputManager::addOutputComponent
bool addOutputComponent(const std::shared_ptr< OutputComponent > &output)
Specific call for output components.
Definition: InputManager.cpp:131
SurgSim::Input::InputManager::m_outputs
std::vector< std::shared_ptr< OutputComponent > > m_outputs
Collection of all output components.
Definition: InputManager.h:95
SurgSim::Framework::ComponentManager
Base Component Manager class.
Definition: ComponentManager.h:49
SurgSim::Input::InputManager::executeAdditions
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 de...
Definition: InputManager.cpp:62
SurgSim::Input::InputManager::m_mutex
boost::mutex m_mutex
Protect critical sections.
Definition: InputManager.h:103
SurgSim::Input::InputManager::m_devices
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.
Definition: InputManager.h:100
SurgSim::Input::InputManager::addInputComponent
bool addInputComponent(const std::shared_ptr< InputComponent > &input)
Specific call for input components.
Definition: InputManager.cpp:112
SurgSim::Input::InputManager::m_inputs
std::vector< std::shared_ptr< InputComponent > > m_inputs
Collection of all input components.
Definition: InputManager.h:93
SurgSim::Input::InputManager::~InputManager
virtual ~InputManager()
Definition: InputManager.cpp:33
SurgSim::Input::InputManager::doStartUp
bool doStartUp() override
Definition: InputManager.cpp:42
SurgSim::Input::InputManager::addDevice
bool addDevice(std::shared_ptr< SurgSim::Input::DeviceInterface > device)
Adds a device to the manager.
Definition: InputManager.cpp:161
SurgSim::Input::InputManager::doUpdate
bool doUpdate(double dt) override
Implementation of actual work function for this thread, this has a default implementation to handle d...
Definition: InputManager.cpp:47
SurgSim::Input::InputManager::InputManager
InputManager()
Definition: InputManager.cpp:28
SurgSim::Input::InputManager::executeRemovals
bool executeRemovals(const std::shared_ptr< SurgSim::Framework::Component > &component) override
Removes the component described by component.
Definition: InputManager.cpp:85
ComponentManager.h
SurgSim::Input::DeviceInterface
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:41
SurgSim::Input::InputManager::getType
int getType() const override
Returns the type of Manager.
Definition: InputManager.cpp:202
SurgSim::Input::InputManager
Manager to handle InputComponent and OutputComponent, SceneElement can add these to get input from de...
Definition: InputManager.h:37
SurgSim::Input::InputManager::doBeforeStop
void doBeforeStop() override
Prepares the thread for its execution to be stopped.
Definition: InputManager.cpp:54
SurgSim::Input::InputManager::removeDevice
bool removeDevice(std::shared_ptr< SurgSim::Input::DeviceInterface > device)
Removes the device described by device.
Definition: InputManager.cpp:184