-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathGestureComponent.h
135 lines (102 loc) · 4.09 KB
/
GestureComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/** @file
@brief Header
@date 2015
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA
#define INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA
// Internal Includes
#include <osvr/Common/Export.h>
#include <osvr/Common/DeviceComponent.h>
#include <osvr/Common/SerializationTags.h>
#include <osvr/Common/RegisteredStringMap.h>
#include <osvr/Util/ChannelCountC.h>
#include <osvr/Util/ClientReportTypesC.h>
#include <osvr/Common/JSONSerializationTags.h>
#include <osvr/Common/CommonComponent_fwd.h>
// Library/third-party includes
#include <vrpn_BaseClass.h>
// Standard includes
// - none
namespace osvr {
namespace common {
struct GestureData {
OSVR_ChannelCount sensor;
OSVR_GestureState gestureState;
StringID gestureID;
};
struct GestureMap {
GestureData data;
SerializedStringMap serializedMap;
};
namespace messages {
class GestureRecord : public MessageRegistration<GestureRecord> {
public:
class MessageSerialization;
static const char *identifier();
};
class GestureMapRecord : public MessageRegistration<GestureMapRecord> {
public:
class MessageSerialization;
static const char *identifier();
};
} // namespace messages
/// @brief BaseDevice component
class GestureComponent : public DeviceComponent {
public:
/// @brief Factory method
///
/// Required to ensure that allocation and deallocation stay on the same
/// side of a DLL line.
static OSVR_COMMON_EXPORT shared_ptr<GestureComponent>
create(OSVR_ChannelCount numSensor = 1);
/// @brief Message from server to client, containing Gesture data.
messages::GestureRecord gestureRecord;
/// @brief Message from server to client, containing gesture map
messages::GestureMapRecord gestureMapRecord;
OSVR_COMMON_EXPORT void sendGestureData(
OSVR_GestureState gestureState, std::string const &gestureName,
OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp);
void m_sendGestureMap(OSVR_TimeValue const ×tamp);
typedef std::function<void(
GestureData const &, util::time::TimeValue const &)> GestureHandler;
typedef std::function<void(GestureMap const &,
util::time::TimeValue const &)>
GestureMapHandler;
OSVR_COMMON_EXPORT void registerGestureHandler(GestureHandler cb);
OSVR_COMMON_EXPORT void registerGestureMapHandler(GestureMapHandler cb);
private:
GestureComponent(OSVR_ChannelCount numChan);
virtual void m_parentSet();
static int VRPN_CALLBACK
m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p);
static int VRPN_CALLBACK
m_handleGestureMapRecord(void *userdata, vrpn_HANDLERPARAM p);
void m_checkFirst(OSVR_GestureState const &gesture);
OSVR_ChannelCount m_numSensor;
std::vector<GestureHandler> m_cb;
std::vector<GestureMapHandler> m_cb_map;
bool m_gotOne;
// name to ID map used by the server
RegisteredStringMap m_gestureNameMap;
/// @brief Common component for system device
common::CommonComponent *m_commonComponent;
};
} // namespace common
} // namespace osvr
#endif // INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA