- Including Watchdog Timer in CoreBackendManager to ping DBus service.
- Including ExternalCommandHelper::ping slot to receive pings. - Including timer to watch last ping in the service to unregister it after reaching 42 seconds without pings.
This commit is contained in:
parent
ca136dfcaa
commit
47a1519699
|
@ -25,6 +25,7 @@
|
|||
#include <QDBusInterface>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QVector>
|
||||
#include <QUuid>
|
||||
|
||||
|
@ -78,6 +79,22 @@ void CoreBackendManager::startExternalCommandHelper()
|
|||
auto conn = QObject::connect(job(), &KAuth::ExecuteJob::newData, exitLoop);
|
||||
loop.exec();
|
||||
QObject::disconnect(conn);
|
||||
|
||||
// Watchdog Timer for the DBus service
|
||||
QTimer *timer = new QTimer;
|
||||
|
||||
auto sendDBusPing = [&] () {
|
||||
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"),
|
||||
QStringLiteral("/Helper"),
|
||||
QStringLiteral("org.kde.kpmcore.externalcommand"),
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
if (iface.isValid())
|
||||
iface.call(QStringLiteral("ping"), CoreBackendManager::self()->Uuid());
|
||||
};
|
||||
|
||||
QObject::connect(timer, &QTimer::timeout, sendDBusPing);
|
||||
timer->start(20000); // 20 seconds
|
||||
}
|
||||
|
||||
void CoreBackendManager::stopExternalCommandHelper()
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "externalcommandhelper.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QtDBus>
|
||||
#include <QDBusContext>
|
||||
#include <QDebug>
|
||||
|
@ -49,6 +50,13 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
|
|||
HelperSupport::progressStep(QVariantMap());
|
||||
m_loop.exec();
|
||||
reply.addData(QStringLiteral("success"), true);
|
||||
|
||||
m_pingTime = new QDateTime(QDateTime::currentDateTime());
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &ExternalCommandHelper::checkPing);
|
||||
timer->start(20000); // check ping every 20 secs
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -237,6 +245,29 @@ void ExternalCommandHelper::exit(const QString& Uuid)
|
|||
QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper"));
|
||||
}
|
||||
|
||||
void ExternalCommandHelper::ping(const QString &Uuid)
|
||||
{
|
||||
if (!isCallerAuthorized(Uuid))
|
||||
return;
|
||||
|
||||
// update ping
|
||||
m_pingTime->setDate(QDate::currentDate());
|
||||
m_pingTime->setTime(QTime::currentTime());
|
||||
}
|
||||
|
||||
void ExternalCommandHelper::checkPing()
|
||||
{
|
||||
qint64 mSecsSinceLastPing = m_pingTime->msecsTo(QDateTime::currentDateTime());
|
||||
|
||||
qDebug() << (((double)mSecsSinceLastPing) / 1000) << " seconds since the last ping.";
|
||||
|
||||
if (mSecsSinceLastPing >= 42000) { // more than 42 seconds since the last ping
|
||||
qDebug() << "Ending DBus service";
|
||||
|
||||
exit(m_callerUuid);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommandHelper::onReadOutput()
|
||||
{
|
||||
// const QByteArray s = cmd.readAllStandardOutput();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <KAuth>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QEventLoop>
|
||||
#include <QString>
|
||||
#include <QProcess>
|
||||
|
@ -44,6 +45,10 @@ public Q_SLOTS:
|
|||
Q_SCRIPTABLE QVariantMap start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment);
|
||||
Q_SCRIPTABLE bool copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize);
|
||||
Q_SCRIPTABLE void exit(const QString& Uuid);
|
||||
Q_SCRIPTABLE void ping(const QString& Uuid);
|
||||
|
||||
private Q_SLOTS:
|
||||
void checkPing();
|
||||
|
||||
private:
|
||||
void onReadOutput();
|
||||
|
@ -54,6 +59,8 @@ private:
|
|||
QString m_command;
|
||||
QString m_sourceDevice;
|
||||
QProcess m_cmd;
|
||||
|
||||
QDateTime *m_pingTime;
|
||||
// QByteArray output;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue