42 #include <qplatformdefs.h> 46 #include "private/qcore_unix_p.h" 48 #ifndef QT_NO_FILESYSTEMWATCHER 55 #include <sys/types.h> 56 #include <sys/event.h> 67 # define DEBUG if(false)qDebug 81 fcntl(kqfd, F_SETFD, FD_CLOEXEC);
84 perror(
"QKqueueFileSystemWatcherEngine: cannot create pipe");
99 if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) {
100 perror(
"QKqueueFileSystemWatcherEngine: cannot watch pipe, kevent returned");
115 ::close(
id < 0 ? -
id :
id);
126 QMutableListIterator<QString>
it(p);
127 while (it.hasNext()) {
130 #if defined(O_EVTONLY) 136 perror(
"QKqueueFileSystemWatcherEngine::addPaths: open");
139 if (fd >= (
int)FD_SETSIZE / 2 && fd < (
int)FD_SETSIZE) {
140 int fddup =
fcntl(fd, F_DUPFD, FD_SETSIZE);
146 fcntl(fd, F_SETFD, FD_CLOEXEC);
149 if (QT_FSTAT(fd, &st) == -1) {
150 perror(
"QKqueueFileSystemWatcherEngine::addPaths: fstat");
154 int id = (
S_ISDIR(st.st_mode)) ? -fd : fd;
171 EV_ADD | EV_ENABLE | EV_CLEAR,
172 NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE,
175 if (kevent(
kqfd, &kev, 1, 0, 0, 0) == -1) {
176 perror(
"QKqueueFileSystemWatcherEngine::addPaths: kevent");
183 DEBUG() <<
"QKqueueFileSystemWatcherEngine: added directory path" << path;
184 directories->
append(path);
186 DEBUG() <<
"QKqueueFileSystemWatcherEngine: added file path" << path;
214 QMutableListIterator<QString>
it(p);
215 while (it.hasNext()) {
222 ::close(
id < 0 ? -
id :
id);
253 DEBUG() <<
"QKqueueFileSystemWatcherEngine: waiting for kevents...";
256 perror(
"QKqueueFileSystemWatcherEngine: error during kevent wait");
261 DEBUG() <<
"QKqueueFileSystemWatcherEngine: processing kevent" << kev.ident << kev.filter;
267 perror(
"QKqueueFileSystemWatcherEngine: error reading from pipe");
272 for (
int i = 0; i < ba.
size(); ++i) {
280 DEBUG() <<
"QKqueueFileSystemWatcherEngine: thread received 'q', exiting...";
283 DEBUG() <<
"QKqueueFileSystemWatcherEngine: thread received '@', continuing...";
286 DEBUG() <<
"QKqueueFileSystemWatcherEngine: thread received unknow message" << cmd;
299 DEBUG() <<
"QKqueueFileSystemWatcherEngine: received a kevent for a file we're not watching";
303 if (kev.filter != EVFILT_VNODE) {
304 DEBUG() <<
"QKqueueFileSystemWatcherEngine: received a kevent with the wrong filter";
308 if ((kev.fflags & (NOTE_DELETE | NOTE_REVOKE | NOTE_RENAME)) != 0) {
309 DEBUG() << path <<
"removed, removing watch also";
320 DEBUG() << path <<
"changed";
332 #endif //QT_NO_FILESYSTEMWATCHER QKqueueFileSystemWatcherEngine(int kqfd)
void fileChanged(const QString &path, bool removed)
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
int remove(const Key &key)
Removes all the items that have the key from the hash.
#define EINTR_LOOP(var, cmd)
#define it(className, varName)
The QByteArray class provides an array of bytes.
void run()
The starting point for the thread.
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories)
The QString class provides a Unicode character string.
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
const T value(const Key &key) const
Returns the value associated with the key.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static bool isEmpty(const char *str)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QStringList class provides a list of strings.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
~QKqueueFileSystemWatcherEngine()
void directoryChanged(const QString &path, bool removed)
const char * constData() const
Returns a pointer to the data stored in the byte array.
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
QHash< int, QString > idToPath
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
#define st(var, type, card)
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
static QKqueueFileSystemWatcherEngine * create()
QHash< QString, int > pathToID
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
bool isRunning() const
Returns true if the thread is running; otherwise returns false.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
#define forever
This macro is provided for convenience for writing infinite loops.