ServerImpl::ServerImpl(connection::ConnectionPtr const &conn, boost::optional<std::string> const &host, boost::optional<int> const &port) : m_conn(conn), m_ctx(make_shared<pluginhost::RegistrationContext>()), m_host(host.get_value_or("localhost")), m_port(port.get_value_or(util::UseDefaultPort)), m_log(util::log::make_logger(util::log::OSVR_SERVER_LOG)) { if (!m_conn) { throw std::logic_error( "Can't pass a null ConnectionPtr into Server constructor!"); } osvr::connection::Connection::storeConnection(*m_ctx, m_conn); // Get the underlying VRPN connection, and make sure it's OK. auto vrpnConn = getVRPNConnection(m_conn); if (!(vrpnConn->doing_okay())) { throw ServerCreationFailure(); } // Set up system device/system component m_systemDevice = common::createServerDevice( common::SystemComponent::deviceName(), vrpnConn); m_systemComponent = m_systemDevice->addComponent(common::SystemComponent::create()); m_systemComponent->registerClientRouteUpdateHandler( &ServerImpl::m_handleUpdatedRoute, this); // Things to do when we get a new incoming connection // No longer doing hardware detect unconditionally here - see // triggerHardwareDetect() m_commonComponent = m_systemDevice->addComponent(common::CommonComponent::create()); m_commonComponent->registerPingHandler([&] { m_queueTreeSend(); }); // Set up the default display descriptor. m_tree.getNodeByPath("/display").value() = common::elements::StringElement(util::makeString(display_json)); // Deal with updated device descriptors. m_conn->registerDescriptorHandler([&] { m_handleDeviceDescriptors(); }); // Set up handlers to enter/exit idle sleep mode. // Can't do this with the nice wrappers on the CommonComponent of the // system device, I suppose since people aren't really connecting to // that device. vrpnConn->register_handler( vrpnConn->register_message_type(vrpn_got_first_connection), &ServerImpl::m_exitIdle, this); vrpnConn->register_handler( vrpnConn->register_message_type(vrpn_dropped_last_connection), &ServerImpl::m_enterIdle, this); }
ServerImpl::ServerImpl(connection::ConnectionPtr const &conn) : m_conn(conn), m_ctx(make_shared<pluginhost::RegistrationContext>()), m_systemComponent(nullptr), m_running(false), m_sleepTime(0) { if (!m_conn) { throw std::logic_error( "Can't pass a null ConnectionPtr into Server constructor!"); } osvr::connection::Connection::storeConnection(*m_ctx, m_conn); // Get the underlying VRPN connection, and make sure it's OK. auto vrpnConn = getVRPNConnection(m_conn); if (!(vrpnConn->doing_okay())) { throw ServerCreationFailure(); } // Set up system device/system component m_systemDevice = common::createServerDevice( common::SystemComponent::deviceName(), vrpnConn); m_systemComponent = m_systemDevice->addComponent(common::SystemComponent::create()); m_systemComponent->registerClientRouteUpdateHandler( &ServerImpl::m_handleUpdatedRoute, this); // Things to do when we get a new incoming connection m_commonComponent = m_systemDevice->addComponent(common::CommonComponent::create()); m_commonComponent->registerPingHandler( [&] { triggerHardwareDetect(); }); m_commonComponent->registerPingHandler([&] { m_sendTree(); }); // Set up the default display descriptor. m_tree.getNodeByPath("/display").value() = common::elements::StringElement(util::makeString(display_json)); // Deal with updated device descriptors. m_conn->registerDescriptorHandler([&] { m_handleDeviceDescriptors(); }); }
vrpn_Connection *getVRPNConnection(OSVR_PluginRegContext ctx) { return getVRPNConnection( osvr::pluginhost::PluginSpecificRegistrationContext::get(ctx)); }