示例#1
0
bool start(FileWatcher *watcher) {
#ifndef DEBUG
    if (watcher->sdkVersion < 24)
#endif
        addWatches(watcher);
    processInotifyEvent(watcher);
    return destroyWatches(watcher);
}
示例#2
0
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();
}