| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef INOTIFY_IMPL_H |
| 6 | #define INOTIFY_IMPL_H |
| 7 | |
| 8 | #include "inotify_hook.h" |
| 9 | #include "inotify_linux.h" |
| 10 | #include <QDebug> |
| 11 | #include <QObject> |
| 12 | #include <QThread> |
| 13 | |
| 14 | class InotifyImpl : public QObject |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | public: |
| 18 | static InotifyHook *createInotify() |
| 19 | { |
| 20 | InotifyHook *inotifyHook = nullptr; |
| 21 | #ifdef __linux__ |
| 22 | inotifyHook = new InotifyLinux(); |
| 23 | #endif |
| 24 | if (!inotifyHook) { |
| 25 | qCritical() << "Failed, create inotify hook!"; |
| 26 | } |
| 27 | inotifyHook->start(); |
| 28 | inotifyHook->metaObject()->invokeMethod(nullptr, "start"); |
| 29 | return inotifyHook; |
| 30 | } |
| 31 | |
| 32 | static void removeInotify(InotifyHook *hook) |
| 33 | { |
| 34 | if (hook) |
| 35 | hook->stop(); |
| 36 | while (!hook->isFinished()); |
| 37 | delete hook; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | #endif // INOTIFY_IMPL_H |
| 42 |