AnalysisClientContext::AnalysisClientContext(
        const char appId[], const char host[], vrpn_ConnectionPtr const &conn,
        common::ClientContextDeleter del)
        : ::OSVR_ClientContextObject(appId, del), m_mainConn(conn),
          m_ifaceMgr(m_pathTreeOwner, m_factory,
                     *static_cast<common::ClientContext *>(this)) {

        /// Create all the remote handler factories.
        populateRemoteHandlerFactory(m_factory, m_vrpnConns);

        m_vrpnConns.addConnection(m_mainConn, "localhost");
        m_vrpnConns.addConnection(m_mainConn, host);
        std::string sysDeviceName =
            std::string(common::SystemComponent::deviceName()) + "@" + host;
        m_mainConn = m_vrpnConns.getConnection(
            common::SystemComponent::deviceName(), host);

        /// Create the system client device.
        m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
        m_systemComponent =
            m_systemDevice->addComponent(common::SystemComponent::create());
        using DedupJsonFunction =
            common::DeduplicatingFunctionWrapper<Json::Value const &>;
        m_systemComponent->registerReplaceTreeHandler(
            DedupJsonFunction([&](Json::Value nodes) {

                OSVR_DEV_VERBOSE("Got updated path tree, processing");

                // Tree observers will handle destruction/creation of remote
                // handlers.
                m_pathTreeOwner.replaceTree(nodes);
            }));

        // No startup spin.
    }
Exemplo n.º 2
0
    JointClientContext::JointClientContext(const char appId[],
                                           common::ClientContextDeleter del)
        : ::OSVR_ClientContextObject(appId, del), m_host("localhost") {

        /// Create all the remote handler factories.
        populateRemoteHandlerFactory(m_factory, m_vrpnConns);

        /// creates the OSVR connection with its nested VRPN connection
        auto conn = connection::Connection::createLoopbackConnection();

        /// Get the VRPN connection out and use it.
        m_mainConn = static_cast<vrpn_Connection *>(std::get<0>(conn));
        m_vrpnConns.addConnection(m_mainConn, m_host);

        /// Get the OSVR connection out and use it to make a server.
        m_server = server::Server::create(std::get<1>(conn));

        std::string sysDeviceName =
            std::string(common::SystemComponent::deviceName()) + "@" + m_host;

        /// Create the system client device.
        m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
        m_systemComponent =
            m_systemDevice->addComponent(common::SystemComponent::create());
        typedef common::DeduplicatingFunctionWrapper<Json::Value const &>
            DedupJsonFunction;
        m_systemComponent->registerReplaceTreeHandler(DedupJsonFunction(
            [&](Json::Value const &nodes) { m_handleReplaceTree(nodes); }));
    }
Exemplo n.º 3
0
    JointClientContext::JointClientContext(const char appId[],
                                           common::ClientContextDeleter del)
        : ::OSVR_ClientContextObject(appId, del),
          m_ifaceMgr(m_pathTreeOwner, m_factory,
                     *static_cast<common::ClientContext *>(this)) {

        /// Create all the remote handler factories.
        populateRemoteHandlerFactory(m_factory, m_vrpnConns);

        /// creates the OSVR connection with its nested VRPN connection
        auto conn = connection::Connection::createLoopbackConnection();

        /// Get the VRPN connection out and use it.
        m_mainConn = static_cast<vrpn_Connection *>(std::get<0>(conn));
        m_vrpnConns.addConnection(m_mainConn, HOST);
        BOOST_ASSERT(!m_vrpnConns.empty());

        /// Get the OSVR connection out and use it to make a server.
        m_server = server::Server::createNonListening(std::get<1>(conn));

        std::string sysDeviceName =
            std::string(common::SystemComponent::deviceName()) + "@" + HOST;

        /// Create the system client device.
        m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
        m_systemComponent =
            m_systemDevice->addComponent(common::SystemComponent::create());
        typedef common::DeduplicatingFunctionWrapper<Json::Value const &>
            DedupJsonFunction;

        using DedupJsonFunction =
            common::DeduplicatingFunctionWrapper<Json::Value const &>;
        m_systemComponent->registerReplaceTreeHandler(
            DedupJsonFunction([&](Json::Value nodes) {

                OSVR_DEV_VERBOSE("Got updated path tree, processing");

                // Tree observers will handle destruction/creation of remote
                // handlers.
                m_pathTreeOwner.replaceTree(nodes);
            }));
    }
Exemplo n.º 4
0
    PureClientContext::PureClientContext(const char appId[], const char host[],
                                         common::ClientContextDeleter del)
        : ::OSVR_ClientContextObject(appId, del), m_host(host) {

        if (!m_network.isUp()) {
            throw std::runtime_error("Network error: " + m_network.getError());
        }

        /// Create all the remote handler factories.
        populateRemoteHandlerFactory(m_factory, m_vrpnConns);

        std::string sysDeviceName =
            std::string(common::SystemComponent::deviceName()) + "@" + host;
        m_mainConn = m_vrpnConns.getConnection(
            common::SystemComponent::deviceName(), host);

        /// Create the system client device.
        m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
        m_systemComponent =
            m_systemDevice->addComponent(common::SystemComponent::create());
#define OSVR_USE_DEDUP
#ifdef OSVR_USE_DEDUP
        typedef common::DeduplicatingFunctionWrapper<Json::Value const &>
            DedupJsonFunction;
        m_systemComponent->registerReplaceTreeHandler(DedupJsonFunction(
            [&](Json::Value const &nodes) { m_handleReplaceTree(nodes); }));
#else
        // Just for testing purposes, figuring out why we end up looping too
        // much.
        m_systemComponent->registerReplaceTreeHandler(
            [&](Json::Value const &nodes, util::time::TimeValue const &) {
                m_handleReplaceTree(nodes);
            });
#endif
        typedef std::chrono::system_clock clock;
        auto begin = clock::now();

        // Spin the update to get a connection
        auto connEnd = begin + STARTUP_CONNECT_TIMEOUT;
        while (clock::now() < connEnd && !m_gotConnection) {
            m_update();
            std::this_thread::sleep_for(STARTUP_LOOP_SLEEP);
        }
        if (!m_gotConnection) {
            OSVR_DEV_VERBOSE(
                "Could not connect to OSVR server in the timeout period "
                "allotted of "
                << std::chrono::duration_cast<std::chrono::milliseconds>(
                       STARTUP_CONNECT_TIMEOUT)
                       .count()
                << "ms");
            return; // Bail early if we don't even have a connection
        }

        // Spin the update to get a path tree
        auto treeEnd = begin + STARTUP_TREE_TIMEOUT;
        while (clock::now() < treeEnd && !m_gotTree) {
            m_update();
            std::this_thread::sleep_for(STARTUP_LOOP_SLEEP);
        }
        auto timeToStartup = (clock::now() - begin);
        OSVR_DEV_VERBOSE(
            "Connection process took "
            << std::chrono::duration_cast<std::chrono::milliseconds>(
                   timeToStartup)
                   .count()
            << "ms: " << (m_gotConnection ? "have connection to server, "
                                          : "don't have connection to server, ")
            << (m_gotTree ? "have path tree" : "don't have path tree"));
    }
Exemplo n.º 5
0
    PureClientContext::PureClientContext(const char appId[], const char host[],
                                         common::ClientContextDeleter del)
        : ::OSVR_ClientContextObject(appId, del), m_host(host),
          m_ifaceMgr(m_pathTreeOwner, m_factory,
                     *static_cast<common::ClientContext *>(this)) {

        if (!m_network.isUp()) {
            throw std::runtime_error("Network error: " + m_network.getError());
        }

        /// Create all the remote handler factories.
        populateRemoteHandlerFactory(m_factory, m_vrpnConns);

        std::string sysDeviceName =
            std::string(common::SystemComponent::deviceName()) + "@" + host;
        m_mainConn = m_vrpnConns.getConnection(
            common::SystemComponent::deviceName(), host);

        /// Create the system client device.
        m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
        m_systemComponent =
            m_systemDevice->addComponent(common::SystemComponent::create());
        using DedupJsonFunction =
            common::DeduplicatingFunctionWrapper<Json::Value const &>;

        m_systemComponent->registerReplaceTreeHandler(
            DedupJsonFunction([&](Json::Value nodes) {
                logger()->debug("Got updated path tree, processing");
                // Replace localhost before we even convert the json to a tree.
                // replace the @localhost with the correct host name
                // in case we are a remote client, otherwise the connection
                // would fail
                replaceLocalhostServers(nodes, m_host);

                // Tree observers will handle destruction/creation of remote
                // handlers.
                m_pathTreeOwner.replaceTree(nodes);
            }));

        typedef std::chrono::system_clock clock;
        auto begin = clock::now();

        // Spin the update to get a connection
        auto connEnd = begin + STARTUP_CONNECT_TIMEOUT;
        while (clock::now() < connEnd && !m_gotConnection) {
            m_update();
            std::this_thread::sleep_for(STARTUP_LOOP_SLEEP);
        }
        if (!m_gotConnection) {
            logger()->notice()
                << "Could not connect to OSVR server in the timeout period "
                   "allotted of "
                << std::chrono::duration_cast<std::chrono::milliseconds>(
                       STARTUP_CONNECT_TIMEOUT)
                       .count()
                << "ms";
            return; // Bail early if we don't even have a connection
        }

        // Spin the update to get a path tree
        auto treeEnd = begin + STARTUP_TREE_TIMEOUT;
        while (clock::now() < treeEnd && !m_pathTreeOwner) {
            m_update();
            std::this_thread::sleep_for(STARTUP_LOOP_SLEEP);
        }
        auto timeToStartup = (clock::now() - begin);

        // this message is just "info" if we're all good, but "notice" if we
        // aren't fully set up yet.
        logger()->log(m_pathTreeOwner ? util::log::LogLevel::info
                                      : util::log::LogLevel::notice)
            << "Connection process took "
            << std::chrono::duration_cast<std::chrono::milliseconds>(
                   timeToStartup)
                   .count()
            << "ms: "
            << (m_gotConnection ? "have connection to server, "
                                : "don't have connection to server, ")
            << (m_pathTreeOwner ? "have path tree" : "don't have path tree");
    }