iMSTK
Interactive Medical Simulation Toolkit
imstkVRPNDeviceManager.h
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 #pragma once
8 
9 #include "imstkDeviceManager.h"
10 #include "imstkDeviceClient.h"
11 
12 #include <map>
13 
14 //VRPN
15 #include <vrpn_Connection.h>
16 #include <vrpn_MainloopContainer.h>
17 
18 #include "quat.h"
19 
20 namespace imstk
21 {
22 class VRPNDeviceClient;
23 
24 using VRPNDeviceType = int;
25 const VRPNDeviceType VRPNAnalog = 0x1;
26 const VRPNDeviceType VRPNButton = 0x2;
27 const VRPNDeviceType VRPNTracker = 0x4;
28 const VRPNDeviceType VRPNForce = 0x8;
29 
42 {
43 public:
44 
51  VRPNDeviceManager(const std::string& machine = "localhost", int port = vrpn_DEFAULT_LISTEN_PORT_NO);
52 
53  ~VRPNDeviceManager() override = default;
54 
55  IMSTK_TYPE_NAME(VRPNDeviceManager)
56 
57  void addDeviceClient(std::shared_ptr<VRPNDeviceClient> client);
58 
67  std::shared_ptr<DeviceClient> makeDeviceClient(const std::string& deviceName, VRPNDeviceType deviceType);
68  std::shared_ptr<DeviceClient> makeDeviceClient(const std::string deviceName) override;
69 
70 protected:
74  bool initModule() override;
75 
79  void updateModule() override;
80 
84  void uninitModule() override;
85 
86 private:
87 
88  const std::string m_machine = "localhost";
89  const int m_port = vrpn_DEFAULT_LISTEN_PORT_NO;
90 
91  struct Client
92  {
93  std::shared_ptr<VRPNDeviceClient> client;
94  VRPNDeviceType type;
95  };
96 
97  std::map<VRPNDeviceType, std::vector<std::shared_ptr<VRPNDeviceClient>>> m_deviceMap;
98  std::unique_ptr<vrpn_MainloopContainer> m_deviceConnections;
99 };
100 } // imstk
void updateModule() override
Run the server module.
connects to the vrpn.exe server and lets iMSTK attach devices to the server
Compound Geometry.
std::shared_ptr< DeviceClient > makeDeviceClient(const std::string &deviceName, VRPNDeviceType deviceType)
Creates a client from the given parameters.
VRPNDeviceManager(const std::string &machine="localhost", int port=vrpn_DEFAULT_LISTEN_PORT_NO)
Constructor.
void uninitModule() override
Clean the server module.
Abstract class for DeviceManagers which must return a DeviceClient for which it manages.
bool initModule() override
Initialize the server module.