Akonadi

agentprocessinstance.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#include "agentprocessinstance.h"
8
9#include "agenttype.h"
10#include "akonadicontrol_debug.h"
11#include "private/standarddirs_p.h"
12#include "processcontrol.h"
13
14#include <QStandardPaths>
15
16using namespace Akonadi;
17
18AgentProcessInstance::AgentProcessInstance(AgentManager &manager)
19 : AgentInstance(manager)
20{
21}
22
23bool AgentProcessInstance::start(const AgentType &agentInfo)
24{
25 Q_ASSERT(!identifier().isEmpty());
26 if (identifier().isEmpty()) {
27 return false;
28 }
29
30 setAgentType(agentInfo.identifier);
31
32 Q_ASSERT(agentInfo.launchMethod == AgentType::Process || agentInfo.launchMethod == AgentType::Launcher);
33
34 const QString executable = (agentInfo.launchMethod == AgentType::Process) ? Akonadi::StandardDirs::findExecutable(agentInfo.exec) : agentInfo.exec;
35
36 if (executable.isEmpty()) {
37 qCWarning(AKONADICONTROL_LOG) << "Unable to find agent executable" << agentInfo.exec;
38 return false;
39 }
40
41 mController = std::make_unique<Akonadi::ProcessControl>();
42 connect(mController.get(), &ProcessControl::unableToStart, this, &AgentProcessInstance::failedToStart);
43
44 if (agentInfo.launchMethod == AgentType::Process) {
45 const QStringList arguments = {QStringLiteral("--identifier"), identifier()};
46 mController->start(executable, arguments);
47 } else {
48 Q_ASSERT(agentInfo.launchMethod == AgentType::Launcher);
49 const QStringList arguments = QStringList() << executable << identifier();
50 const QString agentLauncherExec = Akonadi::StandardDirs::findExecutable(QStringLiteral("akonadi_agent_launcher"));
51 mController->start(agentLauncherExec, arguments);
52 }
53 return true;
54}
55
56void AgentProcessInstance::quit()
57{
58 mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
59 AgentInstance::quit();
60}
61
62void AgentProcessInstance::cleanup()
63{
64 mController->setCrashPolicy(Akonadi::ProcessControl::StopOnCrash);
65 AgentInstance::cleanup();
66}
67
68void AgentProcessInstance::restartWhenIdle()
69{
70 if (mController->isRunning()) {
71 if (status() != 1) {
72 mController->restartOnceWhenFinished();
73 quit();
74 }
75 } else {
76 mController->start();
77 }
78}
79
80void Akonadi::AgentProcessInstance::configure(qlonglong windowId)
81{
82 controlInterface()->configure(windowId);
83}
84
85void AgentProcessInstance::failedToStart()
86{
87 statusChanged(2 /*Broken*/, QStringLiteral("Unable to start."));
88}
89
90#include "moc_agentprocessinstance.cpp"
Represents one agent instance and takes care of communication with it.
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
Status status() const
Returns the status of the agent instance.
QString identifier() const
Returns the unique identifier of the agent instance.
void unableToStart()
Emitted if the process could not be started since it terminated too often.
Helper integration between Akonadi and Qt.
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:49:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.