OSVR-Core
RemoteHandlerFactory.h
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 #ifndef INCLUDED_RemoteHandlerFactory_h_GUID_3B3394C0_DADA_4BAA_3EDD_6CDA96760D91
26 #define INCLUDED_RemoteHandlerFactory_h_GUID_3B3394C0_DADA_4BAA_3EDD_6CDA96760D91
27 
28 // Internal Includes
29 #include <osvr/Client/Export.h>
30 #include <osvr/Util/SharedPtr.h>
36 
37 // Library/third-party includes
38 // - none
39 
40 // Standard includes
41 #include <functional>
42 #include <unordered_map>
43 
44 namespace osvr {
45 namespace client {
46  class VRPNConnectionCollection;
48  public:
49  typedef shared_ptr<RemoteHandler> FactoryProduct;
50  typedef std::function<FactoryProduct(
51  common::OriginalSource const &, common::InterfaceList &,
52  common::ClientContext &)> SpecificFactory;
53 
54  void addFactory(std::string const &name, SpecificFactory factory) {
55  m_factoriesByInterface[name] = factory;
56  }
57 
58  bool isKnownInterfaceType(std::string const &name) const {
59  return m_factoriesByInterface.find(name) !=
60  end(m_factoriesByInterface);
61  }
62 
63  FactoryProduct invokeFactory(common::OriginalSource const &source,
64  common::InterfaceList &ifaces,
65  common::ClientContext &ctx) const {
66  auto factory =
67  m_factoriesByInterface.find(source.getInterfaceName());
68 
69  if (factory == end(m_factoriesByInterface)) {
71  return FactoryProduct();
72  }
73 
74  return (factory->second)(source, ifaces, ctx);
75  }
76 
77  private:
78  std::unordered_map<std::string, SpecificFactory> m_factoriesByInterface;
79  };
80 
83  OSVR_CLIENT_EXPORT void
85  VRPNConnectionCollection const &conns);
86 
87 } // namespace client
88 } // namespace osvr
89 #endif // INCLUDED_RemoteHandlerFactory_h_GUID_3B3394C0_DADA_4BAA_3EDD_6CDA96760D91
Definition: RemoteHandlerFactory.h:47
The result of resolving a tree node to a device: either an original source to connect to...
Definition: OriginalSource.h:47
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header to bring shared_ptr into the osvr namespace.
Definition: ClientContext.h:50
FactoryProduct invokeFactory(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx) const
Definition: RemoteHandlerFactory.h:63
Definition: VRPNConnectionCollection.h:42
OSVR_CLIENT_EXPORT void populateRemoteHandlerFactory(RemoteHandlerFactory &factory, VRPNConnectionCollection const &conns)
Populates a RemoteHandlerFactory with each of the specific factories included with OSVR...
Definition: RemoteHandlerFactory.cpp:45