RawMultiAxisScaffold.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_RAWMULTIAXISSCAFFOLD_H
17 #define SURGSIM_DEVICES_MULTIAXIS_RAWMULTIAXISSCAFFOLD_H
18 
19 #include <memory>
20 #include <vector>
21 
24 
25 namespace SurgSim
26 {
27 namespace Device
28 {
29 
30 class RawMultiAxisDevice;
31 class RawMultiAxisThread;
32 class SystemInputDeviceHandle;
33 
38 {
39 public:
43  explicit RawMultiAxisScaffold(std::shared_ptr<SurgSim::Framework::Logger> logger = nullptr);
44 
47 
50  std::shared_ptr<SurgSim::Framework::Logger> getLogger() const
51  {
52  return m_logger;
53  }
54 
58  static std::shared_ptr<RawMultiAxisScaffold> getOrCreateSharedInstance();
59 
64 
65 private:
67  struct StateData;
69  struct DeviceData;
70 
71  friend class RawMultiAxisDevice;
72  friend class RawMultiAxisThread;
73  friend struct StateData;
74 
80  bool registerDevice(RawMultiAxisDevice* device);
81 
87  bool unregisterDevice(const RawMultiAxisDevice* device);
88 
90  void setPositionScale(const RawMultiAxisDevice* device, double scale);
91 
93  void setOrientationScale(const RawMultiAxisDevice* device, double scale);
94 
96  void setAxisDominance(const RawMultiAxisDevice* device, bool onOff);
97 
102  bool runInputFrame(DeviceData* info);
103 
108  bool runAfterLastFrame(DeviceData* info);
109 
112  bool updateDevice(DeviceData* info);
113 
116  bool initializeSdk();
117 
120  bool finalizeSdk();
121 
128  bool findUnusedDeviceAndRegister(RawMultiAxisDevice* device, int* numUsedDevicesSeen);
129 
137  bool registerIfUnused(const std::string& path, RawMultiAxisDevice* device, int* numUsedDevicesSeen);
138 
141  bool createPerDeviceThread(DeviceData* data);
142 
146 
149  std::unique_ptr<SystemInputDeviceHandle> openDevice(const std::string& path);
150 
153 
154 
155 
157  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
159  std::unique_ptr<StateData> m_state;
160 
163 };
164 
165 }; // namespace Device
166 }; // namespace SurgSim
167 
168 #endif // SURGSIM_DEVICES_MULTIAXIS_RAWMULTIAXISSCAFFOLD_H
void setPositionScale(const RawMultiAxisDevice *device, double scale)
Sets the position scale for this device.
Definition: RawMultiAxisScaffold.cpp:277
Definition: DriveElementFromInputBehavior.cpp:27
bool createPerDeviceThread(DeviceData *data)
Creates the input loop thread.
Definition: RawMultiAxisScaffold.cpp:574
LogLevel
Logging levels.
Definition: Logger.h:36
bool unregisterDevice(const RawMultiAxisDevice *device)
Unregisters the specified device object.
Definition: RawMultiAxisScaffold.cpp:251
std::unique_ptr< SystemInputDeviceHandle > openDevice(const std::string &path)
Opens the specified device.
Definition: RawMultiAxisScaffold.cpp:460
bool findUnusedDeviceAndRegister(RawMultiAxisDevice *device, int *numUsedDevicesSeen)
Scans hardware that is present in the system, and if an unused device is found, register an object fo...
Definition: RawMultiAxisScaffold.cpp:472
static SurgSim::Framework::LogLevel m_defaultLogLevel
The default logging level.
Definition: RawMultiAxisScaffold.h:162
A class implementing the communication with a multi-axis controller input device, for example a 3DCon...
Definition: RawMultiAxisDevice.h:55
std::unique_ptr< StateData > m_state
Internal scaffold state.
Definition: RawMultiAxisScaffold.h:159
bool runAfterLastFrame(DeviceData *info)
Executes the operations after the last input frame, as the device input loop thread is shutting down...
Definition: RawMultiAxisScaffold.cpp:324
static std::shared_ptr< RawMultiAxisScaffold > getOrCreateSharedInstance()
Gets or creates the scaffold shared by all RawMultiAxisDevice instances.
Definition: RawMultiAxisScaffold.cpp:607
RawMultiAxisScaffold(std::shared_ptr< SurgSim::Framework::Logger > logger=nullptr)
Constructor.
Definition: RawMultiAxisScaffold.cpp:176
void setAxisDominance(const RawMultiAxisDevice *device, bool onOff)
Turns on or off the axis dominance setting for this device.
Definition: RawMultiAxisScaffold.cpp:301
bool destroyPerDeviceThread(DeviceData *data)
Destroys the input loop thread.
Definition: RawMultiAxisScaffold.cpp:585
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Gets the logger used by this object and the devices it manages.
Definition: RawMultiAxisScaffold.h:50
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the scaffold and all devices.
Definition: RawMultiAxisScaffold.h:157
static void setDefaultLogLevel(SurgSim::Framework::LogLevel logLevel)
Sets the default log level.
Definition: RawMultiAxisScaffold.cpp:613
void setOrientationScale(const RawMultiAxisDevice *device, double scale)
Sets the orientation scale for this device.
Definition: RawMultiAxisScaffold.cpp:289
A class that implements the behavior of RawMultiAxisDevice objects.
Definition: RawMultiAxisScaffold.h:37
A collection of NamedData objects.
Definition: DataGroup.h:66
bool initializeSdk()
Initializes the RawMultiAxis SDK.
Definition: RawMultiAxisScaffold.cpp:440
bool runInputFrame(DeviceData *info)
Executes the operations for a single input frame for a single device.
Definition: RawMultiAxisScaffold.cpp:313
friend struct StateData
Definition: RawMultiAxisScaffold.h:73
bool registerDevice(RawMultiAxisDevice *device)
Registers the specified device object.
Definition: RawMultiAxisScaffold.cpp:216
~RawMultiAxisScaffold()
Destructor.
Definition: RawMultiAxisScaffold.cpp:188
bool updateDevice(DeviceData *info)
Updates the device information for a single device.
Definition: RawMultiAxisScaffold.cpp:347
A class implementing the thread context for sampling RawMultiAxis devices.
Definition: RawMultiAxisThread.h:33
bool finalizeSdk()
Finalizes (de-initializes) the RawMultiAxis SDK.
Definition: RawMultiAxisScaffold.cpp:450
Definition: RawMultiAxisScaffold.cpp:152
Definition: RawMultiAxisScaffold.cpp:59
static SurgSim::DataStructures::DataGroup buildDeviceInputData()
Builds the data layout for the application input (i.e. device output).
Definition: RawMultiAxisScaffold.cpp:596
bool registerIfUnused(const std::string &path, RawMultiAxisDevice *device, int *numUsedDevicesSeen)
Register a device object given a device path, if the same path is not already in use.
Definition: RawMultiAxisScaffold.cpp:541