OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DeviceComponent.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 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
27 #include <osvr/Common/BaseDevice.h>
28 
29 // Library/third-party includes
30 #include <boost/assert.hpp>
31 
32 // Standard includes
33 // - none
34 
35 namespace osvr {
36 namespace common {
37  DeviceComponent::DeviceComponent() : m_parent(nullptr) {}
38 
40  BOOST_ASSERT_MSG(nullptr == m_parent,
41  "recordParent should only be called once!");
42  m_parent = &dev;
43  m_parentSet();
44  }
45 
47 
48  bool DeviceComponent::m_hasParent() const { return nullptr != m_parent; }
49 
51  return *m_parent;
52  }
53 
54  void DeviceComponent::m_registerHandler(vrpn_MESSAGEHANDLER handler,
55  void *userdata,
56  RawMessageType const &msgType) {
57  auto h = make_shared<MessageHandler<BaseDeviceMessageHandleTraits> >(
58  handler, userdata, msgType);
59  h->registerHandler(&m_getParent());
60  m_messageHandlers.push_back(h);
61  }
63 } // namespace common
64 } // namespace osvr
Class used as an interface for underlying devices that can have device components (corresponding to i...
Definition: BaseDevice.h:51
void m_registerHandler(vrpn_MESSAGEHANDLER handler, void *userdata, RawMessageType const &msgType)
Registers a handler whose lifetime is tied to the lifetime of the component.
virtual void m_update()
Implementation-specific (optional) stuff to do during mainloop.
virtual void m_parentSet()=0
Called once when we have a parent.
bool m_hasParent() const
Returns true if we have a parent registered.
Parent & m_getParent()
Gets the parent - only call if m_hasParent() is true.
Header.
void recordParent(Parent &dev)
Called (only) by BaseDevice when being added: effectively records a "parent pointer" that does not co...
Type-safe wrapper with built-in default for a VRPN "message type" integer.
void update()
Called during mainloop.
DeviceComponent()
Protected constructor, to require subclassing.