Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QFILESYSTEMWATCHER_FSEVENTS_P_H
5#define QFILESYSTEMWATCHER_FSEVENTS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19
20#include <QtCore/qhash.h>
21#include <QtCore/qmutex.h>
22#include <QtCore/qsocketnotifier.h>
23#include <QtCore/qthread.h>
24
25#include <dispatch/dispatch.h>
26#include <CoreServices/CoreServices.h>
27
28QT_REQUIRE_CONFIG(filesystemwatcher);
29
31
33{
35public:
37
39
42
43 void processEvent(ConstFSEventStreamRef streamRef, size_t numEvents, char **eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
44
46 void emitFileChanged(const QString &path, bool removed);
47 void emitDirectoryChanged(const QString &path, bool removed);
49
50private slots:
51 void doEmitFileChanged(const QString &path, bool removed);
52 void doEmitDirectoryChanged(const QString &path, bool removed);
53 bool restartStream();
54
55private:
56 struct Info {
57 QString origPath;
58 timespec ctime;
59 mode_t mode;
60 QString watchedPath;
61
62 Info(): mode(0)
63 {
64 ctime.tv_sec = 0;
65 ctime.tv_nsec = 0;
66 }
67
68 Info(const QString &origPath, const timespec &ctime, mode_t mode, const QString &watchedPath)
69 : origPath(origPath)
70 , ctime(ctime)
71 , mode(mode)
72 , watchedPath(watchedPath)
73 {}
74 };
75 typedef QHash<QString, Info> InfoByName;
76 typedef QHash<QString, InfoByName> FilesByPath;
77 struct DirInfo {
78 Info dirInfo;
79 InfoByName entries;
80 };
81 typedef QHash<QString, DirInfo> DirsByName;
82 typedef QHash<QString, qint64> PathRefCounts;
83
84 struct WatchingState {
85 // These fields go hand-in-hand. FSEvents watches paths, and there is no use in watching
86 // the same path multiple times. So, the "refcount" on a path is the number of watched
87 // files that have the same path, plus the number of directories that have the same path.
88 //
89 // If the stream fails to start after adding files/directories, the watcher will try to
90 // keep watching files/directories that it was already watching. It does that by restoring
91 // the previous WatchingState and restarting the stream.
92 FilesByPath watchedFiles;
93 DirsByName watchedDirectories;
94 PathRefCounts watchedPaths;
95 };
96
98 bool startStream();
99 void stopStream(bool isStopped = false);
100 InfoByName scanForDirEntries(const QString &path);
101 bool derefPath(const QString &watchedPath);
102 bool checkDir(DirsByName::iterator &it);
103 bool rescanDirs(const QString &path);
104 bool rescanFiles(InfoByName &filesInPath);
105 bool rescanFiles(const QString &path);
106
107 QMutex lock;
108 dispatch_queue_t queue;
109 FSEventStreamRef stream;
110 FSEventStreamEventId lastReceivedEvent;
111 WatchingState watchingState;
112};
113
115
116#endif // QFILESYSTEMWATCHER_FSEVENTS_P_H
void processEvent(ConstFSEventStreamRef streamRef, size_t numEvents, char **eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories)
void emitDirectoryChanged(const QString &path, bool removed)
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories)
void emitFileChanged(const QString &path, bool removed)
friend class iterator
Definition qhash.h:1142
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QSet< QString >::iterator it
Combined button and popup list for selecting options.
EGLStreamKHR stream
GLenum mode
GLsizei const GLuint * paths
GLsizei const GLchar *const * path
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define slots
#define Q_SIGNALS
QStringList files
[8]
view create()