From 4273c14e57d26cf2dde90ed9db1f463a25b327bd Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 29 Nov 2013 12:55:59 +0100 Subject: Mac: FSEvents-based QFileSystemWatcherEngine. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use FSEvents to monitor changes in the filesystem instead of the kqueue implementation. This removes the limit of wathed files: kqueue uses a file descriptor for each file monitored, for which the ulimit was set by default to 256. Now the OSX implementation on par with the other major desktop platforms. Change-Id: I2d46cca811978621989fd35201138df88a37c0fb Reviewed-by: Morten Johan Sørvig --- src/corelib/io/qfilesystemwatcher_fsevents_p.h | 142 +++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/corelib/io/qfilesystemwatcher_fsevents_p.h (limited to 'src/corelib/io/qfilesystemwatcher_fsevents_p.h') diff --git a/src/corelib/io/qfilesystemwatcher_fsevents_p.h b/src/corelib/io/qfilesystemwatcher_fsevents_p.h new file mode 100644 index 0000000000..c899c556c8 --- /dev/null +++ b/src/corelib/io/qfilesystemwatcher_fsevents_p.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFILESYSTEMWATCHER_FSEVENTS_P_H +#define QFILESYSTEMWATCHER_FSEVENTS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "qfilesystemwatcher_p.h" + +#include +#include +#include +#include +#include + +#include +#include + +#ifndef QT_NO_FILESYSTEMWATCHER + +QT_BEGIN_NAMESPACE + +class QFseventsFileSystemWatcherEngine : public QFileSystemWatcherEngine +{ + Q_OBJECT +public: + ~QFseventsFileSystemWatcherEngine(); + + static QFseventsFileSystemWatcherEngine *create(QObject *parent); + + QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories); + QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories); + + void processEvent(ConstFSEventStreamRef streamRef, size_t numEvents, char **eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]); + +Q_SIGNALS: + void emitFileChanged(const QString path, bool removed); + void emitDirectoryChanged(const QString path, bool removed); + +private slots: + void doEmitFileChanged(const QString path, bool removed); + void doEmitDirectoryChanged(const QString path, bool removed); + +private: + struct Info { + QString origPath; + timespec ctime; + mode_t mode; + QString watchedPath; + + Info(): mode(0) + { + ctime.tv_sec = 0; + ctime.tv_nsec = 0; + } + + Info(const QString &origPath, const timespec &ctime, mode_t mode, const QString &watchedPath) + : origPath(origPath) + , ctime(ctime) + , mode(mode) + , watchedPath(watchedPath) + {} + }; + typedef QHash InfoByName; + typedef QHash FilesByPath; + struct DirInfo { + Info dirInfo; + InfoByName entries; + }; + typedef QHash DirsByName; + typedef QHash PathRefCounts; + + QFseventsFileSystemWatcherEngine(QObject *parent); + bool startStream(); + void stopStream(bool isStopped = false); + InfoByName scanForDirEntries(const QString &path); + void derefPath(const QString &watchedPath); + void checkDir(DirsByName::iterator &it); + void rescanDirs(const QString &path); + void rescanFiles(InfoByName &filesInPath); + void rescanFiles(const QString &path); + + QMutex lock; + dispatch_queue_t queue; + FSEventStreamRef stream; + FilesByPath watchedFiles; + DirsByName watchedDirectories; + PathRefCounts watchedPaths; +}; + +QT_END_NAMESPACE + +#endif //QT_NO_FILESYSTEMWATCHER +#endif // QFILESYSTEMWATCHER_FSEVENTS_P_H -- cgit v1.2.3