OSVR-Core
DeviceToken.h
Go to the documentation of this file.
1 
11 // Copyright 2014 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_DeviceToken_h_GUID_428B015C_19A2_46B0_CFE6_CC100763D387
26 #define INCLUDED_DeviceToken_h_GUID_428B015C_19A2_46B0_CFE6_CC100763D387
27 
28 // Internal Includes
31 #include <osvr/Connection/Export.h>
36 #include <osvr/Util/TimeValue.h>
37 #include <osvr/Util/GuardPtr.h>
40 
41 // Library/third-party includes
42 #include <boost/noncopyable.hpp>
43 
44 // Standard includes
45 #include <string>
46 #include <functional>
47 
48 namespace osvr {
49 namespace connection {
50  typedef std::function<OSVR_ReturnCode()> DeviceUpdateCallback;
51 } // namespace connection
52 } // namespace osvr
53 
56 struct OSVR_DeviceTokenObject : boost::noncopyable {
57  public:
63  OSVR_CONNECTION_EXPORT static osvr::connection::DeviceTokenPtr
64  createAsyncDevice(osvr::connection::DeviceInitObject &init);
67  OSVR_CONNECTION_EXPORT static osvr::connection::DeviceTokenPtr
68  createSyncDevice(osvr::connection::DeviceInitObject &init);
72  OSVR_CONNECTION_EXPORT static osvr::connection::DeviceTokenPtr
73  createVirtualDevice(std::string const &name,
76 
77  using EventFunction = std::function<void()>;
78 
80  virtual ~OSVR_DeviceTokenObject();
81 
83  OSVR_CONNECTION_EXPORT std::string const &getName() const;
84 
86  OSVR_CONNECTION_EXPORT void
87  setUpdateCallback(osvr::connection::DeviceUpdateCallback const &cb);
88 
91  OSVR_CONNECTION_EXPORT void
92  setPreConnectionInteract(EventFunction const &f);
93 
102  OSVR_CONNECTION_EXPORT void sendData(osvr::connection::MessageType *type,
103  const char *bytestream, size_t len);
104 
110  OSVR_CONNECTION_EXPORT void
111  sendData(osvr::util::time::TimeValue const &timestamp,
112  osvr::connection::MessageType *type, const char *bytestream,
113  size_t len);
114 
115  OSVR_CONNECTION_EXPORT osvr::util::GuardPtr getSendGuard();
116 
119  void connectionInteract();
120 
122  void stopThreads();
123 
125  OSVR_CONNECTION_EXPORT void
126  setDeviceDescriptor(std::string const &jsonString);
127 
130  template <typename T> void *acquireObject(T obj) {
131  return m_ownedObjects.acquire(obj);
132  }
133 
138  OSVR_CONNECTION_EXPORT bool releaseObject(void *obj);
139 
140  protected:
141  OSVR_DeviceTokenObject(std::string const &name);
142  osvr::connection::ConnectionPtr m_getConnection();
143  osvr::connection::ConnectionDevicePtr m_getConnectionDevice();
144  virtual void
145  m_setUpdateCallback(osvr::connection::DeviceUpdateCallback const &cb) = 0;
146  virtual void m_sendData(osvr::util::time::TimeValue const &timestamp,
148  const char *bytestream, size_t len) = 0;
149  virtual osvr::util::GuardPtr m_getSendGuard() = 0;
150  virtual void m_connectionInteract() = 0;
151  virtual void m_stopThreads();
152 
153  private:
154  void m_sharedInit(osvr::connection::DeviceInitObject &init);
155  std::string const m_name;
158  osvr::connection::ServerInterfaceList m_serverInterfaces;
159  EventFunction m_preConnectionInteract;
161 };
162 
163 #endif // INCLUDED_DeviceToken_h_GUID_428B015C_19A2_46B0_CFE6_CC100763D387
Header forward declaring MessageType and specifying a smart pointer.
A DeviceToken connects the generic device interaction code in PluginKit&#39;s C API with the workings of ...
Definition: DeviceToken.h:56
Header forward-declaring ConnectionDevice and specifying the desired pointer to hold a ConnectionDevi...
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
Structure used internally to construct the desired type of device.
Definition: DeviceInitObject.h:59
Base class for connection-specific message type registration.
Definition: MessageType.h:38
Holds on to smart pointers by value, and lets you free them by providing the corresponding void *...
Definition: KeyedOwnershipContainer.h:83
Header declaring device callback types.
Header providing a C++ wrapper around TimeValueC.h.
shared_ptr< ConnectionDevice > ConnectionDevicePtr
How to hold on to a ConnectionDevice.
Definition: ConnectionDevicePtr.h:40
void * acquireObject(T obj)
Pass (smart-pointer) ownership of some object to the client context.
Definition: DeviceToken.h:130
Header.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Header forward-declaring Connection and specifying the smart pointer to hold a Connection in...