37 #include <boost/assert.hpp>
40 #include <unordered_set>
44 ClientInterfaceObjectManager::ClientInterfaceObjectManager(
45 common::PathTreeOwner &tree, RemoteHandlerFactory &handlerFactory,
46 common::ClientContext &ctx)
47 : m_pathTree(tree.
get()), m_treeObserver(tree.makeObserver()),
48 m_factory(handlerFactory), m_ctx(&ctx) {
49 m_treeObserver->setEventCallback(
50 common::PathTreeEvents::AboutToUpdate,
51 [&](common::PathTree &) { m_interfaces.clearHandlers(); });
52 m_treeObserver->setEventCallback(
53 common::PathTreeEvents::AfterUpdate,
54 [&](common::PathTree &) { m_connectNeededCallbacks(); });
62 m_connectCallbacksOnPath(pin->getPath(), verboseFailure);
65 void ClientInterfaceObjectManager::releaseInterface(
70 m_removeCallbacksOnPath(pin->getPath());
78 bool ClientInterfaceObjectManager::m_connectCallbacksOnPath(
79 std::string
const &path,
bool verboseFailure) {
85 auto source = common::resolveTreeNode(m_pathTree, path);
86 if (!source.is_initialized()) {
88 logger()->info() <<
"Could not resolve source for " << path;
97 logger()->info() <<
"Successfully produced handler for " << path;
102 "We removed the old handler before so it should be null now");
106 logger()->info() <<
"Could not produce handler for " << path;
112 void ClientInterfaceObjectManager::m_removeCallbacksOnPath(
113 std::string
const &path) {
117 void ClientInterfaceObjectManager::m_connectNeededCallbacks() {
118 auto failedPaths = std::unordered_set<std::string>{};
119 auto successfulPaths =
size_t{0};
123 auto success = m_connectCallbacksOnPath(path);
127 failedPaths.insert(path);
130 logger()->info() <<
"Connected " << successfulPaths <<
" of "
131 << successfulPaths + failedPaths.size()
132 <<
" unconnected paths successfully";
135 util::log::LoggerPtr
const &ClientInterfaceObjectManager::logger()
const {
ref_type_at_key< Derived, Key >::type get(TypeKeyedBase< Derived > &c)
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
RemoteHandlerPtr eraseHandlerForPath(std::string const &path)
Clears and returns the handler for a given path.
FactoryProduct invokeFactory(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx) const
bool addInterface(common::ClientInterfacePtr const &iface)
Add an interface to the tree.
RemoteHandlerPtr replaceHandlerForPath(std::string const &path, RemoteHandlerPtr const &handler)
Sets the handler for a given path, returning the old handler if any.
void updateHandlers()
Call the update method on all handlers.
common::InterfaceList & getInterfacesForPath(std::string const &path)
Returns a reference to the list of interfaces registered for a given path.
bool removeInterface(common::ClientInterfacePtr const &iface)
Remove an interface from the tree.
void visitPathsWithoutHandlers(F &&func)
Visit all paths with interfaces in their list but no handler.
void addInterface(common::ClientInterfacePtr const &iface, bool verboseFailure=true)
Internal, configured header file for verbosity macros.
osvr::util::log::LoggerPtr const & logger() const
Provides logger access for related internal classes.
void updateHandlers()
run update on all remote handlers