//------------------------------------------------------------------------------------- KBEShared_ptr< WatcherObject > WatcherPaths::getWatcher(const std::string& fullpath) { if(hasWatcher(fullpath) == false) { DEBUG_MSG(fmt::format("WatcherPaths::delWatcher: not found {}\n", fullpath)); return KBEShared_ptr< WatcherObject > ((WatcherObject*)NULL); } std::vector<std::string> vec; KBEngine::strutil::kbe_split(fullpath, '/', vec); if(vec.size() == 1) return KBEShared_ptr< WatcherObject > ((WatcherObject*)NULL); std::string name = (*(vec.end() - 1)); vec.erase(vec.end() - 1); WatcherPaths* pCurrWatcherPaths = this; for(std::vector<std::string>::iterator iter = vec.begin(); iter != vec.end(); ++iter) { WATCHER_PATHS& paths = pCurrWatcherPaths->watcherPaths(); KBEUnordered_map<std::string, KBEShared_ptr<WatcherPaths> >::iterator fiter = paths.find((*iter)); if(fiter == paths.end()) return KBEShared_ptr< WatcherObject > ((WatcherObject*)NULL); pCurrWatcherPaths = fiter->second.get(); if(pCurrWatcherPaths == NULL) return KBEShared_ptr< WatcherObject > ((WatcherObject*)NULL); } return pCurrWatcherPaths->watchers().getWatcher(name); }
//------------------------------------------------------------------------------------- bool Watchers::delWatcher(const std::string& name) { if(!hasWatcher(name)) return false; watcherObjs_.erase(name); DEBUG_MSG(fmt::format("Watchers::delWatcher: {}\n", name)); return true; }
//------------------------------------------------------------------------------------- bool Watchers::addWatcher(const std::string& path, WatcherObject* pwo) { if(hasWatcher(pwo->name())) { return false; } watcherObjs_[pwo->name()].reset(pwo); //DEBUG_MSG(fmt::format("Watchers::addWatcher: path={}, name={}, id={}\n", // pwo->path(), pwo->name(), pwo->id())); return true; }
//------------------------------------------------------------------------------------- bool Watchers::addWatcher(const std::string& path, WatcherObject* pwo) { if(hasWatcher(pwo->name())) { return false; } watcherObjs_[pwo->name()].reset(pwo); //DEBUG_MSG(boost::format("Watchers::addWatcher: path=%1%, name=%2%, id=%3%\n") % // pwo->path() % pwo->name() % pwo->id()); return true; }