OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Location2DRemoteFactory.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:
52  vrpn_ConnectionPtr const &conn, 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 location = common::Location2DComponent::create();
59  m_dev->addComponent(location);
60  location->registerLocationHandler(
61  [&](common::LocationData const &data,
62  util::time::TimeValue const &timestamp) {
63  m_handleLocation(data, timestamp);
64  });
65  OSVR_DEV_VERBOSE("Constructed an 2D-Location Handler for "
66  << deviceName);
67  }
68 
71  operator=(NetworkLocation2DRemoteHandler const &) = delete;
72 
75  }
76 
77  virtual void update() { m_dev->update(); }
78 
79  private:
80  void m_handleLocation(common::LocationData const &data,
81  util::time::TimeValue const &timestamp) {
82  if (!m_all && *m_sensor != data.sensor) {
84  return;
85  }
86 
87  OSVR_Location2DReport report;
88  report.sensor = data.sensor;
89  report.location = data.location;
90  m_internals.setStateAndTriggerCallbacks(timestamp, report);
91  }
92 
93  common::BaseDevicePtr m_dev;
94  RemoteHandlerInternals m_internals;
95  bool m_all;
96  boost::optional<OSVR_ChannelCount> m_sensor;
97  };
98 
99  Location2DRemoteFactory::Location2DRemoteFactory(
100  VRPNConnectionCollection const &conns)
101  : m_conns(conns) {}
102 
103  shared_ptr<RemoteHandler> Location2DRemoteFactory::
105  common::InterfaceList &ifaces, common::ClientContext &) {
106 
107  shared_ptr<RemoteHandler> ret;
108 
109  if (source.hasTransform()) {
110  OSVR_DEV_VERBOSE(
111  "Ignoring transform found on route for 2D-Location data!");
112  }
113 
114  auto const &devElt = source.getDeviceElement();
115 
117  ret.reset(new NetworkLocation2DRemoteHandler(
118  m_conns.getConnection(devElt), devElt.getFullDeviceName(),
119  source.getSensorNumberAsChannelCount(), ifaces));
120  return ret;
121  }
122 
123 } // namespace client
124 } // namespace osvr
The result of resolving a tree node to a device: either an original source to connect to...
NetworkLocation2DRemoteHandler & operator=(NetworkLocation2DRemoteHandler const &)=delete
Deleted assignment operator.
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.
Report type for 2D location.
void setStateAndTriggerCallbacks(const OSVR_TimeValue &timestamp, ReportType const &report)
Set state and call callbacks for a report type.
static shared_ptr< Location2DComponent > create(OSVR_ChannelCount numSensor=1)
Factory method.
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
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)