VRPN Scol plugin
Loading...
Searching...
No Matches
sVrpn.h
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25#ifndef S_VRPN_H
26#define S_VRPN_H
27
28#include <scolPlugin.h>
29#include <string>
30#include <vector>
31#include <set>
32
33#include <boost/thread/thread.hpp>
34
35#ifdef SCOL_STATIC
36#include <boost/thread/recursive_mutex.hpp>
37#endif
38
39#include <boost/bind/bind.hpp>
40
41#include <vrpn_Tracker.h>
42#include <vrpn_Button.h>
43#include <vrpn_Analog.h>
44#include <vrpn_Dial.h>
45#include <vrpn_Text.h>
46#include <vrpn_Shared.h>
47#include "vrpn_BaseClass.h"
48#include "vrpn_Configure.h"
49#include "vrpn_Types.h"
50
51static ScolWindowHandle HScol;
52
57{
58public:
59 std::string textData;
60 std::vector<float> analogData;
61 std::vector<float> vectorData;
62 std::vector<float> quatData;
63 std::vector<int> btnData;
64 int valueId;
65 int btnState;
66protected:
67private:
68
69public:
70 SCbData()
71 {
72 textData = "";
73 };
74
75
76 ~SCbData()
77 {
78 };
79protected:
80private:
81};
82
83
87class SVrpn
88{
89public:
90protected:
91 bool mEnableAnalogData;
92 bool mEnableButtonData;
93 bool mEnableButtonStateData;
94 bool mEnableTrackerData;
95 bool mEnableTrackerVelData;
96 bool mEnableTrackerAccelData;
97 bool mEnableDialData;
98 bool mEnableTextData;
99
100private:
101#ifdef SCOL_STATIC
102 boost::recursive_mutex m_mutex;
103#else
104 boost::mutex m_mutex;
105#endif
106 vrpn_Analog_Remote* m_analog;
107 vrpn_Button_Remote* m_button;
108 vrpn_Tracker_Remote* m_traker;
109 vrpn_Dial_Remote* m_dial;
110 vrpn_Text_Receiver* m_textMessage;
111 std::string m_host;
112 std::string m_name;
113
114public:
118 SVrpn(const std::string& host, const std::string& name);
119
123 ~SVrpn();
124
125 std::string GetName();
126
127 void EnableAnalogData(bool state);
128 void EnableButtonData(bool state);
129 void EnableButtonStateData(bool state);
130 void EnableTrackerData(bool state);
131 void EnableTrackerVelData(bool state);
132 void EnableTrackerAccelData(bool state);
133 void EnableDialData(bool state);
134 void EnableTextData(bool state);
135
136 bool GetEnableAnalogData();
137 bool GetEnableButtonData();
138 bool GetEnableButtonStateData();
139 bool GetEnableTrackerData();
140 bool GetEnableTrackerVelData();
141 bool GetEnableTrackerAccelData();
142 bool GetEnableDialData();
143 bool GetEnableTextData();
144
145 void Update();
146
147protected:
148private:
149 static void VRPN_CALLBACK handle_analog(void* userData, const vrpn_ANALOGCB analog);
150 static void VRPN_CALLBACK handle_button_state(void* userData, const vrpn_BUTTONCB button);
151 static void VRPN_CALLBACK handle_button_states(void* userData, const vrpn_BUTTONSTATESCB button);
152 static void VRPN_CALLBACK handle_tracker(void* userData, const vrpn_TRACKERCB tracker);
153 static void VRPN_CALLBACK handle_tracker_vel(void* userData, const vrpn_TRACKERVELCB tracker);
154 static void VRPN_CALLBACK handle_tracker_acc(void* userData, const vrpn_TRACKERACCCB tracker);
155 static void VRPN_CALLBACK handle_dial(void* userData, const vrpn_DIALCB dial);
156 static void VRPN_CALLBACK handle_text(void* userData, const vrpn_TEXTCB text);
157};
158
159
161{
162 public:
163 typedef std::set<SVrpn*> DeviceList;
164
165 public:
166 DeviceList deviceList;
167
168 protected:
169
170 private:
171 static sVrpnThread* _singleton;
172 boost::thread m_thread;
173#ifdef SCOL_STATIC
174 boost::recursive_mutex m_mutex;
175#else
176 boost::mutex m_mutex;
177#endif
178 bool m_terminate;
179
180 public:
181 static sVrpnThread* GetInstance();
182 static void Kill();
183 SVrpn* AddDevice(const std::string& host, const std::string& name);
184 void RemoveDevice(SVrpn* device);
185
186 protected:
187 ~sVrpnThread();
188
189 private:
190 sVrpnThread();
191 void UpdateThread();
192};
193
194#endif
Definition sVrpn.h:88
~SVrpn()
Definition sVrpn.cpp:61