forked from openkylin/ukui-search
新增进程间同步信号量;新增可索引目录默认值;
This commit is contained in:
parent
c6fc1dbceb
commit
ffef1d76ee
|
@ -2,15 +2,20 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
static std::once_flag flag;
|
static std::once_flag flag;
|
||||||
static DirWatcher *global_intance = nullptr;
|
static DirWatcher *global_intance = nullptr;
|
||||||
|
|
||||||
DirWatcher::DirWatcher(QObject *parent) : QObject(parent)
|
DirWatcher::DirWatcher(QObject *parent)
|
||||||
|
: QObject(parent), m_semaphore(QStringLiteral("ukui-search-dir-manager-dbus-register-sem"), 0, QSystemSemaphore::AccessMode::Open)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_dbusInterface = new QDBusInterface("com.ukui.search.fileindex.service",
|
m_dbusInterface = new QDBusInterface("com.ukui.search.fileindex.service",
|
||||||
"/org/ukui/search/privateDirWatcher",
|
"/org/ukui/search/privateDirWatcher",
|
||||||
"org.ukui.search.fileindex");
|
"org.ukui.search.fileindex");
|
||||||
|
m_semaphore.acquire();
|
||||||
|
m_semaphore.release();
|
||||||
if (!m_dbusInterface->isValid()) {
|
if (!m_dbusInterface->isValid()) {
|
||||||
qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError();
|
qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError();
|
||||||
return;
|
return;
|
||||||
|
@ -42,7 +47,7 @@ QStringList DirWatcher::currentIndexableDir()
|
||||||
QDBusReply<QStringList> reply = m_dbusInterface->call("currentIndexableDir");
|
QDBusReply<QStringList> reply = m_dbusInterface->call("currentIndexableDir");
|
||||||
if (!reply.isValid()) {
|
if (!reply.isValid()) {
|
||||||
qCritical() << "currentIndexableDir call filed!";
|
qCritical() << "currentIndexableDir call filed!";
|
||||||
return QStringList();
|
return QStringList() << QString(QDir::homePath());
|
||||||
}
|
}
|
||||||
return reply.value();
|
return reply.value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
|
#include <QSystemSemaphore>
|
||||||
|
|
||||||
class DirWatcher : public QObject
|
class DirWatcher : public QObject
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,8 @@ private:
|
||||||
~DirWatcher() = default;
|
~DirWatcher() = default;
|
||||||
|
|
||||||
QDBusInterface *m_dbusInterface = nullptr;
|
QDBusInterface *m_dbusInterface = nullptr;
|
||||||
|
|
||||||
|
QSystemSemaphore m_semaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MOUNTDISKLISTENER_H
|
#endif // MOUNTDISKLISTENER_H
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
#include <QDBusError>
|
#include <QDBusError>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName) : QtSingleApplication (applicationName, argc, argv)
|
UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName)
|
||||||
|
: QtSingleApplication (applicationName, argc, argv), m_semaphore(QStringLiteral("ukui-search-dir-manager-dbus-register-sem"), 0, QSystemSemaphore::AccessMode::Create)
|
||||||
{
|
{
|
||||||
setQuitOnLastWindowClosed(false);
|
setQuitOnLastWindowClosed(false);
|
||||||
setApplicationVersion(QString("v%1").arg(VERSION));
|
setApplicationVersion(QString("v%1").arg(VERSION));
|
||||||
|
@ -27,6 +28,7 @@ UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], cons
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Ukui search dir manager is running!";
|
qWarning() << "Ukui search dir manager is running!";
|
||||||
}
|
}
|
||||||
|
m_semaphore.release();
|
||||||
//parse cmd
|
//parse cmd
|
||||||
qDebug()<<"parse cmd";
|
qDebug()<<"parse cmd";
|
||||||
auto message = this->arguments().join(' ').toUtf8();
|
auto message = this->arguments().join(' ').toUtf8();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef UKUISEARCHDIRWATCHERDBUS_H
|
#ifndef UKUISEARCHDIRWATCHERDBUS_H
|
||||||
#define UKUISEARCHDIRWATCHERDBUS_H
|
#define UKUISEARCHDIRWATCHERDBUS_H
|
||||||
|
|
||||||
|
#include <QSystemSemaphore>
|
||||||
#include "qtsingleapplication.h"
|
#include "qtsingleapplication.h"
|
||||||
|
|
||||||
class UkuiSearchDirManagerDbus : public QtSingleApplication
|
class UkuiSearchDirManagerDbus : public QtSingleApplication
|
||||||
|
@ -10,6 +11,8 @@ public:
|
||||||
UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName = "ukui-search-service-dir-manager");
|
UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName = "ukui-search-service-dir-manager");
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void parseCmd(QString msg, bool isPrimary);
|
void parseCmd(QString msg, bool isPrimary);
|
||||||
|
private:
|
||||||
|
QSystemSemaphore m_semaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UKUISEARCHDIRWATCHERDBUS_H
|
#endif // UKUISEARCHDIRWATCHERDBUS_H
|
||||||
|
|
Loading…
Reference in New Issue