OSVR-Core
VRPNDeviceRegistration.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_VRPNDeviceRegistration_h_GUID_1D69B168_9B9C_47B9_A9F3_9A569E9710D2
26 #define INCLUDED_VRPNDeviceRegistration_h_GUID_1D69B168_9B9C_47B9_A9F3_9A569E9710D2
27 
28 // Internal Includes
29 #include <osvr/VRPNServer/Export.h>
30 #include <osvr/Util/UniquePtr.h>
35 
36 // Library/third-party includes
37 // - none
38 
39 // Standard includes
40 // - none
41 
42 class vrpn_Connection;
43 
44 namespace osvr {
45 namespace vrpnserver {
46  class VRPNDeviceRegistration_impl;
47 
48  namespace detail {
51  template <typename T>
52  static OSVR_ReturnCode callMainloop(void *userdata) {
53  T *obj = static_cast<T *>(userdata);
54  obj->mainloop();
55  return OSVR_RETURN_SUCCESS;
56  }
57  } // namespace detail
58 
60  public:
65  operator=(VRPNDeviceRegistration const &) = delete;
68  OSVR_VRPNSERVER_EXPORT
71  OSVR_VRPNSERVER_EXPORT VRPNDeviceRegistration(
74  OSVR_VRPNSERVER_EXPORT ~VRPNDeviceRegistration();
75 
87  OSVR_VRPNSERVER_EXPORT std::string
88  useDecoratedName(std::string const &name);
89 
92  OSVR_VRPNSERVER_EXPORT vrpn_Connection *getVRPNConnection();
93 
99  template <typename T> T *registerDevice(T *dev) {
101  m_ctx.extractOpaquePointer(), dev);
102  m_registerDevice(&detail::callMainloop<T>,
103  static_cast<void *>(dev));
104  return dev;
105  }
106 
118  template <typename T>
119  T *constructAndRegisterDevice(std::string const &name) {
120  unique_ptr<T> ret(
121  new T(useDecoratedName(name).c_str(), getVRPNConnection()));
122  return registerDevice(ret.release());
123  }
124 
125  OSVR_VRPNSERVER_EXPORT void
126  setDeviceDescriptor(std::string const &jsonString);
127 
128  private:
129  OSVR_VRPNSERVER_EXPORT void
130  m_registerDevice(OSVR_DeviceUpdateCallback cb, void *dev);
132  unique_ptr<VRPNDeviceRegistration_impl> m_impl;
133  };
134 } // namespace vrpnserver
135 } // namespace osvr
136 
137 #endif // INCLUDED_VRPNDeviceRegistration_h_GUID_1D69B168_9B9C_47B9_A9F3_9A569E9710D2
Header providing C++ interface wrappers around functionality in PluginRegistrationC.h.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Class providing the external interface of a registration context backing a single plugin...
Definition: PluginSpecificRegistrationContext.h:52
Header to bring unique_ptr into the osvr namespace.
T * constructAndRegisterDevice(std::string const &name)
Constructs and registers your custom device with the server and takes ownership of the object...
Definition: VRPNDeviceRegistration.h:119
Definition: VRPNDeviceRegistration.h:59
Definition: newuoa.h:1888
T * registerObjectForDeletion(OSVR_PluginRegContext ctx, T *obj)
Registers an object to be destroyed with delete when the plugin is unloaded.
Definition: PluginRegistration.h:72
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_VRPNSERVER_EXPORT vrpn_Connection * getVRPNConnection(OSVR_PluginRegContext ctx)
Retrieves the vrpn_Connection pointer from an OSVR_PluginRegContext.
Definition: GetVRPNConnection.cpp:39
Header declaring the opaque plugin registration context type.
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:148
OSVR_ReturnCode(* OSVR_DeviceUpdateCallback)(void *userData)
Function type of a Device Update callback.
Definition: DeviceCallbackTypesC.h:48
T * registerDevice(T *dev)
Registers your custom device with the server and takes ownership of the object.
Definition: VRPNDeviceRegistration.h:99
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin&#39;s entry point and other locations of control flow transfer...
Definition: PluginRegContextC.h:47