OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DeviceInitObject.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_DeviceInitObject_h_GUID_6B7D1689_CE30_4A9F_4B59_36773D1F0064
26 #define INCLUDED_DeviceInitObject_h_GUID_6B7D1689_CE30_4A9F_4B59_36773D1F0064
27 
28 // Internal Includes
33 #include <osvr/Util/StdInt.h>
34 #include <osvr/Util/UniquePtr.h>
35 #include <osvr/Connection/Export.h>
40 
41 // Library/third-party includes
42 #include <boost/noncopyable.hpp>
43 #include <boost/optional.hpp>
44 
45 // Standard includes
46 #include <string>
47 #include <type_traits>
48 #include <memory>
49 
50 namespace osvr {
51 namespace connection {
52  class AnalogServerInterface;
53  class ButtonServerInterface;
54  class TrackerServerInterface;
55 } // namespace connection
56 } // namespace osvr
57 
59 struct OSVR_DeviceInitObject : boost::noncopyable {
60  public:
61  OSVR_CONNECTION_EXPORT explicit OSVR_DeviceInitObject(
63  OSVR_CONNECTION_EXPORT explicit OSVR_DeviceInitObject(
65 
67  OSVR_CONNECTION_EXPORT void setName(std::string const &n);
68 
70  OSVR_CONNECTION_EXPORT void
73 
76 
78  OSVR_CONNECTION_EXPORT void
81 
84 
86  OSVR_CONNECTION_EXPORT void
88 
91  OSVR_CONNECTION_EXPORT void
92  addServerInterface(osvr::connection::ServerInterfacePtr const &iface);
93 
96  OSVR_CONNECTION_EXPORT void
97  addComponent(osvr::common::DeviceComponentPtr const &comp);
98 
101  template <typename T> T *makeInterfaceObject() {
102  static_assert(
103  std::is_base_of<osvr::connection::DeviceInterfaceBase, T>::value,
104  "Your interface object must derive from "
105  "DeviceInterfaceBase to use this handy wrapper!");
106  auto ifaceObj = getContext()->registerDataWithGenericDelete(new T);
107  addTokenInterest(ifaceObj);
108  return ifaceObj;
109  }
110 
114  if (nullptr != devPtr) {
115  m_tokenInterest.push_back(devPtr);
116  }
117  }
119  if (nullptr != ifaceObj) {
120  m_deviceInterfaces.push_back(ifaceObj);
121  }
122  }
123 
126  for (auto interest : m_tokenInterest) {
127  *interest = dev;
128  }
129  for (auto ifaceObj : m_deviceInterfaces) {
130  ifaceObj->setDeviceToken(*dev);
131  }
132  }
133 
135  void
137 
139  std::string getQualifiedName() const;
140 
143 
146  getContext();
147 
148  boost::optional<OSVR_ChannelCount> getAnalogs() const { return m_analogs; }
149  boost::optional<OSVR_ChannelCount> getButtons() const { return m_buttons; }
150  bool getTracker() const { return m_tracker; }
151  osvr::connection::ServerInterfaceList const &getServerInterfaces() const {
152  return m_serverInterfaces;
153  }
154 
155  osvr::common::DeviceComponentList const &getComponents() const {
156  return m_components;
157  }
158 
159  private:
162  std::string m_name;
163  std::string m_qualifiedName;
164  boost::optional<OSVR_ChannelCount> m_analogs;
166  boost::optional<OSVR_ChannelCount> m_buttons;
168  bool m_tracker;
170  osvr::connection::ServerInterfaceList m_serverInterfaces;
171  osvr::common::DeviceComponentList m_components;
172  std::vector<OSVR_DeviceTokenObject **> m_tokenInterest;
173 
174  std::vector<osvr::connection::DeviceInterfaceBase *> m_deviceInterfaces;
175 };
176 
177 #endif // INCLUDED_DeviceInitObject_h_GUID_6B7D1689_CE30_4A9F_4B59_36773D1F0064
T * makeInterfaceObject()
A helper method to make a "device interface object" of user-designated type and apppropriate lifetime...
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
osvr::connection::ConnectionPtr getConnection()
Retrieve the connection pointer.
void addTokenInterest(OSVR_DeviceTokenObject **devPtr)
Add an observer that we'll eventually inform about the device token.
Interface for external access to generating button reports.
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
Interface for external access to generating tracker reports.
void returnTrackerInterface(osvr::connection::TrackerServerInterface &iface)
Returns a tracker interface through the pointer-pointer.
Automatically-generated export header - do not edit!
Header wrapping the C99 standard stdint header.
std::string getQualifiedName() const
Get device name qualified by plugin name.
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
Header to bring unique_ptr into the osvr namespace.
void setName(std::string const &n)
Set the (unqualified) name of the device to create.
Structure used internally to construct the desired type of device.
Interface for external access to generating analog reports.
void returnAnalogInterface(osvr::connection::AnalogServerInterface &iface)
Returns an analog interface through the pointer-pointer.
void notifyToken(OSVR_DeviceTokenObject *dev)
Notify all those interested what the device token is.
void setAnalogs(OSVR_ChannelCount num, osvr::connection::AnalogServerInterface **iface)
Set analogs: clears the boost::optional if 0 is passed.
Header declaring the opaque plugin registration context type.
void addServerInterface(osvr::connection::ServerInterfacePtr const &iface)
Add a server interface pointer to our list, which will get registered when the device is created...
void addComponent(osvr::common::DeviceComponentPtr const &comp)
Add a device component to our list, which will get added to the device when created.
T * registerDataWithGenericDelete(T *data)
Register data allocated with new to be deleted on plugin unload.
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...
void returnButtonInterface(osvr::connection::ButtonServerInterface &iface)
Returns a button interface through the pointer-pointer.
Base class for the DeviceInterfaceObjects retrieved by plugins to let them send data on an interface...
osvr::pluginhost::PluginSpecificRegistrationContext * getContext()
Retrieves the plugin context.
Header forward-declaring Connection and specifying the smart pointer to hold a Connection in...
void setButtons(OSVR_ChannelCount num, osvr::connection::ButtonServerInterface **iface)
Set buttons: clears the boost::optional if 0 is passed.
void setTracker(osvr::connection::TrackerServerInterface **iface)
Enables tracker interface.