OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AnalysisClientContext.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include "AnalysisClientContext.h"
33 #include <osvr/Util/Verbosity.h>
35 
36 // Library/third-party includes
37 #include <json/value.h>
38 
39 // Standard includes
40 #include <unordered_set>
41 #include <thread>
42 
43 namespace osvr {
44 namespace client {
45 
46  //static const std::chrono::milliseconds STARTUP_CONNECT_TIMEOUT(200);
47  //static const std::chrono::milliseconds STARTUP_TREE_TIMEOUT(1000);
48  //static const std::chrono::milliseconds STARTUP_LOOP_SLEEP(1);
49 
51  const char appId[], const char host[], vrpn_ConnectionPtr const &conn,
52  common::ClientContextDeleter del)
53  : ::OSVR_ClientContextObject(appId, del), m_mainConn(conn),
54  m_ifaceMgr(m_pathTreeOwner, m_factory,
55  *static_cast<common::ClientContext *>(this)) {
56 
58  populateRemoteHandlerFactory(m_factory, m_vrpnConns);
59 
60  m_vrpnConns.addConnection(m_mainConn, "localhost");
61  m_vrpnConns.addConnection(m_mainConn, host);
62  std::string sysDeviceName =
63  std::string(common::SystemComponent::deviceName()) + "@" + host;
64  m_mainConn = m_vrpnConns.getConnection(
66 
68  m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn);
69  m_systemComponent =
70  m_systemDevice->addComponent(common::SystemComponent::create());
71  using DedupJsonFunction =
73  m_systemComponent->registerReplaceTreeHandler(
74  DedupJsonFunction([&](Json::Value nodes) {
75 
76  OSVR_DEV_VERBOSE("Got updated path tree, processing");
77 
78  // Tree observers will handle destruction/creation of remote
79  // handlers.
80  m_pathTreeOwner.replaceTree(nodes);
81  }));
82 
83  // No startup spin.
84  }
85 
86  AnalysisClientContext::~AnalysisClientContext() {}
87 
88  void AnalysisClientContext::m_update() {
89  m_started = true;
91  m_systemDevice->update();
93  m_ifaceMgr.updateHandlers();
94  }
95 
96  void AnalysisClientContext::m_sendRoute(std::string const &route) {
97  m_systemComponent->sendClientRouteUpdate(route);
98  m_update();
99  }
100 
101  void AnalysisClientContext::m_handleNewInterface(
102  common::ClientInterfacePtr const &iface) {
103  m_ifaceMgr.addInterface(iface, m_started);
104  }
105 
106  void AnalysisClientContext::m_handleReleasingInterface(
107  common::ClientInterfacePtr const &iface) {
108  m_ifaceMgr.releaseInterface(iface);
109  }
110 
111  bool AnalysisClientContext::m_getStatus() const {
112  return bool(m_pathTreeOwner);
113  }
114 
115  common::PathTree const &AnalysisClientContext::m_getPathTree() const {
116  return m_pathTreeOwner.get();
117  }
118 } // namespace client
119 } // namespace osvr
void replaceTree(Json::Value const &nodes)
Replace the entirety of the path tree from the given serialized array of nodes.
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
BaseDevicePtr createClientDevice(std::string const &name, vrpn_ConnectionPtr const &conn)
Factory function for a bare client device with no components/interfaces registered by default...
Header including PathTree.h and all additional headers needed to define related types.
AnalysisClientContext(const char appId[], const char host[], vrpn_ConnectionPtr const &conn, common::ClientContextDeleter del)
static shared_ptr< SystemComponent > create()
Factory method.
void addInterface(common::ClientInterfacePtr const &iface, bool verboseFailure=true)
Internal, configured header file for verbosity macros.
static const char * deviceName()
Get the special device name to be used with this component.
void updateHandlers()
run update on all remote handlers
A wrapper for a unary function that only calls its contained function when the input has changed...
PathTree & get()
Access the path tree object itself.
Definition: PathTreeOwner.h:73