OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ImagingRemoteFactory.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 "ImagingRemoteFactory.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  ImagingRemoteHandler(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 imaging = common::ImagingComponent::create();
59  m_dev->addComponent(imaging);
60  imaging->registerImageHandler(
61  [&](common::ImageData const &data,
62  util::time::TimeValue const &timestamp) {
63  m_handleImage(data, timestamp);
64  });
65  OSVR_DEV_VERBOSE("Constructed an ImagingHandler for "
66  << deviceName);
67  }
68 
71 
74  }
75 
76  virtual void update() { m_dev->update(); }
77 
78  private:
79  void m_handleImage(common::ImageData const &data,
80  util::time::TimeValue const &timestamp) {
81  if (!m_all && *m_sensor != data.sensor) {
83  return;
84  }
85 
86  OSVR_ImagingReport report;
87  report.sensor = data.sensor;
88  report.state.metadata = data.metadata;
89  report.state.data = data.buffer.get();
90 
91  m_internals.forEachInterface(
92  [&timestamp, &report, &data](common::ClientInterface &iface) {
93  // Note: not setting state here! we don't store image state.
94  auto n = iface.getNumCallbacksFor(report);
95  for (std::size_t i = 0; i < n; ++i) {
96  // Acquire a reference for each callback we're going to
97  // call.
98  iface.getContext().acquireObject(data.buffer);
99  }
100  iface.triggerCallbacks(timestamp, report);
101  });
102  }
103 
104  common::BaseDevicePtr m_dev;
105  RemoteHandlerInternals m_internals;
106  bool m_all;
107  boost::optional<OSVR_ChannelCount> m_sensor;
108  };
109 
110  ImagingRemoteFactory::ImagingRemoteFactory(
111  VRPNConnectionCollection const &conns)
112  : m_conns(conns) {}
113 
114  shared_ptr<RemoteHandler> ImagingRemoteFactory::
116  common::InterfaceList &ifaces, common::ClientContext &) {
117 
118  shared_ptr<RemoteHandler> ret;
119 
120  if (source.hasTransform()) {
121  OSVR_DEV_VERBOSE(
122  "Ignoring transform found on route for Imaging data!");
123  }
124 
125  auto const &devElt = source.getDeviceElement();
126 
128  ret.reset(new ImagingRemoteHandler(
129  m_conns.getConnection(devElt), devElt.getFullDeviceName(),
130  source.getSensorNumberAsChannelCount(), ifaces));
131  return ret;
132  }
133 
134 } // namespace client
135 } // 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< ImagingComponent > create(OSVR_ChannelCount numSensor=0)
Factory method.
void forEachInterface(F &&f)
Do something with every client interface object, if the above options don't suit your needs...
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)
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
ImagingRemoteHandler & operator=(ImagingRemoteHandler const &)=delete
Deleted assignment operator.