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 <robin+qt@viroteck.net> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
716905cd56
commit
9834b3681f
@ -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
|
||||
|
@ -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()));
|
||||
|
@ -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<QString, int> pathToID;
|
||||
QHash<int, QString> idToPath;
|
||||
|
@ -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()));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
|
||||
QHash<QString, FileInfo> 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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user