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
56private:
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 typedef QHash<QString, Info> InfoByName;
77 typedef QHash<QString, InfoByName> FilesByPath;
78 struct DirInfo {
79 Info dirInfo;
80 InfoByName entries;
81 };
82 typedef QHash<QString, DirInfo> DirsByName;
83 typedef QHash<QString, qint64> PathRefCounts;
84
85 struct WatchingState {
86 // These fields go hand-in-hand. FSEvents watches paths, and there is no use in watching
87 // the same path multiple times. So, the "refcount" on a path is the number of watched
88 // files that have the same path, plus the number of directories that have the same path.
89 //
90 // If the stream fails to start after adding files/directories, the watcher will try to
91 // keep watching files/directories that it was already watching. It does that by restoring
92 // the previous WatchingState and restarting the stream.
93 FilesByPath watchedFiles;
94 DirsByName watchedDirectories;
95 PathRefCounts watchedPaths;
96 };
97
98 QFseventsFileSystemWatcherEngine(QObject *parent);
99 bool startStream();
100 void stopStream(bool isStopped = false);
101 InfoByName scanForDirEntries(const QString &path);
102 bool derefPath(const QString &watchedPath);
103 bool checkDir(DirsByName::iterator &it);
104 bool rescanDirs(const QString &path);
105 bool rescanFiles(InfoByName &filesInPath);
106 bool rescanFiles(const QString &path);
107
108 QMutex lock;
109 dispatch_queue_t queue;
110 FSEventStreamRef stream;
111 FSEventStreamEventId lastReceivedEvent;
112 WatchingState watchingState;
113};
114
115QT_END_NAMESPACE
116
117#endif // QFILESYSTEMWATCHER_FSEVENTS_P_H
const QString & asString(const QString &s)
Definition qstring.h:1680
QT_REQUIRE_CONFIG(filesystemwatcher)
static QT_BEGIN_NAMESPACE void callBackFunction(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
#define qPrintable(string)
Definition qstring.h:1685