From 9834b3681fb02ef5eaab19d678b674365a4381e4 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 12 Jan 2012 11:40:51 +0100 Subject: Make QFileSystemWatcherEngines children of QFileSystemWatcher To support moving QFileSystemWatcher to another thread, the engines need to follow when the watcher is moved. The easiest way to do this is by parenting the engines to the watcher. Change-Id: Ie2bb701c0c148da9cc2302d4de23286b8ef42c4d Reviewed-by: Robin Burchell Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemwatcher.cpp | 24 +++++++----------------- src/corelib/io/qfilesystemwatcher_inotify.cpp | 11 ++++++----- src/corelib/io/qfilesystemwatcher_inotify_p.h | 4 ++-- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 11 ++++++----- src/corelib/io/qfilesystemwatcher_kqueue_p.h | 4 ++-- src/corelib/io/qfilesystemwatcher_p.h | 5 +++-- src/corelib/io/qfilesystemwatcher_polling.cpp | 5 +++-- src/corelib/io/qfilesystemwatcher_polling_p.h | 2 +- src/corelib/io/qfilesystemwatcher_win_p.h | 3 +++ 9 files changed, 33 insertions(+), 36 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index b6eb5eda5a..4abb4f3cc1 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -63,16 +63,16 @@ QT_BEGIN_NAMESPACE -QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine() +QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject *parent) { #if defined(Q_OS_WIN) - return new QWindowsFileSystemWatcherEngine; + return new QWindowsFileSystemWatcherEngine(parent); #elif defined(Q_OS_LINUX) // there is a chance that inotify may fail on Linux pre-2.6.13 (August // 2005), so we can't just new inotify directly. - return QInotifyFileSystemWatcherEngine::create(); + return QInotifyFileSystemWatcherEngine::create(parent); #elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC) - return QKqueueFileSystemWatcherEngine::create(); + return QKqueueFileSystemWatcherEngine::create(parent); #else return 0; #endif @@ -86,7 +86,7 @@ QFileSystemWatcherPrivate::QFileSystemWatcherPrivate() void QFileSystemWatcherPrivate::init() { Q_Q(QFileSystemWatcher); - native = createNativeEngine(); + native = createNativeEngine(q); if (native) { QObject::connect(native, SIGNAL(fileChanged(QString,bool)), @@ -105,7 +105,7 @@ void QFileSystemWatcherPrivate::initPollerEngine() return; Q_Q(QFileSystemWatcher); - poller = new QPollingFileSystemWatcherEngine; // that was a mouthful + poller = new QPollingFileSystemWatcherEngine(q); // that was a mouthful QObject::connect(poller, SIGNAL(fileChanged(QString,bool)), q, @@ -216,17 +216,7 @@ QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent Destroys the file system watcher. */ QFileSystemWatcher::~QFileSystemWatcher() -{ - Q_D(QFileSystemWatcher); - if (d->native) { - delete d->native; - d->native = 0; - } - if (d->poller) { - delete d->poller; - d->poller = 0; - } -} +{ } /*! Adds \a path to the file system watcher if \a path exists. The diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 49299e2254..ff732bc70e 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -210,7 +210,7 @@ QT_END_NAMESPACE QT_BEGIN_NAMESPACE -QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create() +QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create(QObject *parent) { register int fd = -1; #ifdef IN_CLOEXEC @@ -221,12 +221,13 @@ QInotifyFileSystemWatcherEngine *QInotifyFileSystemWatcherEngine::create() if (fd == -1) return 0; } - return new QInotifyFileSystemWatcherEngine(fd); + return new QInotifyFileSystemWatcherEngine(fd, parent); } -QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd) - : inotifyFd(fd) - , notifier(fd, QSocketNotifier::Read, this) +QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd, QObject *parent) + : QFileSystemWatcherEngine(parent), + inotifyFd(fd), + notifier(fd, QSocketNotifier::Read, this) { fcntl(inotifyFd, F_SETFD, FD_CLOEXEC); connect(¬ifier, SIGNAL(activated(int)), SLOT(readFromInotify())); diff --git a/src/corelib/io/qfilesystemwatcher_inotify_p.h b/src/corelib/io/qfilesystemwatcher_inotify_p.h index daedb01fac..8b3ce62c46 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify_p.h +++ b/src/corelib/io/qfilesystemwatcher_inotify_p.h @@ -70,7 +70,7 @@ class QInotifyFileSystemWatcherEngine : public QFileSystemWatcherEngine public: ~QInotifyFileSystemWatcherEngine(); - static QInotifyFileSystemWatcherEngine *create(); + static QInotifyFileSystemWatcherEngine *create(QObject *parent); QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories); QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories); @@ -79,7 +79,7 @@ private Q_SLOTS: void readFromInotify(); private: - QInotifyFileSystemWatcherEngine(int fd); + QInotifyFileSystemWatcherEngine(int fd, QObject *parent); int inotifyFd; QHash pathToID; QHash idToPath; diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 8070af5e18..fd7bfa2b27 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -67,17 +67,18 @@ QT_BEGIN_NAMESPACE # define DEBUG if(false)qDebug #endif -QKqueueFileSystemWatcherEngine *QKqueueFileSystemWatcherEngine::create() +QKqueueFileSystemWatcherEngine *QKqueueFileSystemWatcherEngine::create(QObject *parent) { int kqfd = kqueue(); if (kqfd == -1) return 0; - return new QKqueueFileSystemWatcherEngine(kqfd); + return new QKqueueFileSystemWatcherEngine(kqfd, parent); } -QKqueueFileSystemWatcherEngine::QKqueueFileSystemWatcherEngine(int kqfd) - : kqfd(kqfd) - , notifier(kqfd, QSocketNotifier::Read, this) +QKqueueFileSystemWatcherEngine::QKqueueFileSystemWatcherEngine(int kqfd, QObject *parent) + : QFileSystemWatcherEngine(parent), + kqfd(kqfd), + notifier(kqfd, QSocketNotifier::Read, this) { connect(¬ifier, SIGNAL(activated(int)), SLOT(readFromKqueue())); diff --git a/src/corelib/io/qfilesystemwatcher_kqueue_p.h b/src/corelib/io/qfilesystemwatcher_kqueue_p.h index 41afbadf6a..9bd9378c0c 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue_p.h +++ b/src/corelib/io/qfilesystemwatcher_kqueue_p.h @@ -72,7 +72,7 @@ class QKqueueFileSystemWatcherEngine : public QFileSystemWatcherEngine public: ~QKqueueFileSystemWatcherEngine(); - static QKqueueFileSystemWatcherEngine *create(); + static QKqueueFileSystemWatcherEngine *create(QObject *parent); QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories); QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories); @@ -81,7 +81,7 @@ private Q_SLOTS: void readFromKqueue(); private: - QKqueueFileSystemWatcherEngine(int kqfd); + QKqueueFileSystemWatcherEngine(int kqfd, QObject *parent); int kqfd; diff --git a/src/corelib/io/qfilesystemwatcher_p.h b/src/corelib/io/qfilesystemwatcher_p.h index 0f1032c445..9f403b308f 100644 --- a/src/corelib/io/qfilesystemwatcher_p.h +++ b/src/corelib/io/qfilesystemwatcher_p.h @@ -68,7 +68,8 @@ class QFileSystemWatcherEngine : public QObject Q_OBJECT protected: - inline QFileSystemWatcherEngine() + inline QFileSystemWatcherEngine(QObject *parent) + : QObject(parent) { } @@ -94,7 +95,7 @@ class QFileSystemWatcherPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QFileSystemWatcher) - static QFileSystemWatcherEngine *createNativeEngine(); + static QFileSystemWatcherEngine *createNativeEngine(QObject *parent); public: QFileSystemWatcherPrivate(); diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index ef106acd0b..23dca140d6 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -44,8 +44,9 @@ QT_BEGIN_NAMESPACE -QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine() - : timer(this) +QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) + : QFileSystemWatcherEngine(parent), + timer(this) { connect(&timer, SIGNAL(timeout()), SLOT(timeout())); } diff --git a/src/corelib/io/qfilesystemwatcher_polling_p.h b/src/corelib/io/qfilesystemwatcher_polling_p.h index 717d438582..3b3272a890 100644 --- a/src/corelib/io/qfilesystemwatcher_polling_p.h +++ b/src/corelib/io/qfilesystemwatcher_polling_p.h @@ -108,7 +108,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine QHash files, directories; public: - QPollingFileSystemWatcherEngine(); + QPollingFileSystemWatcherEngine(QObject *parent); QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories); QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories); diff --git a/src/corelib/io/qfilesystemwatcher_win_p.h b/src/corelib/io/qfilesystemwatcher_win_p.h index 4da29bb4ce..8e6b779b93 100644 --- a/src/corelib/io/qfilesystemwatcher_win_p.h +++ b/src/corelib/io/qfilesystemwatcher_win_p.h @@ -79,6 +79,9 @@ class QWindowsFileSystemWatcherEngine : public QFileSystemWatcherEngine { Q_OBJECT public: + inline QWindowsFileSystemWatcherEngine(QObject *parent) + : QFileSystemWatcherEngine(parent) + { } ~QWindowsFileSystemWatcherEngine(); QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories); -- cgit v1.2.3