InputManager.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_INPUT_INPUTMANAGER_H
17 #define SURGSIM_INPUT_INPUTMANAGER_H
18 
19 #include <boost/thread/mutex.hpp>
20 #include <memory>
21 #include <unordered_map>
22 #include <vector>
23 
25 
26 namespace SurgSim
27 {
28 namespace Input
29 {
30 class DeviceInterface;
31 class InputComponent;
32 class OutputComponent;
33 
38 {
39 public:
40  InputManager();
41  virtual ~InputManager();
42 
43  friend class InputManagerTest;
44 
48  bool addDevice(std::shared_ptr<SurgSim::Input::DeviceInterface> device);
49 
53  bool removeDevice(std::shared_ptr<SurgSim::Input::DeviceInterface> device);
54 
55  int getType() const override;
56 
57 private:
58  bool doInitialize() override;
59  bool doStartUp() override;
60  bool doUpdate(double dt) override;
61  void doBeforeStop() override;
62 
71  bool executeAdditions(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
72 
76  bool executeRemovals(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
77 
78 
82  bool addInputComponent(const std::shared_ptr<InputComponent>& input);
84  bool addOutputComponent(const std::shared_ptr<OutputComponent>& output);
85 
90  bool tryFindDevice(const std::string& name, DeviceInterface** device);
91 
93  std::vector<std::shared_ptr<InputComponent>> m_inputs;
95  std::vector<std::shared_ptr<OutputComponent>> m_outputs;
96 
100  std::unordered_map<std::string, std::shared_ptr<SurgSim::Input::DeviceInterface>> m_devices;
101 
103  boost::mutex m_mutex;
104 };
105 
106 }; //namespace Input
107 }; //namespace SurgSim
108 #endif
bool tryFindDevice(const std::string &name, DeviceInterface **device)
Returns a device with the given name, if one is available.
Definition: InputManager.cpp:207
Definition: CompoundShapeToGraphics.cpp:29
bool doInitialize() override
Definition: InputManager.cpp:37
friend class InputManagerTest
Definition: InputManager.h:43
bool addOutputComponent(const std::shared_ptr< OutputComponent > &output)
Specific call for output components.
Definition: InputManager.cpp:131
std::vector< std::shared_ptr< OutputComponent > > m_outputs
Collection of all output components.
Definition: InputManager.h:95
Base Component Manager class.
Definition: ComponentManager.h:49
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
boost::mutex m_mutex
Protect critical sections.
Definition: InputManager.h:103
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
bool addInputComponent(const std::shared_ptr< InputComponent > &input)
Specific call for input components.
Definition: InputManager.cpp:112
std::vector< std::shared_ptr< InputComponent > > m_inputs
Collection of all input components.
Definition: InputManager.h:93
virtual ~InputManager()
Definition: InputManager.cpp:33
bool doStartUp() override
Definition: InputManager.cpp:42
bool addDevice(std::shared_ptr< SurgSim::Input::DeviceInterface > device)
Adds a device to the manager.
Definition: InputManager.cpp:161
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
InputManager()
Definition: InputManager.cpp:28
bool executeRemovals(const std::shared_ptr< SurgSim::Framework::Component > &component) override
Removes the component described by component.
Definition: InputManager.cpp:85
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:41
int getType() const override
Returns the type of Manager.
Definition: InputManager.cpp:202
Manager to handle InputComponent and OutputComponent, SceneElement can add these to get input from de...
Definition: InputManager.h:37
void doBeforeStop() override
Prepares the thread for its execution to be stopped.
Definition: InputManager.cpp:54
bool removeDevice(std::shared_ptr< SurgSim::Input::DeviceInterface > device)
Removes the device described by device.
Definition: InputManager.cpp:184