//---------------------------------------------------------------------------------- void Monitor::init() { // now scan through all resources, which are already loaded const ResourceManager::ResourceGroupMap& res = mRoot->sResourceManager()->getResourceMap(); ResourceManager::ResourceGroupMap::const_iterator it = res.begin(); for (; it != res.end(); it++) { // for each group do std::list<ResourceHandle>::const_iterator jt = it->second.begin(); for (; jt != it->second.end(); jt++) { // get resource according to the handle IResourcePtr pr = mRoot->sResourceManager()->getByHandle(*jt); // resource is valid, so do if (pr.valid()) { // now get the file name associated with the resource pr.lockResource(); const std::list<std::string>& files = pr.getBase()->getResourceFilenameList(); std::list<std::string>::const_iterator kt = files.begin(); // for each filename add a monitor for (; kt != files.end(); kt ++) { addMonitor(pr, *kt); } pr.unlockResource(); }else{ NR_Log(Log::LOG_PLUGIN, Log::LL_WARNING, "dynamicResources: Resource %s seems to be NULL", pr.getBase()->getResourceName().c_str()); } } } }
//---------------------------------------------------------------------------------- void Monitor::addMonitor(IResourcePtr res, const std::string& file) { // do only add a watcher if inotify already initialized if (!mInotify || !res.valid() || file.length() < 1) return; // we monitor only non-empty resources res.lockResource(); { // create a watch descriptor try { // first check if such a watcher already exists InotifyWatch* watch = mInotify->FindWatch(file); if (watch == NULL) { watch = new InotifyWatch(file, IN_MODIFY); mInotify->Add(watch); } // add new watcher NR_Log(Log::LOG_PLUGIN, Log::LL_DEBUG, "dynamicResources: Monitor %s --> %s", res.getBase()->getResourceName().c_str(), file.c_str()); // add the watcher into the map WatchData data; data.resource = res; data.watcher = watch; data.resourceName = res.getBase()->getResourceName(); mWatchMap[watch->GetDescriptor()].push_back(data); }catch(InotifyException& e) { NR_Log(Log::LOG_PLUGIN, Log::LL_ERROR, "dynamicResources: Cannot add a monitor %s --> %s", res.getBase()->getResourceName().c_str(), file.c_str()); NR_Log(Log::LOG_PLUGIN, Log::LL_ERROR, "dynamicResources: %s", e.GetMessage().c_str()); return; } } res.unlockResource(); }