SixenseScaffold.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_SIXENSE_SIXENSESCAFFOLD_H
17 #define SURGSIM_DEVICES_SIXENSE_SIXENSESCAFFOLD_H
18 
19 #include <memory>
20 
23 
24 namespace SurgSim
25 {
26 namespace Device
27 {
28 
29 class SixenseDevice;
30 class SixenseThread;
31 
36 {
37 public:
40 
43  std::shared_ptr<SurgSim::Framework::Logger> getLogger() const
44  {
45  return m_logger;
46  }
47 
51  static std::shared_ptr<SixenseScaffold> getOrCreateSharedInstance();
52 
57 
58 private:
60  struct StateData;
62  struct DeviceData;
63 
64  friend class SixenseDevice;
65  friend class SixenseThread;
66  friend struct StateData;
67 
71  explicit SixenseScaffold(std::shared_ptr<SurgSim::Framework::Logger> logger = nullptr);
72 
78  bool registerDevice(SixenseDevice* device);
79 
85  bool unregisterDevice(const SixenseDevice* device);
86 
90  bool runInputFrame();
91 
94  bool updateDevice(const DeviceData& info);
95 
98  bool initializeSdk();
99 
102  bool finalizeSdk();
103 
112  bool findUnusedDeviceAndRegister(SixenseDevice* device, int* numUsedDevicesSeen, bool* fatalError);
113 
122  bool registerIfUnused(int baseIndex, int controllerIndex, SixenseDevice* device, int* numUsedDevicesSeen);
123 
126  bool createThread();
127 
131  bool destroyThread();
132 
135 
136 
137 
139  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
141  std::unique_ptr<StateData> m_state;
142 
149 };
150 
151 }; // namespace Device
152 }; // namespace SurgSim
153 
154 #endif // SURGSIM_DEVICES_SIXENSE_SIXENSESCAFFOLD_H
bool destroyThread()
Destroys the input loop thread.
Definition: SixenseScaffold.cpp:445
std::unique_ptr< StateData > m_state
Internal scaffold state.
Definition: SixenseScaffold.h:141
Definition: DriveElementFromInputBehavior.cpp:27
LogLevel
Logging levels.
Definition: Logger.h:36
bool findUnusedDeviceAndRegister(SixenseDevice *device, int *numUsedDevicesSeen, bool *fatalError)
Scans controllers that are present in the system, and if an unused one is found, register a device fo...
Definition: SixenseScaffold.cpp:331
bool updateDevice(const DeviceData &info)
Updates the device information for a single device.
Definition: SixenseScaffold.cpp:250
bool createThread()
Creates the input loop thread.
Definition: SixenseScaffold.cpp:434
static int m_startupDelayMilliseconds
How long we're willing to wait for devices to be detected, in milliseconds.
Definition: SixenseScaffold.h:146
bool finalizeSdk()
Finalizes (de-initializes) the Sixense SDK.
Definition: SixenseScaffold.cpp:315
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the scaffold and all devices.
Definition: SixenseScaffold.h:139
~SixenseScaffold()
Destructor.
Definition: SixenseScaffold.cpp:115
SixenseScaffold(std::shared_ptr< SurgSim::Framework::Logger > logger=nullptr)
Constructor.
Definition: SixenseScaffold.cpp:103
bool initializeSdk()
Initializes the Sixense SDK.
Definition: SixenseScaffold.cpp:299
bool registerDevice(SixenseDevice *device)
Registers the specified device object.
Definition: SixenseScaffold.cpp:143
static SurgSim::Framework::LogLevel m_defaultLogLevel
The default logging level.
Definition: SixenseScaffold.h:144
static SurgSim::DataStructures::DataGroup buildDeviceInputData()
Builds the data layout for the application input (i.e. device output).
Definition: SixenseScaffold.cpp:456
A class implementing the thread context for sampling Sixense devices.
Definition: SixenseThread.h:33
A collection of NamedData objects.
Definition: DataGroup.h:66
friend struct StateData
Definition: SixenseScaffold.h:66
static std::shared_ptr< SixenseScaffold > getOrCreateSharedInstance()
Gets or creates the scaffold shared by all SixenseDevice instances.
Definition: SixenseScaffold.cpp:474
bool runInputFrame()
Executes the operations for a single input frame.
Definition: SixenseScaffold.cpp:234
A class implementing the communication with one Sixense controller, for example one of the two on the...
Definition: SixenseDevice.h:52
static void setDefaultLogLevel(SurgSim::Framework::LogLevel logLevel)
Sets the default log level.
Definition: SixenseScaffold.cpp:483
bool unregisterDevice(const SixenseDevice *device)
Unregisters the specified device object.
Definition: SixenseScaffold.cpp:212
A class that manages Sixense devices, such as the Razer Hydra.
Definition: SixenseScaffold.h:35
Definition: SixenseScaffold.cpp:52
Definition: SixenseScaffold.cpp:76
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Gets the logger used by this object and the devices it manages.
Definition: SixenseScaffold.h:43
static int m_startupRetryIntervalMilliseconds
How long to wait between trying to detect devices, in milliseconds.
Definition: SixenseScaffold.h:148
bool registerIfUnused(int baseIndex, int controllerIndex, SixenseDevice *device, int *numUsedDevicesSeen)
Register a device object given a (baseIndex, controllerIndex) pair, if the same pair is not already i...
Definition: SixenseScaffold.cpp:404