OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DeviceInitObject.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
29 
30 // Library/third-party includes
31 // - none
32 
33 // Standard includes
34 // - none
37 
38 OSVR_DeviceInitObject::OSVR_DeviceInitObject(OSVR_PluginRegContext ctx)
39  : m_context(&PluginSpecificRegistrationContext::get(ctx)),
40  m_conn(Connection::retrieveConnection(m_context->getParent())),
41  m_analogIface(nullptr), m_buttonIface(nullptr), m_tracker(false) {}
42 
43 OSVR_DeviceInitObject::OSVR_DeviceInitObject(
45  : m_context(nullptr), m_conn(conn), m_tracker(false) {}
46 
47 void OSVR_DeviceInitObject::setName(std::string const &n) {
48  m_name = n;
49  if (m_context) {
50  m_qualifiedName = m_context->getName() + "/" + m_name;
51  } else {
52  m_qualifiedName = m_name;
53  }
54 }
55 
56 template <typename T>
57 inline bool setOptional(OSVR_ChannelCount input, T ptr,
58  boost::optional<OSVR_ChannelCount> &dest) {
59  if (0 == input || nullptr == ptr) {
60  dest.reset();
61  return false;
62  }
63  dest = input;
64  return true;
65 }
66 
69  if (setOptional(num, iface, m_analogs)) {
70  m_analogIface = iface;
71  } else {
72  m_analogIface = nullptr;
73  }
74 }
75 
78  *m_analogIface = &iface;
79 }
80 
83  if (setOptional(num, iface, m_buttons)) {
84  m_buttonIface = iface;
85  } else {
86  m_buttonIface = nullptr;
87  }
88 }
89 
92  *m_buttonIface = &iface;
93 }
94 
97  if (nullptr != iface) {
98  m_tracker = true;
99  } else {
100  m_tracker = false;
101  }
102  m_trackerIface = iface;
103 }
104 
106  osvr::connection::ServerInterfacePtr const &iface) {
107  m_serverInterfaces.push_back(iface);
108 }
110  osvr::common::DeviceComponentPtr const &comp) {
111  m_components.push_back(comp);
112 }
115  *m_trackerIface = &iface;
116 }
117 
119  return m_qualifiedName;
120 }
121 
123  return m_conn;
124 }
125 
128  return m_context;
129 }
typekeyed_detail::ref_type_at_key< Derived, Key >::type get(TypeKeyedBase< Derived > &c)
Definition: TypeKeyed.h:235
Header.
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.
Interface for external access to generating button reports.
Interface for external access to generating tracker reports.
void returnTrackerInterface(osvr::connection::TrackerServerInterface &iface)
Returns a tracker interface through the pointer-pointer.
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
Class wrapping a messaging transport (server or internal) connection.
Definition: Connection.h:56
void setName(std::string const &n)
Set the (unqualified) name of the device to create.
Interface for external access to generating analog reports.
void returnAnalogInterface(osvr::connection::AnalogServerInterface &iface)
Returns an analog interface through the pointer-pointer.
void setAnalogs(OSVR_ChannelCount num, osvr::connection::AnalogServerInterface **iface)
Set analogs: clears the boost::optional if 0 is passed.
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.
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.
osvr::pluginhost::PluginSpecificRegistrationContext * getContext()
Retrieves the plugin context.
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.