OSVR-Core
|
Class wrapping a messaging transport (server or internal) connection. More...
#include <Connection.h>
Public Types | |
typedef std::vector< ConnectionDevicePtr > | DeviceList |
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 *, ConnectionPtr > | createLoopbackConnection () |
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... | |
Class wrapping a messaging transport (server or internal) connection.
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.
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.
|
static |
Factory method to create a shared connection.
iface | The NIC/interface to listen on, an empty string or unset (default) means "all interfaces" |
port | The port to listen on, unset/default means the default port for the underlying connection implementation. |
|
virtual |
Returns some implementation-defined string based on the dynamic type of the connection.
Reimplemented in osvr::connection::VrpnBasedConnection.
|
protectedpure virtual |
(Subclass implementation) Process messages.
This shouldn't block.
|
protectedpure virtual |
(Subclass implementation) Register a function to handle "new connection"/ping messages.
|
protectedpure virtual |
(Subclass implementation) Register (or retrieve registration) of a message type.
void osvr::connection::Connection::process | ( | ) |
Process messages.
This shouldn't block.
Someone needs to call this method frequently.
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.
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.
void osvr::connection::Connection::registerConnectionHandler | ( | std::function< void()> | handler | ) |
Register a function to be called when a client connects or pings.
MessageTypePtr osvr::connection::Connection::registerMessageType | ( | std::string const & | messageId | ) |
Register (or retrieve registration) of a message type.
Wraps the derived implementation for future expandability.
void osvr::connection::Connection::triggerDescriptorHandlers | ( | ) |
Signal a descriptor update and call any/all descriptor handlers.