Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfilesystemwatcher_fsevents_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QFILESYSTEMWATCHER_FSEVENTS_P_H
6#define QFILESYSTEMWATCHER_FSEVENTS_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20
21#include <QtCore/qhash.h>
22#include <QtCore/qmutex.h>
23#include <QtCore/qsocketnotifier.h>
24#include <QtCore/qthread.h>
25
26#include <dispatch/dispatch.h>
27#include <CoreServices/CoreServices.h>
28
30
31QT_BEGIN_NAMESPACE
32
33class QFseventsFileSystemWatcherEngine : public QFileSystemWatcherEngine
34{
35 Q_OBJECT
36public:
37 ~QFseventsFileSystemWatcherEngine();
38
39 static QFseventsFileSystemWatcherEngine *create(QObject *parent);
40
41 QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories);
42 QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
43
44 void processEvent(ConstFSEventStreamRef streamRef, size_t numEvents, char **eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
45
46Q_SIGNALS:
47 void emitFileChanged(const QString &path, bool removed);
48 void emitDirectoryChanged(const QString &path, bool removed);
49 void scheduleStreamRestart();
50
51private Q_SLOTS:
52 void doEmitFileChanged(const QString &path, bool removed);
53 void doEmitDirectoryChanged(const QString &path, bool removed);
54 bool restartStream();
55
56public:
57 struct Info {
58 QString origPath;
59 timespec ctime;
60 mode_t mode;
61 QString watchedPath;
62
63 Info(): mode(0)
64 {
65 ctime.tv_sec = 0;
66 ctime.tv_nsec = 0;
67 }
68
69 Info(const QString &origPath, const timespec &ctime, mode_t mode, const QString &watchedPath)
70 : origPath(origPath)
71 , ctime(ctime)
72 , mode(mode)
73 , watchedPath(watchedPath)
74 {}
75 };
76
77private:
78 typedef QHash<QString, Info> InfoByName;
79 typedef QHash<QString, InfoByName> FilesByPath;
80 struct DirInfo {
81 Info dirInfo;
82 InfoByName entries;
83 };
84 typedef QHash<QString, DirInfo> DirsByName;
85 typedef QHash<QString, qint64> PathRefCounts;
86
87 struct WatchingState {
88 // These fields go hand-in-hand. FSEvents watches paths, and there is no use in watching
89 // the same path multiple times. So, the "refcount" on a path is the number of watched
90 // files that have the same path, plus the number of directories that have the same path.
91 //
92 // If the stream fails to start after adding files/directories, the watcher will try to
93 // keep watching files/directories that it was already watching. It does that by restoring
94 // the previous WatchingState and restarting the stream.
95 FilesByPath watchedFiles;
96 DirsByName watchedDirectories;
97 PathRefCounts watchedPaths;
98 };
99
100 QFseventsFileSystemWatcherEngine(QObject *parent);
101 bool startStream();
102 void stopStream(bool isStopped = false);
103 InfoByName scanForDirEntries(const QString &path);
104 bool derefPath(const QString &watchedPath);
105 bool checkDir(DirsByName::iterator &it);
106 bool rescanDirs(const QString &path);
107 bool rescanFiles(InfoByName &filesInPath);
108 bool rescanFiles(const QString &path);
109
110 QMutex lock;
111 dispatch_queue_t queue;
112 FSEventStreamRef stream;
113 FSEventStreamEventId lastReceivedEvent;
114 WatchingState watchingState;
115};
116
117QT_END_NAMESPACE
118
119#endif // QFILESYSTEMWATCHER_FSEVENTS_P_H
Combined button and popup list for selecting options.
const QString & asString(const QString &s)
Definition qstring.h:1678
QT_REQUIRE_CONFIG(filesystemwatcher)
static void callBackFunction(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
static QT_BEGIN_NAMESPACE bool isSameTimestampAndMode(const QT_STATBUF &statbuff, const QFseventsFileSystemWatcherEngine::Info &info)
#define qPrintable(string)
Definition qstring.h:1683