OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ConnectionDevice.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
28 
29 // Library/third-party includes
30 #include <boost/assert.hpp>
31 
32 // Standard includes
33 // - none
34 
35 namespace osvr {
36 namespace connection {
37 
39 
40  std::string const &ConnectionDevice::getName() const {
41  return m_names.front();
42  }
43 
44  ConnectionDevice::NameList const &ConnectionDevice::getNames() const {
45  return m_names;
46  }
47 
48  ConnectionDevice::ConnectionDevice(std::string const &name)
49  : m_names(1, name), m_token(nullptr) {}
50 
51  ConnectionDevice::ConnectionDevice(ConnectionDevice::NameList const &names)
52  : m_names(names), m_token(nullptr) {}
53 
55 
57  MessageType *type, const char *bytestream,
58  size_t len) {
59  BOOST_ASSERT(type);
60  m_sendData(timestamp, type, bytestream, len);
61  }
62 
64  BOOST_ASSERT(m_token == nullptr);
65  m_token = &token;
66  }
67 
68  void ConnectionDevice::setDeviceDescriptor(std::string const &jsonString) {
70  m_descriptor = jsonString;
71  }
72 
73  std::string const &ConnectionDevice::getDeviceDescriptor() const {
74  return m_descriptor;
75  }
76 
78  return m_token != nullptr;
79  }
80 
82  BOOST_ASSERT(m_token);
83  return *m_token;
84  }
85 
86 } // namespace connection
87 } // namespace osvr
void setDeviceDescriptor(std::string const &jsonString)
Send new/updated JSON device descriptor.
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
virtual void m_sendData(util::time::TimeValue const &timestamp, MessageType *type, const char *bytestream, size_t len)=0
(Subclass implementation) Send message.
ConnectionDevice(std::string const &name)
Constructor for use by derived classes only.
DeviceToken & m_getDeviceToken()
accessor for device token
Base class for connection-specific message type registration.
Definition: MessageType.h:38
void setDeviceToken(DeviceToken &token)
For use only by DeviceToken.
std::string const & getDeviceDescriptor() const
Get the most current JSON device descriptor.
void process()
Process messages. This shouldn't block.
NameList const & getNames() const
accessor for device names
void sendData(util::time::TimeValue const &timestamp, MessageType *type, const char *bytestream, size_t len)
Send message (as primary device name)
std::string const & getName() const
accessor for (primary) device name
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
bool m_hasDeviceToken() const
Does this connection device have a device token? Should be true in nearly every case.
virtual void m_process()=0
(Subclass implementation) Process messages. This shouldn't block.