Class wrapping a messaging transport (server or internal) connection. More...
#include <osvr/Connection/Connection.h>
Public Types | |
typedef std::vector < ConnectionDevicePtr > | DeviceList |
Public Member Functions | |
MessageTypePtr | registerMessageType (std::string const &messageId) |
Register (or retrieve registration) of a message type. More... | |
ConnectionDevicePtr | createConnectionDevice (std::string const &deviceName) |
Create a ConnectionDevice by registering a full device name. This should be namespaced with the plugin name. More... | |
ConnectionDevicePtr | createConnectionDevice (DeviceInitObject &init) |
void | addDevice (ConnectionDevicePtr device) |
Add an externally-constructed device to the device list. | |
void | process () |
Process messages. This shouldn't block. More... | |
void | registerConnectionHandler (std::function< void()> handler) |
Register a function to be called when a client connects or pings. | |
void | registerDescriptorHandler (std::function< void()> handler) |
Register a function to be called when a descriptor changes. | |
void | triggerDescriptorHandlers () |
Signal a descriptor update and call any/all descriptor handlers. | |
virtual | ~Connection () |
Destructor. | |
boost::iterator_range < DeviceList::const_iterator > | getDevices () const |
Get the devices, as a range. | |
Static Public Member Functions | |
Factory methods | |
Factory method to create a local-machine-only connection More to come. | |
static ConnectionPtr | createLocalConnection () |
static ConnectionPtr | createSharedConnection (boost::optional< std::string const & > iface, boost::optional< int > port) |
Factory method to create a shared connection. More... | |
static std::tuple< void *, ConnectionPtr > | createLoopbackConnection () |
Context Storage | |
Retrieve a connection pointer from a RegistrationContext | |
static ConnectionPtr | retrieveConnection (const pluginhost::RegistrationContext &ctx) |
static 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. | |
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. | |
virtual void | m_process ()=0 |
(Subclass implementation) Process messages. This shouldn't block. | |
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. | |
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... | |
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 void * | getUnderlyingObject () |
Access implementation details. | |
virtual const char * | getConnectionKindID () |
Returns some implementation-defined string based on the dynamic type of the connection. | |
Class wrapping a messaging transport (server or internal) connection.
Definition at line 56 of file Connection.h.
|
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. |
Definition at line 53 of file Connection.cpp.
MessageTypePtr osvr::connection::Connection::registerMessageType | ( | std::string const & | messageId | ) |
Register (or retrieve registration) of a message type.
Wraps the derived implementation for future expandability.
Definition at line 86 of file Connection.cpp.
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.
Definition at line 91 of file Connection.cpp.
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.
Definition at line 98 of file Connection.cpp.
void osvr::connection::Connection::process | ( | ) |
Process messages. This shouldn't block.
Someone needs to call this method frequently.
Definition at line 143 of file Connection.cpp.
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.
Definition at line 107 of file Connection.cpp.
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.
Definition at line 119 of file Connection.cpp.