ukui-search/libsearch/index/inotify-watch.h

58 lines
1.5 KiB
C
Raw Normal View History

#ifndef INOTIFYWATCH_H
#define INOTIFYWATCH_H
#include <QThread>
#include <QBuffer>
#include <QSocketNotifier>
#include <QDataStream>
#include <QSharedMemory>
2022-04-14 11:16:26 +08:00
#include <QSystemSemaphore>
#include <sys/prctl.h>
#include <sys/wait.h>
#include <sys/inotify.h>
#include <unistd.h>
#include "traverse_bfs.h"
#include "ukui-search-qdbus.h"
#include "index-status-recorder.h"
#include "file-utils.h"
#include "pending-file-queue.h"
#include "common.h"
2021-12-14 14:43:35 +08:00
namespace UkuiSearch {
class InotifyWatch : public QThread, public Traverse_BFS
{
Q_OBJECT
public:
static InotifyWatch* getInstance();
bool addWatch(const QString &path);
bool removeWatch(const QString &path, bool removeFromDatabase = true);
2022-04-14 11:16:26 +08:00
virtual void work(const QFileInfo &info) final;
2022-04-14 11:16:26 +08:00
void firstTraverse(QStringList pathList = {}, QStringList blockList = {});
void stopWatch();
2022-04-14 11:16:26 +08:00
void addIndexPath(const QString path, const QStringList blockList);
2022-06-02 09:23:53 +08:00
void removeIndexPath(const QString &path, bool fileIndexEnable);
protected:
void run() override;
private Q_SLOTS:
void slotEvent(char *buf, ssize_t len);
private:
explicit InotifyWatch();
~InotifyWatch();
char * filter();
void eventProcess(int socket);
void eventProcess(const char *buffer, ssize_t len);
int m_inotifyFd;
QSocketNotifier* m_notifier = nullptr;
QSharedMemory *m_sharedMemory = nullptr;
2022-04-11 17:46:13 +08:00
QMap<int, QString> m_pathMap;
2022-06-02 09:23:53 +08:00
QMutex m_pathMapLock;
2022-04-14 11:16:26 +08:00
QSystemSemaphore m_semaphore;
};
}
#endif // INOTIFYWATCH_H