2021-06-10 20:43:57 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef PENDINGFILEQUEUE_H
|
|
|
|
#define PENDINGFILEQUEUE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMutex>
|
|
|
|
#include "pending-file.h"
|
|
|
|
|
2024-05-27 15:37:19 +08:00
|
|
|
class RemoteFileEventHelper;
|
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-06-10 20:43:57 +08:00
|
|
|
class PendingFileQueue : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static PendingFileQueue *getInstance(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
~PendingFileQueue();
|
|
|
|
//This method will block until current cache has been processed.
|
|
|
|
//Do not do enqueue operation in other thread while this method is running.
|
|
|
|
void forceFinish();
|
|
|
|
void enqueue(const PendingFile& file);
|
|
|
|
QTimer *m_cacheTimer = nullptr;
|
|
|
|
QTimer *m_minProcessTimer = nullptr;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void run() override;
|
2022-10-26 18:01:40 +08:00
|
|
|
|
2021-06-10 20:43:57 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void cacheTimerStart();
|
|
|
|
void minProcessTimerStart();
|
2021-06-11 19:58:32 +08:00
|
|
|
void timerStop();
|
2022-10-26 18:01:40 +08:00
|
|
|
|
|
|
|
void filesUpdate(const QVector<PendingFile>&);
|
2024-05-27 15:37:19 +08:00
|
|
|
|
|
|
|
void signalFileEvent(int eventType, const QString &arg1, const QString &arg2);
|
2021-06-10 20:43:57 +08:00
|
|
|
private:
|
|
|
|
void processCache();
|
|
|
|
explicit PendingFileQueue(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
QVector<PendingFile> m_cache;
|
|
|
|
QMutex m_mutex;
|
|
|
|
|
|
|
|
QThread *m_timerThread = nullptr;
|
2021-06-11 19:58:32 +08:00
|
|
|
int m_enqueuetimes = 0;
|
2021-06-10 20:43:57 +08:00
|
|
|
|
2024-05-27 15:37:19 +08:00
|
|
|
RemoteFileEventHelper *m_fileEventHelper = nullptr;
|
2021-06-10 20:43:57 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // PENDINGFILEQUEUE_H
|