OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DirectionRemoteFactory.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
26 #include "DirectionRemoteFactory.h"
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  NetworkDirectionRemoteHandler(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  auto direction = common::DirectionComponent::create();
59  m_dev->addComponent(direction);
60  direction->registerDirectionHandler(
61  [&](common::DirectionData const &data,
62  util::time::TimeValue const &timestamp) {
63  m_handleDirection(data, timestamp);
64  });
65  OSVR_DEV_VERBOSE("Constructed an Direction Handler for "
66  << deviceName);
67  }
68 
71  operator=(NetworkDirectionRemoteHandler const &) = delete;
72 
75  }
76 
77  virtual void update() { m_dev->update(); }
78 
79  private:
80  void m_handleDirection(common::DirectionData const &data,
81  util::time::TimeValue const &timestamp) {
82  if (!m_all && *m_sensor != data.sensor) {
84  return;
85  }
86 
87  OSVR_DirectionReport report;
88  report.sensor = data.sensor;
89  report.direction = data.direction;
90 
91  m_internals.setStateAndTriggerCallbacks(timestamp, report);
92  }
93 
94  common::BaseDevicePtr m_dev;
95  RemoteHandlerInternals m_internals;
96  bool m_all;
97  boost::optional<OSVR_ChannelCount> m_sensor;
98  };
99 
100  DirectionRemoteFactory::DirectionRemoteFactory(
101  VRPNConnectionCollection const &conns)
102  : m_conns(conns) {}
103 
104  shared_ptr<RemoteHandler> DirectionRemoteFactory::
106  common::InterfaceList &ifaces, common::ClientContext &) {
107 
108  shared_ptr<RemoteHandler> ret;
109 
110  if (source.hasTransform()) {
111  OSVR_DEV_VERBOSE(
112  "Ignoring transform found on route for Direction data!");
113  }
114 
115  auto const &devElt = source.getDeviceElement();
116 
118  ret.reset(new NetworkDirectionRemoteHandler(
119  m_conns.getConnection(devElt), devElt.getFullDeviceName(),
120  source.getSensorNumberAsChannelCount(), ifaces));
121  return ret;
122  }
123 
124 } // namespace client
125 } // namespace osvr
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...
Header including PathTree.h and all additional headers needed to define related types.
Header to bring unique_ptr into the osvr namespace.
static shared_ptr< DirectionComponent > create(OSVR_ChannelCount numSensor=1)
Factory method.
NetworkDirectionRemoteHandler & operator=(NetworkDirectionRemoteHandler const &)=delete
Deleted assignment operator.
Report type for 3D Direction vector.
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)
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