OSVR-Core
DirectionComponent.h
Go to the documentation of this file.
1 
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 #ifndef INCLUDED_DirectionComponent_h_GUID_DBB6E776_4381_4FB7_C855_B77A87F811BE
27 #define INCLUDED_DirectionComponent_h_GUID_DBB6E776_4381_4FB7_C855_B77A87F811BE
28 
29 // Internal Includes
30 #include <osvr/Common/Export.h>
35 
36 // Library/third-party includes
37 #include <vrpn_BaseClass.h>
38 
39 // Standard includes
40 // - none
41 
42 namespace osvr {
43 namespace common {
44 
45  struct DirectionData {
46  OSVR_ChannelCount sensor;
47  OSVR_DirectionState direction;
48  };
49 
50  namespace messages {
51  class DirectionRecord : public MessageRegistration<DirectionRecord> {
52  public:
54 
55  static const char *identifier();
56  };
57 
58  } // namespace messages
59 
62  public:
67  static OSVR_COMMON_EXPORT shared_ptr<DirectionComponent>
68  create(OSVR_ChannelCount numSensor = 1);
69 
72 
73  OSVR_COMMON_EXPORT void
74  sendDirectionData(OSVR_DirectionState direction,
75  OSVR_ChannelCount sensor,
76  OSVR_TimeValue const &timestamp);
77 
78  typedef std::function<void(DirectionData const &,
79  util::time::TimeValue const &)>
80  DirectionHandler;
81  OSVR_COMMON_EXPORT void registerDirectionHandler(DirectionHandler cb);
82 
83  private:
85  virtual void m_parentSet();
86 
87  static int VRPN_CALLBACK
88  m_handleDirectionRecord(void *userdata, vrpn_HANDLERPARAM p);
89 
90  void m_checkFirst(OSVR_DirectionState const &direction);
91 
92  OSVR_ChannelCount m_numSensor;
93  std::vector<DirectionHandler> m_cb;
94  bool m_gotOne;
95  };
96 
97 } // namespace common
98 } // namespace osvr
99 
100 #endif // INCLUDED_DirectionComponent_h_GUID_DBB6E776_4381_4FB7_C855_B77A87F811BE
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Definition: CommonComponent.h:44
A structure defining a 3D vector, often a position/translation.
Definition: Vec3C.h:48
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: DirectionComponent.h:45
BaseDevice component.
Definition: DirectionComponent.h:61
Definition: DeviceComponent.h:42
CRTP class template wrapping message-specific data and/or logic.
Definition: MessageRegistration.h:44
messages::DirectionRecord directionRecord
Message from server to client, containing 3D direction data.
Definition: DirectionComponent.h:71
Definition: DirectionComponent.h:51
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81