OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DeviceToken.cpp
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 // Internal Includes
27 #include "AsyncDeviceToken.h"
28 #include "SyncDeviceToken.h"
29 #include "VirtualDeviceToken.h"
33 
34 // Library/third-party includes
35 // - none
36 
37 // Standard includes
38 #include <stdexcept>
39 
40 using osvr::connection::DeviceTokenPtr;
48 using osvr::util::GuardPtr;
49 
50 DeviceTokenPtr
51 OSVR_DeviceTokenObject::createAsyncDevice(DeviceInitObject &init) {
52  DeviceTokenPtr ret(new AsyncDeviceToken(init.getQualifiedName()));
53  ret->m_sharedInit(init);
54  return ret;
55 }
56 
57 DeviceTokenPtr
59  DeviceTokenPtr ret(new SyncDeviceToken(init.getQualifiedName()));
60  ret->m_sharedInit(init);
61  return ret;
62 }
63 
64 DeviceTokenPtr
66  ConnectionPtr const &conn) {
67  DeviceInitObject init(conn);
68  init.setName(name);
69  DeviceTokenPtr ret(new VirtualDeviceToken(name));
70  ret->m_sharedInit(init);
71  return ret;
72 }
73 
74 OSVR_DeviceTokenObject::OSVR_DeviceTokenObject(std::string const &name)
75  : m_name(name) {}
76 
78 
79 std::string const &OSVR_DeviceTokenObject::getName() const { return m_name; }
80 
81 void OSVR_DeviceTokenObject::sendData(MessageType *type, const char *bytestream,
82  size_t len) {
85  m_sendData(tv, type, bytestream, len);
86 }
88  osvr::util::time::TimeValue const &timestamp, MessageType *type,
89  const char *bytestream, size_t len) {
90  m_sendData(timestamp, type, bytestream, len);
91 }
92 
93 GuardPtr OSVR_DeviceTokenObject::getSendGuard() { return m_getSendGuard(); }
94 
96  osvr::connection::DeviceUpdateCallback const &cb) {
97  m_setUpdateCallback(cb);
98 }
99 
101  m_preConnectionInteract = f;
102 }
103 
105  if (m_preConnectionInteract) {
106  m_preConnectionInteract();
107  }
108  m_connectionInteract();
109 }
110 
111 void OSVR_DeviceTokenObject::stopThreads() { m_stopThreads(); }
112 
114  return m_ownedObjects.release(obj);
115 }
116 
118  std::string const &jsonString) {
119  m_getConnectionDevice()->setDeviceDescriptor(jsonString);
120  m_getConnection()->triggerDescriptorHandlers();
121 }
122 
123 ConnectionPtr OSVR_DeviceTokenObject::m_getConnection() { return m_conn; }
124 
125 ConnectionDevicePtr OSVR_DeviceTokenObject::m_getConnectionDevice() {
126  return m_dev;
127 }
128 
129 void OSVR_DeviceTokenObject::m_stopThreads() {}
130 
131 void OSVR_DeviceTokenObject::m_sharedInit(DeviceInitObject &init) {
132  m_conn = init.getConnection();
133  m_dev = m_conn->createConnectionDevice(init);
134  m_dev->setDeviceToken(*this);
135  m_serverInterfaces = init.getServerInterfaces();
136  for (auto &iface : m_serverInterfaces) {
137  iface->registerMessageTypes(*this);
138  }
139 }
Header.
void setUpdateCallback(osvr::connection::DeviceUpdateCallback const &cb)
Sets the update/wait callback.
Definition: DeviceToken.cpp:95
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
Definition: TimeValue.h:51
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
void stopThreads()
Stop any threads spawned and owned by this DeviceToken.
Structure used internally to construct the desired type of device.
bool release(void *ptr)
Releases the indicated smart pointer in our ownership, if we have it.
Base class for connection-specific message type registration.
Definition: MessageType.h:38
void connectionInteract()
Interact with connection. Only legal to end up in ConnectionDevice::sendData from within here somehow...
A device token for a device that does not have a standard update or wait callback - for instance...
bool releaseObject(void *obj)
Frees some object whose lifetime is controlled by the client context.
void setDeviceDescriptor(std::string const &jsonString)
Send a new or updated device descriptor for this device.
void setPreConnectionInteract(EventFunction const &f)
Sets a function to be executed at the beginning of connectionInteract()
shared_ptr< ConnectionDevice > ConnectionDevicePtr
How to hold on to a ConnectionDevice.
void sendData(osvr::connection::MessageType *type, const char *bytestream, size_t len)
Send data.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
std::string const & getName() const
Accessor for name property.
Definition: DeviceToken.cpp:79
static osvr::connection::DeviceTokenPtr createSyncDevice(osvr::connection::DeviceInitObject &init)
Creates a device token (and underlying ConnectionDevice) that has an update method that runs in the s...
Definition: DeviceToken.cpp:58
static osvr::connection::DeviceTokenPtr createVirtualDevice(std::string const &name, osvr::connection::ConnectionPtr const &conn)
Creates a device token (and underlying ConnectionDevice) without a traditional, built-in update metho...
Definition: DeviceToken.cpp:65
virtual ~OSVR_DeviceTokenObject()
Destructor.
Definition: DeviceToken.cpp:77