OSVR-Core
Public Types | Public Member Functions | Protected Member Functions | List of all members
osvr::connection::Connection Class Referenceabstract

Class wrapping a messaging transport (server or internal) connection. More...

#include <Connection.h>

Inheritance diagram for osvr::connection::Connection:
osvr::connection::VrpnBasedConnection

Public Types

typedef std::vector< ConnectionDevicePtrDeviceList
 

Public Member Functions

OSVR_CONNECTION_EXPORT MessageTypePtr registerMessageType (std::string const &messageId)
 Register (or retrieve registration) of a message type. More...
 
OSVR_CONNECTION_EXPORT ConnectionDevicePtr createConnectionDevice (std::string const &deviceName)
 Create a ConnectionDevice by registering a full device name. More...
 
OSVR_CONNECTION_EXPORT ConnectionDevicePtr createConnectionDevice (DeviceInitObject &init)
 
OSVR_CONNECTION_EXPORT void addDevice (ConnectionDevicePtr device)
 Add an externally-constructed device to the device list.
 
OSVR_CONNECTION_EXPORT void process ()
 Process messages. More...
 
OSVR_CONNECTION_EXPORT void registerConnectionHandler (std::function< void()> handler)
 Register a function to be called when a client connects or pings. More...
 
OSVR_CONNECTION_EXPORT void registerDescriptorHandler (std::function< void()> handler)
 Register a function to be called when a descriptor changes.
 
OSVR_CONNECTION_EXPORT void triggerDescriptorHandlers ()
 Signal a descriptor update and call any/all descriptor handlers. More...
 
virtual OSVR_CONNECTION_EXPORT ~Connection ()
 Destructor.
 
boost::iterator_range< DeviceList::const_iterator > getDevices () const
 Get the devices, as a range.
 

Static Public Member Functions

Factory methods

More to come.

Factory method to create a local-machine-only connection

static OSVR_CONNECTION_EXPORT ConnectionPtr createLocalConnection ()
 
static OSVR_CONNECTION_EXPORT ConnectionPtr createSharedConnection (boost::optional< std::string const &> iface, boost::optional< int > port)
 Factory method to create a shared connection. More...
 
static OSVR_CONNECTION_EXPORT std::tuple< void *, ConnectionPtrcreateLoopbackConnection ()
 
Context Storage

Retrieve a connection pointer from a RegistrationContext

static OSVR_CONNECTION_EXPORT ConnectionPtr retrieveConnection (const pluginhost::RegistrationContext &ctx)
 
static OSVR_CONNECTION_EXPORT void storeConnection (pluginhost::RegistrationContext &ctx, ConnectionPtr conn)
 Store a connection pointer in a RegistrationContext.
 

Protected Member Functions

virtual MessageTypePtr m_registerMessageType (std::string const &messageId)=0
 (Subclass implementation) Register (or retrieve registration) of a message type. More...
 
virtual ConnectionDevicePtr m_createConnectionDevice (DeviceInitObject &init)=0
 (Subclass implementation) Register a full device name.
 
virtual void m_registerConnectionHandler (std::function< void()> handler)=0
 (Subclass implementation) Register a function to handle "new connection"/ping messages. More...
 
virtual void m_process ()=0
 (Subclass implementation) Process messages. More...
 
 Connection ()
 brief Constructor
 

Advanced Methods - not for general consumption

These can break encapsulation rules and/or encourage bad coding habits.

Avoid if at all possible.

typedef std::vector< std::string > NameList
 Type of list of device names.
 
OSVR_CONNECTION_EXPORT ConnectionDevicePtr registerAdvancedDevice (std::string const &deviceName, OSVR_DeviceUpdateCallback updateFunction, void *userdata)
 Record a full device name (namespaced with the plugin name) associated with a given callback. More...
 
OSVR_CONNECTION_EXPORT ConnectionDevicePtr registerAdvancedDevice (NameList const &deviceNames, OSVR_DeviceUpdateCallback updateFunction, void *userdata)
 Record more than one full device name (namespaced with the plugin name) associated with a given callback. More...
 
virtual OSVR_CONNECTION_EXPORT void * getUnderlyingObject ()
 Access implementation details.
 
virtual OSVR_CONNECTION_EXPORT const char * getConnectionKindID ()
 Returns some implementation-defined string based on the dynamic type of the connection. More...
 

Detailed Description

Class wrapping a messaging transport (server or internal) connection.

Member Function Documentation

§ createConnectionDevice() [1/2]

ConnectionDevicePtr osvr::connection::Connection::createConnectionDevice ( std::string const &  deviceName)

Create a ConnectionDevice by registering a full device name.

This should be namespaced with the plugin name.

This also adds the device so created to the device list.

ConnectionDevices often assume they're owned by a DeviceToken (whose constructor calls this method), so doing otherwise is unadvisable.

§ createConnectionDevice() [2/2]

ConnectionDevicePtr osvr::connection::Connection::createConnectionDevice ( DeviceInitObject init)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ createSharedConnection()

ConnectionPtr osvr::connection::Connection::createSharedConnection ( boost::optional< std::string const &>  iface,
boost::optional< int >  port 
)
static

Factory method to create a shared connection.

Parameters
ifaceThe NIC/interface to listen on, an empty string or unset (default) means "all interfaces"
portThe port to listen on, unset/default means the default port for the underlying connection implementation.

§ getConnectionKindID()

const char * osvr::connection::Connection::getConnectionKindID ( )
virtual

Returns some implementation-defined string based on the dynamic type of the connection.

Reimplemented in osvr::connection::VrpnBasedConnection.

§ m_process()

virtual void osvr::connection::Connection::m_process ( )
protectedpure virtual

(Subclass implementation) Process messages.

This shouldn't block.

§ m_registerConnectionHandler()

virtual void osvr::connection::Connection::m_registerConnectionHandler ( std::function< void()>  handler)
protectedpure virtual

(Subclass implementation) Register a function to handle "new connection"/ping messages.

§ m_registerMessageType()

virtual MessageTypePtr osvr::connection::Connection::m_registerMessageType ( std::string const &  messageId)
protectedpure virtual

(Subclass implementation) Register (or retrieve registration) of a message type.

§ process()

void osvr::connection::Connection::process ( )

Process messages.

This shouldn't block.

Someone needs to call this method frequently.

§ registerAdvancedDevice() [1/2]

ConnectionDevicePtr osvr::connection::Connection::registerAdvancedDevice ( std::string const &  deviceName,
OSVR_DeviceUpdateCallback  updateFunction,
void *  userdata 
)

Record a full device name (namespaced with the plugin name) associated with a given callback.

This does not register the name in the underlying connection: it is an advanced method that assumes you have some other way of doing that.

This also adds the device so created to the device list.

§ registerAdvancedDevice() [2/2]

ConnectionDevicePtr osvr::connection::Connection::registerAdvancedDevice ( NameList const &  deviceNames,
OSVR_DeviceUpdateCallback  updateFunction,
void *  userdata 
)

Record more than one full device name (namespaced with the plugin name) associated with a given callback.

This does not register the names in the underlying connection: it is an advanced method that assumes you have some other way of doing that.

This also adds the device so created to the device list.

For use when a single device exposes more than one name.

§ registerConnectionHandler()

void osvr::connection::Connection::registerConnectionHandler ( std::function< void()>  handler)

Register a function to be called when a client connects or pings.

§ registerMessageType()

MessageTypePtr osvr::connection::Connection::registerMessageType ( std::string const &  messageId)

Register (or retrieve registration) of a message type.

Wraps the derived implementation for future expandability.

§ triggerDescriptorHandlers()

void osvr::connection::Connection::triggerDescriptorHandlers ( )

Signal a descriptor update and call any/all descriptor handlers.


The documentation for this class was generated from the following files: