InputDeviceHandle.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_DEVICES_MULTIAXIS_LINUX_INPUTDEVICEHANDLE_H
17 #define SURGSIM_DEVICES_MULTIAXIS_LINUX_INPUTDEVICEHANDLE_H
18 
19 #include <string>
20 #include <memory>
21 #include <array>
22 #include <vector>
23 
25 
26 
27 namespace SurgSim
28 {
29 namespace Framework
30 {
31 class Logger;
32 }; // namespace Framework
33 
34 namespace Device
35 {
36 
40 {
41 public:
44 
48  static std::vector<std::string> enumeratePaths(SurgSim::Framework::Logger* logger);
49 
54  static std::unique_ptr<InputDeviceHandle> open(const std::string& path,
55  std::shared_ptr<SurgSim::Framework::Logger> logger);
56 
57  virtual std::string getDeviceName() const override;
58 
59  virtual bool getDeviceIds(int* vendorId, int* productId) const override;
60 
61  virtual bool hasTranslationAndRotationAxes() const override;
62 
63  virtual bool updateStates(AxisStates* axisStates, ButtonStates* buttonStates, bool* updated) override;
64 
65 private:
69  explicit InputDeviceHandle(std::shared_ptr<SurgSim::Framework::Logger>&& logger);
70 
71  // Prevent copy construction and copy assignment.
72  InputDeviceHandle(const InputDeviceHandle& other) = delete;
73  InputDeviceHandle& operator=(const InputDeviceHandle& other) = delete;
74 
77  std::vector<int> getDeviceButtonsAndKeys();
78 
85 
86  struct State;
87  std::unique_ptr<State> m_state;
88 };
89 
90 }; // namespace Device
91 }; // namespace SurgSim
92 
93 #endif // SURGSIM_DEVICES_MULTIAXIS_LINUX_INPUTDEVICEHANDLE_H
static std::unique_ptr< InputDeviceHandle > open(const std::string &path, std::shared_ptr< SurgSim::Framework::Logger > logger)
Opens the given path and creates an access wrapper for the device.
Definition: InputDeviceHandle.cpp:95
Definition: InputDeviceHandle.cpp:36
Definition: DriveElementFromInputBehavior.cpp:27
virtual bool getDeviceIds(int *vendorId, int *productId) const override
Gets the device identifiers.
Definition: InputDeviceHandle.cpp:136
InputDeviceHandle & operator=(const InputDeviceHandle &other)=delete
virtual bool hasTranslationAndRotationAxes() const override
Queries if this device has 3 translation and 3 rotation axes.
Definition: InputDeviceHandle.cpp:231
static std::vector< std::string > enumeratePaths(SurgSim::Framework::Logger *logger)
Enumerates input devices.
Definition: InputDeviceHandle.cpp:68
Access to an input/HID device using the Input API in Linux.
Definition: InputDeviceHandle.h:39
bool hasRelativeTranslationAndRotationAxes() const
Query if this device has 3 translation and 3 rotation {relative} axes.
Definition: InputDeviceHandle.cpp:193
~InputDeviceHandle()
Destructor.
Definition: InputDeviceHandle.cpp:64
virtual std::string getDeviceName() const override
Gets the name returned by the operating system for this device.
Definition: InputDeviceHandle.cpp:119
std::array< int, MAX_NUM_AXES > AxisStates
Type used to store axis states.
Definition: SystemInputDeviceHandle.h:39
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
std::unique_ptr< State > m_state
Definition: InputDeviceHandle.h:86
std::array< bool, MAX_NUM_BUTTONS > ButtonStates
Type used to store button states.
Definition: SystemInputDeviceHandle.h:41
virtual bool updateStates(AxisStates *axisStates, ButtonStates *buttonStates, bool *updated) override
Updates the axis and states from the device input, if any.
Definition: InputDeviceHandle.cpp:236
A wrapper for system-dependent access to an input/HID device.
Definition: SystemInputDeviceHandle.h:30
std::vector< int > getDeviceButtonsAndKeys()
Gets the indices of the available device buttons.
Definition: InputDeviceHandle.cpp:310
bool hasAbsoluteTranslationAndRotationAxes() const
Query if this device has 3 translation and 3 rotation {absolute} axes.
Definition: InputDeviceHandle.cpp:153
InputDeviceHandle(std::shared_ptr< SurgSim::Framework::Logger > &&logger)
Constructor.
Definition: InputDeviceHandle.cpp:59