OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VRPNDeviceRegistration.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
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 #include <algorithm>
37 
38 namespace osvr {
39 namespace vrpnserver {
40  class VRPNDeviceRegistration_impl : boost::noncopyable {
41  public:
44  : m_ctx(ctx) {}
45 
47  return m_ctx;
48  }
49 
50  std::string useDecoratedName(std::string const &name) {
51  std::string ret = m_ctx.getName() + "/" + name;
52 
53  // Add if not already in the list.
54  if (std::find(begin(m_names), end(m_names), ret) == end(m_names)) {
55  m_names.push_back(ret);
56  }
57  return ret;
58  }
59 
60  void registerDevice(OSVR_DeviceUpdateCallback cb, void *dev) {
62  osvr::connection::Connection::retrieveConnection(
63  m_ctx.getParent());
64 
65  auto const &names = getNames();
66  if (names.empty()) {
67  throw std::logic_error(
68  "Your VRPN device has to register at least one name!");
69  }
70  m_connDev = conn->registerAdvancedDevice(names, cb, dev);
71  }
72 
73  void setDeviceDescriptor(std::string const &jsonString) {
74  m_connDev->setDeviceDescriptor(jsonString);
75  osvr::connection::Connection::retrieveConnection(m_ctx.getParent())
76  ->triggerDescriptorHandlers();
77  }
78 
79  connection::ConnectionDevice::NameList const &getNames() const {
80  return m_names;
81  }
82 
83  private:
85  connection::ConnectionDevice::NameList m_names;
87  };
88 
90  : m_ctx(pluginhost::PluginSpecificRegistrationContext::get(ctx)),
91  m_impl(new VRPNDeviceRegistration_impl(m_ctx)) {}
92 
95  : m_ctx(context), m_impl(new VRPNDeviceRegistration_impl(context)) {}
96 
99 
100  std::string
101  VRPNDeviceRegistration::useDecoratedName(std::string const &name) {
102  return m_impl->useDecoratedName(name);
103  }
106  }
107 
108  void
109  VRPNDeviceRegistration::setDeviceDescriptor(std::string const &jsonString) {
110  m_impl->setDeviceDescriptor(jsonString);
111  }
112 
113  void VRPNDeviceRegistration::m_registerDevice(OSVR_DeviceUpdateCallback cb,
114  void *dev) {
115  m_impl->registerDevice(cb, dev);
116  }
117 
118 } // namespace vrpnserver
119 } // namespace osvr
Header.
VRPNDeviceRegistration(VRPNDeviceRegistration const &)=delete
noncopyable
vrpn_Connection * getVRPNConnection()
Get the vrpn_Connection object to use in constructing your object.
Class providing the external interface of a registration context backing a single plugin...
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
const std::string & getName() const
Accessor for plugin name.
vrpn_Connection * getVRPNConnection(OSVR_PluginRegContext ctx)
Retrieves the vrpn_Connection pointer from an OSVR_PluginRegContext.
shared_ptr< ConnectionDevice > ConnectionDevicePtr
How to hold on to a ConnectionDevice.
virtual RegistrationContext & getParent()=0
Get parent registration context.
std::string useDecoratedName(std::string const &name)
Decorates a device name with the plugin name and returns it, as well as records it for registration w...
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin's entry point and other locations of control flow transfer...
OSVR_ReturnCode(* OSVR_DeviceUpdateCallback)(void *userData)
Function type of a Device Update callback.