- Including ExternalCommandHelper asynchronous DBus call in ExternalCommand::execute
- Stop helper before starting a new in CoreBackendManager::startExternalCommandHelper - Unregister org.kde.kpmcore.helperinterface service in ExternalCommandHelper::exit
This commit is contained in:
parent
4b91f2c07e
commit
dac3372a78
|
@ -65,6 +65,8 @@ QVector<KPluginMetaData> CoreBackendManager::list() const
|
||||||
|
|
||||||
void CoreBackendManager::startExternalCommandHelper()
|
void CoreBackendManager::startExternalCommandHelper()
|
||||||
{
|
{
|
||||||
|
stopExternalCommandHelper();
|
||||||
|
|
||||||
KAuth::Action action = KAuth::Action(QStringLiteral("org.kde.kpmcore.externalcommand.init"));
|
KAuth::Action action = KAuth::Action(QStringLiteral("org.kde.kpmcore.externalcommand.init"));
|
||||||
action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand"));
|
action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand"));
|
||||||
action.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
action.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||||
|
|
|
@ -152,6 +152,7 @@ bool ExternalCommand::start(int timeout)
|
||||||
// connect(this, &ExternalCommand::finished, &loop, &QEventLoop::quit);
|
// connect(this, &ExternalCommand::finished, &loop, &QEventLoop::quit);
|
||||||
// loop.exec();
|
// loop.exec();
|
||||||
// return true;
|
// return true;
|
||||||
|
Q_UNUSED(timeout)
|
||||||
execute();
|
execute();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -173,20 +174,43 @@ void ExternalCommand::execute()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus());
|
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"),
|
||||||
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
QStringLiteral("/Helper"),
|
||||||
if (iface.isValid()) {
|
QStringLiteral("org.kde.kpmcore.externalcommand"),
|
||||||
QDBusReply<QVariantMap> reply = iface.call(QStringLiteral("start"), CoreBackendManager::self()->Uuid(), cmd, args(), m_Input, QStringList());
|
QDBusConnection::systemBus());
|
||||||
if (reply.isValid()) {
|
|
||||||
m_Output = reply.value()[QStringLiteral("output")].toByteArray();
|
|
||||||
setExitCode(reply.value()[QStringLiteral("exitCode")].toInt());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qWarning() << reply.error().message();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emit finished();
|
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||||
|
|
||||||
|
if (iface.isValid()) {
|
||||||
|
QDBusPendingCall pcall = iface.asyncCall(QStringLiteral("start"),
|
||||||
|
CoreBackendManager::self()->Uuid(),
|
||||||
|
cmd,
|
||||||
|
args(),
|
||||||
|
m_Input,
|
||||||
|
QStringList());
|
||||||
|
|
||||||
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
|
||||||
|
|
||||||
|
QEventLoop loop;
|
||||||
|
|
||||||
|
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
|
||||||
|
loop.exit();
|
||||||
|
|
||||||
|
if (watcher->isError())
|
||||||
|
qWarning() << watcher->error();
|
||||||
|
else {
|
||||||
|
QDBusPendingReply<QVariantMap> reply = *watcher;
|
||||||
|
|
||||||
|
m_Output = reply.value()[QStringLiteral("output")].toByteArray();
|
||||||
|
setExitCode(reply.value()[QStringLiteral("exitCode")].toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
emit finished();
|
||||||
|
};
|
||||||
|
|
||||||
|
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
|
||||||
|
loop.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalCommand::write(const QByteArray& input)
|
bool ExternalCommand::write(const QByteArray& input)
|
||||||
|
@ -210,7 +234,7 @@ bool ExternalCommand::waitFor(int timeout)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// onReadOutput();
|
// onReadOutput();
|
||||||
|
Q_UNUSED(timeout)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,6 +225,11 @@ void ExternalCommandHelper::exit(const QString& Uuid)
|
||||||
{
|
{
|
||||||
isCallerAuthorized(Uuid);
|
isCallerAuthorized(Uuid);
|
||||||
m_loop.exit();
|
m_loop.exit();
|
||||||
|
|
||||||
|
if (QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")))
|
||||||
|
qDebug() << "org.kde.kpmcore.helperinterface unregistered";
|
||||||
|
|
||||||
|
QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalCommandHelper::onReadOutput()
|
void ExternalCommandHelper::onReadOutput()
|
||||||
|
|
Loading…
Reference in New Issue