添加远程调用流程,用于智能数据管理获取文件创建事件

indexupdater和pendingupdatequeue增加信号用于线程间通信
新增RemoteFileEventHelper类,用于管理replica实例
This commit is contained in:
Yue-Lan 2024-05-27 15:37:19 +08:00
parent a7e78889e8
commit d6f7e768a3
8 changed files with 111 additions and 2 deletions

View File

@ -111,7 +111,7 @@ set(LIBUKUI_SEARCH_SRC
icon-loader.cpp icon-loader.h
data-collecter.cpp
data-collecter.h
remote-file-event-helper.cpp
)
qt5_generate_repc(LIBUKUI_SEARCH_SRC index/monitor.rep REPLICA)
set(QRC_FILES resource1.qrc)
@ -119,6 +119,8 @@ file(GLOB TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../translations/libukui-search/*.
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/libsearch/.qm)
qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES})
qt5_generate_repc(LIBUKUI_SEARCH_SRC fileeventhandler.rep REPLICA)
add_library(${PROJECT_NAME} SHARED
${LIBUKUI_SEARCH_SRC}
${QRC_FILES}
@ -231,4 +233,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-search-config.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})
if(BUILD_TEST)
add_subdirectory(test)
endif ()
endif ()

View File

@ -0,0 +1,6 @@
#include <QtCore>
class FileEventHandler
{
SLOT(void handleFileEvent(int eventType, QString arg1, QString arg2))
}

View File

@ -29,6 +29,7 @@
#include "compatible-define.h"
#include "index-status-recorder.h"
#include "ai-indexer.h"
#include "pending-file-queue.h"
using namespace UkuiSearch;
IndexUpdater::IndexUpdater(const QVector<PendingFile>& files,
QAtomicInt& indexstop,
@ -41,6 +42,7 @@ IndexUpdater::IndexUpdater(const QVector<PendingFile>& files,
m_contentIndexOcrStop(&contentIndexOcrStop),
m_aiIndexStop(&aiIndexStop)
{
connect(this, &IndexUpdater::indexUpdated, PendingFileQueue::getInstance(), &PendingFileQueue::signalFileEvent);
}
void IndexUpdater::updateIndex()
{
@ -55,6 +57,11 @@ void IndexUpdater::updateIndex()
}
qDebug() << "===update basic index===";
for(const PendingFile& file : m_cache) {
// notify ukui-idm
if (file.isCreated()) {
Q_EMIT indexUpdated(1, file.path(), nullptr);
}
if(file.shouldRemoveIndex()) {
qDebug() << "| remove:" <<file.path();
basicDb.removeDocument(file.path());

View File

@ -40,6 +40,7 @@ public:
Q_SIGNALS:
void done();
void indexUpdated(int eventType, const QString &arg1, const QString &arg2);
private:
void updateIndex();

View File

@ -21,6 +21,8 @@
#include "file-utils.h"
#include <malloc.h>
#include "index-status-recorder.h"
#include "remote-file-event-helper.h"
using namespace UkuiSearch;
static PendingFileQueue *global_instance_pending_file_queue = nullptr;
PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent)
@ -38,6 +40,9 @@ PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent)
m_cacheTimer->moveToThread(this);
m_minProcessTimer->moveToThread(this);
m_fileEventHelper = new RemoteFileEventHelper;
m_fileEventHelper->moveToThread(this);
// connect(this, &PendingFileQueue::cacheTimerStart, m_cacheTimer, f, Qt::DirectConnection);
// connect(this, &PendingFileQueue::minProcessTimerStart, m_minProcessTimer, f,Qt::DirectConnection);
connect(this, SIGNAL(cacheTimerStart()), m_cacheTimer, SLOT(start()));
@ -47,6 +52,8 @@ PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent)
connect(m_cacheTimer, &QTimer::timeout, this, &PendingFileQueue::processCache, Qt::DirectConnection);
connect(m_minProcessTimer, &QTimer::timeout, this, &PendingFileQueue::processCache, Qt::DirectConnection);
connect(this, &PendingFileQueue::signalFileEvent, m_fileEventHelper, &RemoteFileEventHelper::handleFileEventRequest);
}
PendingFileQueue *PendingFileQueue::getInstance(QObject *parent)
@ -67,6 +74,11 @@ PendingFileQueue::~PendingFileQueue()
delete m_minProcessTimer;
m_minProcessTimer = nullptr;
}
if(m_fileEventHelper) {
delete m_fileEventHelper;
m_fileEventHelper = nullptr;
}
global_instance_pending_file_queue = nullptr;
}

View File

@ -27,6 +27,8 @@
#include <QMutex>
#include "pending-file.h"
class RemoteFileEventHelper;
namespace UkuiSearch {
class PendingFileQueue : public QThread
{
@ -51,6 +53,8 @@ Q_SIGNALS:
void timerStop();
void filesUpdate(const QVector<PendingFile>&);
void signalFileEvent(int eventType, const QString &arg1, const QString &arg2);
private:
void processCache();
explicit PendingFileQueue(QObject *parent = nullptr);
@ -61,6 +65,7 @@ private:
QThread *m_timerThread = nullptr;
int m_enqueuetimes = 0;
RemoteFileEventHelper *m_fileEventHelper = nullptr;
};
}
#endif // PENDINGFILEQUEUE_H

View File

@ -0,0 +1,48 @@
#include "remote-file-event-helper.h"
#include "rep_fileeventhandler_replica.h"
#include <QtRemoteObjects>
#include <QDebug>
RemoteFileEventHelper::RemoteFileEventHelper(QObject *parent) : QObject(parent)
{
setupConnections();
}
RemoteFileEventHelper::~RemoteFileEventHelper()
{
delete m_fileEventHandlerIface;
delete m_remoteNode;
}
void RemoteFileEventHelper::setupConnections()
{
m_remoteNode = new QRemoteObjectNode;
m_remoteNode->connectToNode(nodeUrl());
m_fileEventHandlerIface = m_remoteNode->acquire<FileEventHandlerReplica>();
qDebug() << "connect handle" << m_fileEventHandlerIface;
connect(m_fileEventHandlerIface, &QRemoteObjectReplica::initialized, this, [=]{
qDebug() << "initilized" << m_fileEventHandlerIface;
});
connect(m_fileEventHandlerIface, &QRemoteObjectReplica::stateChanged, this, [=](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState){
qDebug() << "state changed" << state << oldState << m_fileEventHandlerIface;
if (state == QRemoteObjectReplica::Suspect) {
qDebug() << "try reconnect";
m_fileEventHandlerIface->deleteLater();
m_remoteNode->deleteLater();
setupConnections();
}
});
connect(this, &RemoteFileEventHelper::handleFileEventRequest, m_fileEventHandlerIface, [=](int type, const QString &arg1, const QString &arg2){
qDebug() << type << arg1 << arg2 << m_fileEventHandlerIface;
if (m_fileEventHandlerIface->state() == QRemoteObjectReplica::Valid)
m_fileEventHandlerIface->handleFileEvent(type, arg1, arg2);
});
}
QUrl RemoteFileEventHelper::nodeUrl()
{
QString displayEnv = (qgetenv("XDG_SESSION_TYPE") == "wayland") ? QLatin1String("WAYLAND_DISPLAY") : QLatin1String("DISPLAY");
QString display(qgetenv(displayEnv.toUtf8().data()));
return QUrl(QStringLiteral("local:ukui-idm-") + QString(qgetenv("USER")) + display);
}

View File

@ -0,0 +1,28 @@
#ifndef REMOTEFILEEVENTHELPER_H
#define REMOTEFILEEVENTHELPER_H
#include <QObject>
#include <QUrl>
class QRemoteObjectNode;
class FileEventHandlerReplica;
class RemoteFileEventHelper : public QObject
{
Q_OBJECT
public:
explicit RemoteFileEventHelper(QObject *parent = nullptr);
~RemoteFileEventHelper();
Q_SIGNALS:
void handleFileEventRequest(int type, const QString &arg1, const QString &arg2);
private:
void setupConnections();
static QUrl nodeUrl();
QRemoteObjectNode *m_remoteNode = nullptr;
FileEventHandlerReplica *m_fileEventHandlerIface = nullptr;
};
#endif // REMOTEFILEEVENTHELPER_H