25 #ifndef INCLUDED_InternalInterfaceOwner_h_GUID_CE168C67_29A8_44A4_44E4_BCE428AF71EB
26 #define INCLUDED_InternalInterfaceOwner_h_GUID_CE168C67_29A8_44A4_44E4_BCE428AF71EB
34 #include <boost/assert.hpp>
53 : m_ctx(ctx), m_iface(iface) {
61 : m_ctx(ctx), m_iface(iface.get()), m_owningIface(iface) {
69 m_iface = m_owningIface.get();
82 : m_ctx(
std::move(other.m_ctx)),
83 m_owningIface(
std::move(other.m_owningIface)) {
84 std::swap(m_iface, other.m_iface);
94 std::swap(m_ctx, other.m_ctx);
95 std::swap(m_iface, other.m_iface);
96 m_owningIface = std::move(other.m_owningIface);
102 typedef contained_type &reference;
103 typedef contained_type *pointer;
106 explicit operator bool()
const {
return nullptr != m_iface; }
110 reference operator*()
const {
return *m_iface; }
111 pointer operator->()
const {
return m_iface; }
119 if (m_ctx && m_iface) {
121 BOOST_ASSERT_MSG(oldIface,
"We should never be the last one "
122 "holding a reference to this "
126 m_owningIface.reset();
131 void m_checkInvariants()
const {
133 (!m_iface || (m_iface && m_ctx)),
134 "If we have an interface, we must have a context.");
135 BOOST_ASSERT_MSG(!m_owningIface || (m_owningIface.get() == m_iface),
136 "Either owningIface should be empty or the same "
137 "as our raw pointer.");
139 common::ClientContext *m_ctx =
nullptr;
147 #endif // INCLUDED_InternalInterfaceOwner_h_GUID_CE168C67_29A8_44A4_44E4_BCE428AF71EB
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
Header declaring opaque types used by Client and ClientKit.
InternalInterfaceOwner & operator=(InternalInterfaceOwner const &)=delete
non-assignable
InternalInterfaceOwner & operator=(InternalInterfaceOwner &&other)
move-assignable
Class that should be used for all internally-used client interface objects as it handles ownership wi...
InternalInterfaceOwner(InternalInterfaceOwner &&other)
move constructible
osvr::common::ClientInterfacePtr getInterface(const char path[])
Creates an interface object for the given path. The context retains shared ownership.
osvr::common::ClientInterfacePtr releaseInterface(osvr::common::ClientInterface *iface)
Searches through this context to determine if the passed interface object has been retained...
InternalInterfaceOwner(common::ClientContext *ctx, OSVR_ClientInterface iface)
Constructor.
InternalInterfaceOwner()
Empty constructor.
~InternalInterfaceOwner()
Destructor - frees interface.
InternalInterfaceOwner(common::ClientContext *ctx, common::ClientInterfacePtr const &iface)
Constructor that keeps an additional reference to the interface.
InternalInterfaceOwner(common::ClientContext *ctx, const char path[])
Constructor from a context and path.