Akonadi

processcontrol.h
1 /***************************************************************************
2  * Copyright (C) 2006 by Tobias Koenig <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #ifndef AKONADI_PROCESSCONTROL_H
21 #define AKONADI_PROCESSCONTROL_H
22 
23 #include <QObject>
24 #include <QProcess>
25 
26 #include <chrono>
27 
28 namespace Akonadi
29 {
30 
35 class ProcessControl : public QObject
36 {
37  Q_OBJECT
38 
39 public:
47  enum CrashPolicy {
48  StopOnCrash,
49  RestartOnCrash
50  };
51 
57  explicit ProcessControl(QObject *parent = nullptr);
58 
63 
67  void start(const QString &application, const QStringList &arguments = QStringList(),
68  CrashPolicy policy = RestartOnCrash);
69 
73  void start();
74 
78  void stop();
79 
83  void setCrashPolicy(CrashPolicy policy);
84 
89  {
90  mRestartOnceOnExit = true;
91  }
92 
96  Q_REQUIRED_RESULT bool isRunning() const;
97 
104  void setShutdownTimeout(std::chrono::milliseconds timeout);
105 
106 Q_SIGNALS:
113  void processErrorMessages(const QString &errorMsg);
114 
118  void restarted();
119 
124  void unableToStart();
125 
126 private Q_SLOTS:
127  void slotError(QProcess::ProcessError);
128  void slotFinished(int, QProcess::ExitStatus);
129  void resetCrashCount();
130 
131 private:
132  QProcess mProcess;
133  QString mApplication;
134  QStringList mArguments;
135  CrashPolicy mPolicy;
136  bool mFailedToStart;
137  int mCrashCount;
138  bool mRestartOnceOnExit;
139  std::chrono::milliseconds mShutdownTimeout;
140 };
141 
142 }
143 
144 #endif
void setCrashPolicy(CrashPolicy policy)
Sets the crash policy.
void stop()
Stops the currently running application.
void restarted()
This signal is emitted when the server is restarted after a crash.
~ProcessControl()
Destroys the process control.
Q_SIGNALSQ_SIGNALS
void restartOnceWhenFinished()
Restart the application the next time it exits normally.
void start()
Starts the process with the previously set application and arguments.
Q_OBJECTQ_OBJECT
void unableToStart()
Emitted if the process could not be started since it terminated too often.
void processErrorMessages(const QString &errorMsg)
This signal is emitted whenever the observed application writes something to stderr.
This class starts and observes a process.
CrashPolicy
Theses enums describe the behaviour when the observed application crashed.
ProcessControl(QObject *parent=nullptr)
Creates a new process control.
Helper integration between Akonadi and Qt.
void setShutdownTimeout(std::chrono::milliseconds timeout)
Sets the time (in msecs) we wait for the process to shut down before we send terminate/kill signals...
bool isRunning() const
Returns true if the process is currently running.
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.