OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LocomotionRemoteFactory.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
27 #include "RemoteHandlerInternals.h"
33 #include <osvr/Util/UniquePtr.h>
36 #include <osvr/Util/Verbosity.h>
39 
40 // Library/third-party includes
41 // - none
42 
43 // Standard includes
44 // - none
45 
46 namespace osvr {
47 namespace client {
48 
50  public:
51  LocomotionRemoteHandler(vrpn_ConnectionPtr const &conn,
52  std::string const &deviceName,
53  boost::optional<OSVR_ChannelCount> sensor,
54  common::InterfaceList &ifaces)
55  : m_dev(common::createClientDevice(deviceName, conn)),
56  m_internals(ifaces), m_all(!sensor.is_initialized()),
57  m_sensor(sensor) {
58 
59  auto locomotion = common::LocomotionComponent::create();
60  m_dev->addComponent(locomotion);
61 
62  locomotion->registerNaviVelocityHandler(
63  [&](common::NaviVelocityData const &data,
64  util::time::TimeValue const &timestamp) {
65  m_handleNaviVelocity(data, timestamp);
66  });
67  locomotion->registerNaviPositionHandler(
68  [&](common::NaviPositionData const &data,
69  util::time::TimeValue const &timestamp) {
70  m_handleNaviPosition(data, timestamp);
71  });
72 
73 
74  OSVR_DEV_VERBOSE("Constructed a Locomotion Handler for "
75  << deviceName);
76  }
77 
80  operator=(LocomotionRemoteHandler const &) = delete;
81 
84  }
85 
86  virtual void update() { m_dev->update(); }
87 
88  private:
89  void m_handleNaviVelocity(common::NaviVelocityData const &data,
90  util::time::TimeValue const &timestamp) {
91  if (!m_all && *m_sensor != data.sensor) {
93  return;
94  }
95 
97 
98  report.sensor = data.sensor;
99  report.state = data.naviVelState;
100  m_internals.setStateAndTriggerCallbacks(timestamp, report);
101  }
102 
103  void m_handleNaviPosition(common::NaviPositionData const &data,
104  util::time::TimeValue const &timestamp) {
105  if (!m_all && *m_sensor != data.sensor) {
107  return;
108  }
109 
111  report.sensor = data.sensor;
112  report.state = data.naviPosnState;
113  m_internals.setStateAndTriggerCallbacks(timestamp, report);
114  }
115 
116  common::BaseDevicePtr m_dev;
117  RemoteHandlerInternals m_internals;
118  bool m_all;
119  boost::optional<OSVR_ChannelCount> m_sensor;
120  };
121 
122  LocomotionRemoteFactory::LocomotionRemoteFactory(
123  VRPNConnectionCollection const &conns)
124  : m_conns(conns) {}
125 
126  shared_ptr<RemoteHandler> LocomotionRemoteFactory::
128  common::InterfaceList &ifaces, common::ClientContext &) {
129 
130  shared_ptr<RemoteHandler> ret;
131 
132  if (source.hasTransform()) {
134  }
135 
136  auto const &devElt = source.getDeviceElement();
137 
139  ret.reset(new LocomotionRemoteHandler(
140  m_conns.getConnection(devElt), devElt.getFullDeviceName(),
141  source.getSensorNumberAsChannelCount(), ifaces));
142  return ret;
143  }
144 
145 } // namespace client
146 } // namespace osvr
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)
The result of resolving a tree node to a device: either an original source to connect to...
BaseDevicePtr createClientDevice(std::string const &name, vrpn_ConnectionPtr const &conn)
Factory function for a bare client device with no components/interfaces registered by default...
Report type for an navigation position callback on a tracker interface.
Report type for an navigation velocity callback on a tracker interface.
Header including PathTree.h and all additional headers needed to define related types.
LocomotionRemoteHandler & operator=(LocomotionRemoteHandler const &)=delete
Deleted assignment operator.
OSVR_NaviVelocityState state
The 2D vector in world coordinate system, in meters/second.
Header to bring unique_ptr into the osvr namespace.
::OSVR_TimeValue TimeValue
C++-friendly typedef for the OSVR_TimeValue structure.
Definition: TimeValue.h:48
static shared_ptr< LocomotionComponent > create()
Factory method.
OSVR_NaviPositionState state
The 2D vector in world coordinate system, in meters, relative to starting position.
void setStateAndTriggerCallbacks(const OSVR_TimeValue &timestamp, ReportType const &report)
Set state and call callbacks for a report type.
Internal, configured header file for verbosity macros.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Base class for remote device handler classes.
Definition: RemoteHandler.h:40