feat: add Method "KillAll"

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-11-03 14:56:31 +08:00 committed by Comix
parent a330ad8f2b
commit 03deb2c935
4 changed files with 31 additions and 2 deletions

View File

@ -41,5 +41,12 @@
to which the instance belonged has been removed."
/>
</property>
<method name="KillAll">
<arg type="i" name="signal" direction="in"/>
<annotation name="org.freedesktop.DBus.Description"
value="Force kill this instance.
ATTENTION: All processes which launched by
this instance will be killed." />
</method>
</interface>
</node>

View File

@ -8,6 +8,7 @@
constexpr auto SystemdService = u8"org.freedesktop.systemd1";
constexpr auto SystemdObjectPath = u8"/org/freedesktop/systemd1";
constexpr auto SystemdInterfaceName = u8"org.freedesktop.systemd1.Manager";
constexpr auto SystemdUnitInterfaceName = u8"org.freedesktop.systemd1.Unit";
constexpr auto DDEApplicationManager1ServiceName =
#ifdef DDE_AM_USE_DEBUG_DBUS_NAME
u8"org.desktopspec.debug.ApplicationManager1";

View File

@ -3,8 +3,10 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "dbus/instanceservice.h"
#include "constant.h"
#include "propertiesForwarder.h"
#include <QCoreApplication>
#include <QDBusMessage>
#include "global.h"
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher)
: m_Launcher(std::move(launcher))
@ -16,3 +18,18 @@ InstanceService::InstanceService(QString instanceId, QString application, QStrin
}
InstanceService::~InstanceService() = default;
void InstanceService::KillAll(int signal)
{
auto killMsg = QDBusMessage::createMethodCall(SystemdService, m_SystemdUnitPath.path(), SystemdUnitInterfaceName, "Kill");
killMsg << QString{"all"} << signal;
auto &con = ApplicationManager1DBus::instance().globalDestBus();
auto reply = con.call(killMsg);
if (reply.type() == QDBusMessage::ReplyMessage) {
return;
}
sendErrorReply(reply.errorName(), reply.errorMessage());
}

View File

@ -7,8 +7,9 @@
#include <QObject>
#include <QDBusObjectPath>
#include <QDBusContext>
class InstanceService : public QObject
class InstanceService : public QObject, protected QDBusContext
{
Q_OBJECT
public:
@ -25,6 +26,9 @@ public:
[[nodiscard]] const QString &instanceId() const noexcept { return m_instanceId; }
public Q_SLOTS:
void KillAll(int signal);
Q_SIGNALS:
void orphanedChanged();