45 #ifndef QT_NO_FILESYSTEMWATCHER 47 #include "private/qcore_unix_p.h" 55 #if defined(Q_OS_LINUX) 56 #include <sys/syscall.h> 57 #include <sys/ioctl.h> 62 #if defined(QT_NO_INOTIFY) 66 #error "Should not get here." 69 #include <linux/types.h> 72 # define __NR_inotify_init 291 73 # define __NR_inotify_add_watch 292 74 # define __NR_inotify_rm_watch 293 75 # define __NR_inotify_init1 332 76 #elif defined(__x86_64__) 77 # define __NR_inotify_init 253 78 # define __NR_inotify_add_watch 254 79 # define __NR_inotify_rm_watch 255 80 # define __NR_inotify_init1 294 81 #elif defined(__powerpc__) || defined(__powerpc64__) 82 # define __NR_inotify_init 275 83 # define __NR_inotify_add_watch 276 84 # define __NR_inotify_rm_watch 277 85 # define __NR_inotify_init1 318 86 #elif defined (__ia64__) 87 # define __NR_inotify_init 1277 88 # define __NR_inotify_add_watch 1278 89 # define __NR_inotify_rm_watch 1279 90 # define __NR_inotify_init1 1318 91 #elif defined (__s390__) || defined (__s390x__) 92 # define __NR_inotify_init 284 93 # define __NR_inotify_add_watch 285 94 # define __NR_inotify_rm_watch 286 95 # define __NR_inotify_init1 324 96 #elif defined (__alpha__) 97 # define __NR_inotify_init 444 98 # define __NR_inotify_add_watch 445 99 # define __NR_inotify_rm_watch 446 101 #elif defined (__sparc__) || defined (__sparc64__) 102 # define __NR_inotify_init 151 103 # define __NR_inotify_add_watch 152 104 # define __NR_inotify_rm_watch 156 105 # define __NR_inotify_init1 322 106 #elif defined (__arm__) 107 # define __NR_inotify_init 316 108 # define __NR_inotify_add_watch 317 109 # define __NR_inotify_rm_watch 318 110 # define __NR_inotify_init1 360 111 #elif defined (__sh__) 112 # define __NR_inotify_init 290 113 # define __NR_inotify_add_watch 291 114 # define __NR_inotify_rm_watch 292 115 # define __NR_inotify_init1 332 116 #elif defined (__sh64__) 117 # define __NR_inotify_init 318 118 # define __NR_inotify_add_watch 319 119 # define __NR_inotify_rm_watch 320 120 # define __NR_inotify_init1 360 121 #elif defined (__mips__) 122 # define __NR_inotify_init 284 123 # define __NR_inotify_add_watch 285 124 # define __NR_inotify_rm_watch 286 125 # define __NR_inotify_init1 329 126 #elif defined (__hppa__) 127 # define __NR_inotify_init 269 128 # define __NR_inotify_add_watch 270 129 # define __NR_inotify_rm_watch 271 130 # define __NR_inotify_init1 314 131 #elif defined (__avr32__) 132 # define __NR_inotify_init 240 133 # define __NR_inotify_add_watch 241 134 # define __NR_inotify_rm_watch 242 136 #elif defined (__mc68000__) 137 # define __NR_inotify_init 284 138 # define __NR_inotify_add_watch 285 139 # define __NR_inotify_rm_watch 286 140 # define __NR_inotify_init1 328 141 #elif defined (__aarch64__) 142 # define __NR_inotify_init1 26 143 # define __NR_inotify_add_watch 27 144 # define __NR_inotify_rm_watch 28 147 # error "This architecture is not supported. Please talk to qt-bugs@trolltech.com" 150 #if !defined(IN_CLOEXEC) && defined(O_CLOEXEC) && defined(__NR_inotify_init1) 151 # define IN_CLOEXEC O_CLOEXEC 158 static inline int syscall(...) {
return -1; }
161 static inline int inotify_init()
163 #ifdef __NR_inotify_init 164 return syscall(__NR_inotify_init);
166 return syscall(__NR_inotify_init1, 0);
170 static inline int inotify_add_watch(
int fd,
const char *
name, __u32 mask)
172 return syscall(__NR_inotify_add_watch, fd, name, mask);
175 static inline int inotify_rm_watch(
int fd, __u32 wd)
177 return syscall(__NR_inotify_rm_watch, fd, wd);
181 static inline int inotify_init1(
int flags)
183 return syscall(__NR_inotify_init1, flags);
190 struct inotify_event {
198 #define IN_ACCESS 0x00000001 199 #define IN_MODIFY 0x00000002 200 #define IN_ATTRIB 0x00000004 201 #define IN_CLOSE_WRITE 0x00000008 202 #define IN_CLOSE_NOWRITE 0x00000010 203 #define IN_OPEN 0x00000020 204 #define IN_MOVED_FROM 0x00000040 205 #define IN_MOVED_TO 0x00000080 206 #define IN_CREATE 0x00000100 207 #define IN_DELETE 0x00000200 208 #define IN_DELETE_SELF 0x00000400 209 #define IN_MOVE_SELF 0x00000800 210 #define IN_UNMOUNT 0x00002000 211 #define IN_Q_OVERFLOW 0x00004000 212 #define IN_IGNORED 0x00008000 214 #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) 215 #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) 224 #include <sys/inotify.h> 232 register int fd = -1;
234 fd = inotify_init1(IN_CLOEXEC);
240 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
256 inotify_rm_watch(
inotifyFd,
id < 0 ? -
id :
id);
275 QMutableListIterator<QString>
it(p);
276 while (it.hasNext()) {
279 bool isDir = fi.
isDir();
306 perror(
"QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed");
312 int id = isDir ? -wd : wd;
314 directories->
append(path);
335 QMutableListIterator<QString>
it(p);
336 while (it.hasNext()) {
343 int wd =
id < 0 ? -id : id;
370 ioctl(
inotifyFd, FIONREAD, (
char *) &buffSize);
374 char *
const end = at + buffSize;
378 inotify_event *
event =
reinterpret_cast<inotify_event *
>(
at);
385 at +=
sizeof(inotify_event) +
event->len;
389 while (it != eventForId.
constEnd()) {
390 const inotify_event &
event = **
it;
407 if ((
event.mask & (IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT)) != 0) {
427 #endif // QT_NO_FILESYSTEMWATCHER ~QInotifyFileSystemWatcherEngine()
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
QInotifyFileSystemWatcherEngine(int fd)
void fileChanged(const QString &path, bool removed)
#define QT_END_NAMESPACE
This macro expands to.
int remove(const Key &key)
Removes all the items that have the key from the hash.
#define it(className, varName)
#define at(className, varName)
QHash< int, QString > idToPath
static QInotifyFileSystemWatcherEngine * create()
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...
The QHash class is a template class that provides a hash-table-based dictionary.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
void quit()
Tells the thread's event loop to exit with return code 0 (success).
const T value(const Key &key) const
Returns the value associated with the key.
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
QHash< QString, int > pathToID
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QStringList class provides a list of strings.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
void directoryChanged(const QString &path, bool removed)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
The QFileInfo class provides system-independent file information.
static const KeyPair *const end
void run()
The starting point for the thread.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.