Skip to content

Commit

Permalink
fix: 修复系统启动后dmanHelper成为常驻进程的问题
Browse files Browse the repository at this point in the history
  后端内置定时器,每5秒检查前端dman是否存在,若不存在,则后端dmanHelper退出

Log: 修复系统启动后dmanHelper成为常驻进程的问题
  • Loading branch information
starhcq authored and rb-union committed Jul 27, 2023
1 parent 688962a commit 45212dd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ add_executable(dmanHelper
dbus/manual_search_adapter.h
dbus/manual_search_proxy.cpp
dbus/manual_search_proxy.h
dbus/dmanwatcher.cpp
dbus/dmanwatcher.h
base/command.cpp
base/command.h
controller/helpermanager.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/app/dman_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "dbus/dbus_consts.h"
#include "dbus/manual_search_adapter.h"
#include "dbus/manual_search_proxy.h"
#include "dbus/dmanwatcher.h"

#include <DLog>
#include "base/utils.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ int main(int argc, char **argv)
}
#endif

// 后端服务dmanHelper自检,若前端dman应用不存在,则后端dmanHelper退出
DManWatcher watcher;
ManualSearchProxy search_obj;
ManualSearchAdapter adapter(&search_obj);

Expand Down
42 changes: 42 additions & 0 deletions src/dbus/dmanwatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dmanwatcher.h"

#include <QProcess>
#include <QCoreApplication>
#include <QDebug>

DManWatcher::DManWatcher():m_Timer(new QTimer (this))
{

connect(m_Timer,&QTimer::timeout,this,&DManWatcher::onTimeOut);
m_Timer->start(5000);
}

/**
* @brief 定时监控客户端
*/
void DManWatcher::onTimeOut()
{
QString cmd, outPut;
//判断dman客户端是否存在,如果不存在退出服务。
cmd = QString("ps aux | grep -w dman$");
outPut= executCmd(cmd);
int ret = outPut.length();
if (!ret)
QCoreApplication::exit(0);
}

/**
* @brief 执行外部命令
* @param strCmd:外部命令字符串
*/
QString DManWatcher::executCmd(const QString &strCmd)
{
QProcess proc;
proc.start("bash", QStringList() << "-c" << strCmd);
proc.waitForFinished(-1);
return proc.readAllStandardOutput();
}
29 changes: 29 additions & 0 deletions src/dbus/dmanwatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DMANWATCHER_H
#define DMANWATCHER_H

#include <QObject>
#include <QTimer>

/**
* @class DManWatcher
* @brief 监控客户端类
*/
class DManWatcher :public QObject
{
Q_OBJECT
public:
explicit DManWatcher();

public Q_SLOTS:
void onTimeOut();
private:
QString executCmd(const QString &strCmd);
private:
QTimer *m_Timer=nullptr;
};

#endif // DMANWATCHER_H
2 changes: 2 additions & 0 deletions src/view/theme_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "view/theme_proxy.h"
#include <DApplicationHelper>

DGUI_USE_NAMESPACE

ThemeProxy::ThemeProxy(QObject *parent)
: QObject(parent)
{
Expand Down

0 comments on commit 45212dd

Please sign in to comment.