OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VRPNConnectionCollection.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
27 
28 // Library/third-party includes
29 #include <vrpn_Connection.h>
30 
31 // Standard includes
32 // - none
33 
34 namespace osvr {
35 namespace client {
36  VRPNConnectionCollection::VRPNConnectionCollection()
37  : m_connMap(make_shared<ConnectionMap>()) {}
38 
39  vrpn_ConnectionPtr VRPNConnectionCollection::getConnection(
40  common::elements::DeviceElement const &elt) {
41  return getConnection(elt.getDeviceName(), elt.getServer());
42  }
43 
44  vrpn_ConnectionPtr
45  VRPNConnectionCollection::addConnection(vrpn_ConnectionPtr conn,
46  std::string const &host) {
47  auto &connMap = *m_connMap;
48  auto existing = connMap.find(host);
49  if (existing != end(connMap)) {
50  return existing->second;
51  }
52  connMap[host] = conn;
53  BOOST_ASSERT(!empty());
54  return conn;
55  }
56 
57  vrpn_ConnectionPtr
58  VRPNConnectionCollection::getConnection(std::string const &device,
59  std::string const &host) {
60  auto &connMap = *m_connMap;
61  auto existing = connMap.find(host);
62  if (existing != end(connMap)) {
63  return existing->second;
64  }
65  auto fullName = device + "@" + host;
66 
67  vrpn_ConnectionPtr newConn(
68  vrpn_get_connection_by_name(fullName.c_str(), nullptr, nullptr,
69  nullptr, nullptr, nullptr, true));
70  connMap[host] = newConn;
71  newConn->removeReference(); // Remove extra reference.
72  BOOST_ASSERT(!empty());
73  return newConn;
74  }
75 
76  void VRPNConnectionCollection::updateAll() {
77  for (auto &connPair : *m_connMap) {
78  connPair.second->mainloop();
79  }
80  }
81 
82 } // namespace client
83 } // namespace osvr