2023-07-10 10:18:33 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2023-08-07 14:25:22 +08:00
|
|
|
#include "dbus/instanceservice.h"
|
2023-11-03 14:56:31 +08:00
|
|
|
#include "constant.h"
|
2023-09-14 17:57:44 +08:00
|
|
|
#include "propertiesForwarder.h"
|
2023-11-03 14:56:31 +08:00
|
|
|
#include <QDBusMessage>
|
|
|
|
#include "global.h"
|
2023-07-10 10:18:33 +08:00
|
|
|
|
2023-09-13 16:52:53 +08:00
|
|
|
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath, QString launcher)
|
|
|
|
: m_Launcher(std::move(launcher))
|
|
|
|
, m_instanceId(std::move(instanceId))
|
2023-07-24 14:12:59 +08:00
|
|
|
, m_Application(std::move(application))
|
2023-07-21 14:47:40 +08:00
|
|
|
, m_SystemdUnitPath(std::move(systemdUnitPath))
|
2023-07-10 10:18:33 +08:00
|
|
|
{
|
2023-09-14 17:57:44 +08:00
|
|
|
new PropertiesForwarder{application + "/" + instanceId, this};
|
2023-07-10 10:18:33 +08:00
|
|
|
}
|
|
|
|
|
2023-07-17 14:49:35 +08:00
|
|
|
InstanceService::~InstanceService() = default;
|
2023-11-03 14:56:31 +08:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|