OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Imaging.h
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 #ifndef INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
26 #define INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
27 
28 // Internal Includes
33 #include <osvr/Util/TimeValue.h>
34 #include <osvr/Util/Deletable.h>
35 
36 // Library/third-party includes
37 #include <boost/shared_ptr.hpp>
38 #include <boost/noncopyable.hpp>
39 
40 // Standard includes
41 // - none
42 
43 namespace osvr {
44 
45 namespace clientkit {
50  void registerImagingCallback(Interface &iface, ImagingCallback cb,
51  void *userdata);
52 #ifndef OSVR_DOXYGEN_EXTERNAL
53  namespace detail {
57  class ImagingCallbackRegistration : public util::Deletable,
58  boost::noncopyable {
59  public:
60  virtual ~ImagingCallbackRegistration() {}
61 
62  private:
65  ImagingCallbackRegistration(osvr::clientkit::Interface iface,
66  ImagingCallback cb,
67  void *userdata)
68  : m_cb(cb), m_userdata(userdata),
69  m_ctx(iface.getContext().get()) {
71  iface.get(),
72  &ImagingCallbackRegistration::handleRawImagingCallback,
73  this);
74  }
76  class ImagingDeleter {
77  public:
78  ImagingDeleter(OSVR_ClientContext ctx) : m_ctx(ctx) {}
79  void operator()(OSVR_ImageBufferElement *buf) {
80  osvrClientFreeImage(m_ctx, buf);
81  }
82 
83  private:
84  OSVR_ClientContext m_ctx;
85  };
86 
89  static void
90  handleRawImagingCallback(void *userdata,
91  const struct OSVR_TimeValue *timestamp,
92  const struct OSVR_ImagingReport *report) {
93  ImagingCallbackRegistration *self =
94  static_cast<ImagingCallbackRegistration *>(userdata);
95  ImagingReport newReport;
96  newReport.sensor = report->sensor;
97  newReport.metadata = report->state.metadata;
98  newReport.buffer.reset(report->state.data,
99  ImagingDeleter(self->m_ctx));
100  self->m_cb(self->m_userdata, *timestamp, newReport);
101  }
102 
103  ImagingCallback m_cb;
104  void *m_userdata;
105  OSVR_ClientContext m_ctx;
106  friend void osvr::clientkit::registerImagingCallback(
107  Interface &iface, ImagingCallback cb, void *userdata);
108  };
109  } // namespace detail
110 
111 #endif // OSVR_DOXYGEN_EXTERNAL
112 
113  inline void registerImagingCallback(Interface &iface,
114  ImagingCallback cb,
115  void *userdata) {
116  util::boost_util::DeletablePtr ptr(
117  new detail::ImagingCallbackRegistration(iface, cb, userdata));
118  iface.takeOwnership(ptr);
119  }
120 
122 
123 } // end namespace clientkit
124 
125 } // end namespace osvr
126 
127 #endif // INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
Header.
ref_type_at_key< Derived, Key >::type get(TypeKeyedBase< Derived > &c)
Definition: TypeKeyed.h:200
Interface handle object. Typically acquired from a ClientContext.
The main namespace for all C++ elements of the framework, internal and external.
Definition: ClientKit.h:31
OSVR_EXTERN_C_BEGIN OSVR_ReturnCode osvrClientFreeImage(OSVR_ClientContext ctx, OSVR_ImageBufferElement *buf)
Free an image buffer returned from a callback.
OSVR_ClientInterface get()
Get the raw OSVR_ClientInterface from this wrapper.
Definition: Interface.h:55
struct OSVR_ClientContextObject * OSVR_ClientContext
Opaque handle that should be retained by your application. You need only and exactly one...
Header providing a C++ wrapper around TimeValueC.h.
Header defining a base class for objects that just need to be generically deletable.
Header containing the inline implementation of Interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
unsigned char OSVR_ImageBufferElement
Type for raw buffer access to image data.
OSVR_ReturnCode osvrRegisterImagingCallback(OSVR_ClientInterface iface, OSVR_ImagingCallback cb, void *userdata)
Register a callback for Imaging reports on an interface.
void(* ImagingCallback)(void *userdata, util::time::TimeValue const &timestamp, ImagingReport report)
The user-friendly imaging callback type.
Definition: Imaging_decl.h:65