OSVR-Core
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
71  setAnalogs(OSVR_ChannelCount num,
73 
75  void returnAnalogInterface(osvr::connection::AnalogServerInterface &iface);
76 
78  OSVR_CONNECTION_EXPORT void
79  setButtons(OSVR_ChannelCount num,
81 
83  void returnButtonInterface(osvr::connection::ButtonServerInterface &iface);
84 
86  OSVR_CONNECTION_EXPORT void
87  setTracker(osvr::connection::TrackerServerInterface **iface);
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  }
118  void addTokenInterest(osvr::connection::DeviceInterfaceBase *ifaceObj) {
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
136  returnTrackerInterface(osvr::connection::TrackerServerInterface &iface);
137 
139  std::string getQualifiedName() const;
140 
142  osvr::connection::ConnectionPtr getConnection();
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...
Definition: DeviceInitObject.h:101
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
void addTokenInterest(OSVR_DeviceTokenObject **devPtr)
Add an observer that we&#39;ll eventually inform about the device token.
Definition: DeviceInitObject.h:113
Interface for external access to generating button reports.
Definition: ButtonServerInterface.h:45
A DeviceToken connects the generic device interaction code in PluginKit&#39;s C API with the workings of ...
Definition: DeviceToken.h:56
Interface for external access to generating tracker reports.
Definition: TrackerServerInterface.h:46
Header wrapping the C99 standard stdint header.
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
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
Header to bring unique_ptr into the osvr namespace.
Structure used internally to construct the desired type of device.
Definition: DeviceInitObject.h:59
Interface for external access to generating analog reports.
Definition: AnalogServerInterface.h:45
void notifyToken(OSVR_DeviceTokenObject *dev)
Notify all those interested what the device token is.
Definition: DeviceInitObject.h:125
Header declaring the opaque plugin registration context type.
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
Base class for the DeviceInterfaceObjects retrieved by plugins to let them send data on an interface...
Definition: DeviceInterfaceBase.h:43
Header forward-declaring Connection and specifying the smart pointer to hold a Connection in...