37 #include <boost/range/algorithm.hpp>
38 #include <boost/assert.hpp>
44 namespace connection {
46 static const char CONNECTION_KEY[] =
"com.osvr.ConnectionPtr";
50 VrpnBasedConnection::VRPN_LOCAL_ONLY));
54 boost::optional<std::string const &> iface, boost::optional<int> port) {
55 ConnectionPtr conn(make_shared<VrpnBasedConnection>(iface, port));
58 std::tuple<void *, ConnectionPtr> Connection::createLoopbackConnection() {
59 auto conn = make_shared<VrpnBasedConnection>(
60 VrpnBasedConnection::VRPN_LOOPBACK);
61 return std::make_tuple(conn->getUnderlyingObject(),
66 Connection::retrieveConnection(
const pluginhost::RegistrationContext &ctx) {
68 boost::any anyConn = ctx.data().get(CONNECTION_KEY);
69 if (anyConn.empty()) {
81 ctx.
data().
set(CONNECTION_KEY, conn);
112 return updateFunction(userdata);
124 [updateFunction, userdata] {
return updateFunction(userdata); }));
130 BOOST_ASSERT_MSG(device,
"Device must be non-null!");
131 auto const &names = device->getNames();
132 if (names.size() == 1) {
133 m_log->notice() <<
"Added device: " << names.front();
135 m_log->notice() <<
"Added device with names:";
136 for (
auto const &name : names) {
137 m_log->notice() <<
" - " << name;
140 m_devices.push_back(device);
147 for (
auto &dev : m_devices) {
156 m_descriptorHandlers.push_back(handler);
160 for (
auto &handler : m_descriptorHandlers) {
166 : m_log(util::log::make_logger(util::log::OSVR_SERVER_LOG)) {}
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...
ConnectionDevicePtr createConnectionDevice(std::string const &deviceName)
Create a ConnectionDevice by registering a full device name. This should be namespaced with the plugi...
MessageTypePtr registerMessageType(std::string const &messageId)
Register (or retrieve registration) of a message type.
void registerDescriptorHandler(std::function< void()> handler)
Register a function to be called when a descriptor changes.
void registerConnectionHandler(std::function< void()> handler)
Register a function to be called when a client connects or pings.
Class responsible for hosting plugins, along with their registration and destruction.
static ConnectionPtr createSharedConnection(boost::optional< std::string const & > iface, boost::optional< int > port)
Factory method to create a shared connection.
virtual void * getUnderlyingObject()
Access implementation details.
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
virtual void m_process()=0
(Subclass implementation) Process messages. This shouldn't block.
void setName(std::string const &n)
Set the (unqualified) name of the device to create.
Header to bring shared_ptr into the osvr namespace.
virtual MessageTypePtr m_registerMessageType(std::string const &messageId)=0
(Subclass implementation) Register (or retrieve registration) of a message type.
Structure used internally to construct the desired type of device.
void set(std::string const &key, boost::any const &value)
Set data for the given key.
util::AnyMap & data()
Access the data storage map.
virtual void m_registerConnectionHandler(std::function< void()> handler)=0
(Subclass implementation) Register a function to handle "new connection"/ping messages.
static void storeConnection(pluginhost::RegistrationContext &ctx, ConnectionPtr conn)
Store a connection pointer in a RegistrationContext.
unique_ptr< MessageType > MessageTypePtr
a uniquely-owned handle for holding a message type registration.
Connection()
brief Constructor
virtual const char * getConnectionKindID()
Returns some implementation-defined string based on the dynamic type of the connection.
shared_ptr< ConnectionDevice > ConnectionDevicePtr
How to hold on to a ConnectionDevice.
void process()
Process messages. This shouldn't block.
Internal, configured header file for verbosity macros.
void addDevice(ConnectionDevicePtr device)
Add an externally-constructed device to the device list.
std::vector< std::string > NameList
Type of list of device names.
void triggerDescriptorHandlers()
Signal a descriptor update and call any/all descriptor handlers.
virtual ~Connection()
Destructor.
OSVR_ReturnCode(* OSVR_DeviceUpdateCallback)(void *userData)
Function type of a Device Update callback.
virtual ConnectionDevicePtr m_createConnectionDevice(DeviceInitObject &init)=0
(Subclass implementation) Register a full device name.
ConnectionDevice implementation for advanced devices.