void Win32FSHook::handlePendingActions() { debug("+Win32FSHook::handlePendingActions called"); EnterCriticalSection(&_cSection); while (_isRunning && _pendingActions.size() > 0) { debug("Win32FSHook::iteration"); pair<ACTION, int> action = _pendingActions.front(); _pendingActions.pop(); switch (action.first) { case WATCH: { debug("Win32FSHook::handlePendingActions WATCH"); int wd = action.second; map <int, WatchData*>::const_iterator i = _wid2WatchData.find(wd); if (i == _wid2WatchData.end()) { debug("WATCH: watch id %d not found", wd); } else { WatchData* watchData = i->second; watchDirectory(watchData); watchData->signalEvent(); } } break; case CANCEL: { debug("Win32FSHook::handlePendingActions CANCEL"); int wd = action.second; map <int, WatchData*>::const_iterator i = _wid2WatchData.find(wd); if (i == _wid2WatchData.end()) { debug("CANCEL: watch id %d not found", wd); } else { debug("Win32FSHook::handlePendingActions - calling unwatch ptr=%d", i->second); WatchData* watchData = i->second; // unwatching the watchdata cause the watch signal object // to be triggered. unwatchDirectory(watchData); } } break; } } LeaveCriticalSection(&_cSection); debug("-Win32FSHook::handlePendingActions"); }
void FileContentProvider::watch() { boost::filesystem::path watchDir = _filepath.parent_path(); initInotify(); watchDirectory(watchDir); while (true) { LOG_DEBUG(filecontentproviderlog) << "[FileContentProvider] watching directory " << watchDir << std::endl; if (!checkEvents()) { LOG_DEBUG(filecontentproviderlog) << "[FileContentProvider] got an interrupt signal" << std::endl; break; } inotify_event* event = readInotifyEvent(); if (event == NULL ) break; LOG_ALL(filecontentproviderlog) << "directory " << watchDir << " changed!" << std::endl; LOG_ALL(filecontentproviderlog) << "\tmask is: " << event->mask << std::endl; LOG_ALL(filecontentproviderlog) << "\tname is: " << event->name << std::endl; if (strcmp(event->name, _filepath.leaf().c_str()) != 0) { LOG_ALL(filecontentproviderlog) << "file " << event->name << " changed, but I'm interested in " << _filepath.leaf() << std::endl; continue; } processInotifyEvent(event); } unwatchDirectory(watchDir); tearDownInotify(); }