iMSTK
Interactive Medical Simulation Toolkit
imstkDeviceManagerFactory.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkDeviceManagerFactory.h"
8 #include "imstkLogger.h"
9 
10 #ifdef iMSTK_USE_HAPLY
11 #include "imstkHaplyDeviceManager.h"
12 #endif
13 
14 #ifdef iMSTK_USE_OPENHAPTICS
15 #include "imstkOpenHapticDeviceManager.h"
16 #endif
17 
18 #ifdef iMSTK_USE_VRPN
19 #include "imstkVRPNDeviceManager.h"
20 #endif
21 
22 namespace imstk
23 {
24 #ifdef iMSTK_USE_HAPLY
25 IMSTK_REGISTER_DEVICE_MANAGER(HaplyDeviceManager);
26 #endif
27 
28 #ifdef iMSTK_USE_OPENHAPTICS
29 IMSTK_REGISTER_DEVICE_MANAGER(OpenHapticDeviceManager);
30 #endif
31 
32 #ifdef iMSTK_USE_VRPN
33 IMSTK_REGISTER_DEVICE_MANAGER(VRPNDeviceManager);
34 #endif
35 
36 std::shared_ptr<DeviceManager>
37 DeviceManagerFactory::makeDeviceManager(const std::string typeName)
38 {
39  if (!contains(typeName))
40  {
41  LOG(FATAL) << "No DeviceManager type named: " << typeName;
42  return nullptr;
43  }
44  else
45  {
46  return create(typeName);
47  }
48 }
49 
50 std::shared_ptr<DeviceManager>
52 {
53 #if defined iMSTK_USE_HAPLY
54  return makeDeviceManager("HaplyDeviceManager");
55 #elif defined iMSTK_USE_OPENHAPTICS
56  return makeDeviceManager("OpenHapticDeviceManager");
57 #elif defined iMSTK_USE_VRPN
58  return makeDeviceManager("VRPNDeviceManager");
59 #else
60  LOG(FATAL) << "Tried to make default DeviceManager but no haptic API was found";
61  return nullptr;
62 #endif
63 }
64 } // namespace imstk
Compound Geometry.
static std::shared_ptr< DeviceManager > makeDeviceManager()
Attempts to create a new DeviceManager by whichever is default If multiple haptic managers are built ...
static bool contains(const std::string &name)
Definition: imstkFactory.h:50
static std::shared_ptr< DeviceManager > create(const std::string &name, Args &&... args)
tries to construct the object give name, it will forward the given paramters
Definition: imstkFactory.h:35