bool ServerImpl::loop() { bool shouldContinue; { /// @todo More elegant way of running queued things than grabbing a /// mutex each time through? boost::unique_lock<boost::mutex> lock(m_mainThreadMutex); m_conn->process(); if (m_treeDirty) { OSVR_DEV_VERBOSE("Path tree updated"); m_sendTree(); m_treeDirty.reset(); } m_systemDevice->update(); for (auto &f : m_mainloopMethods) { f(); } shouldContinue = m_run.shouldContinue(); } if (m_sleepTime > 0) { osvr::util::time::microsleep(m_sleepTime); } else { m_thread.yield(); } return shouldContinue; }
void ServerImpl::m_update() { osvr::common::tracing::ServerUpdate trace; m_conn->process(); m_systemDevice->update(); for (auto &f : m_mainloopMethods) { f(); } if (m_triggeredDetect) { m_log->info() << "Performing hardware auto-detection."; common::tracing::markHardwareDetect(); m_ctx->triggerHardwareDetect(); m_triggeredDetect = false; } if (m_treeDirty) { m_log->debug() << "Path tree updated or connection detected"; m_sendTree(); m_treeDirty.reset(); } }
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(); }); }