1 /***************************************************************************
2 * Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
3 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef _PROCESSCONTROL_H
22 #define _PROCESSCONTROL_H
24 #include <QtCore/QObject>
25 #include <QtCore/QProcess>
29 * This class starts and observes a process. Depending on the
30 * policy it also restarts the process when it crashes.
32 class ProcessControl
: public QObject
38 * Theses enums describe the behaviour when the observed
39 * application crashed.
41 * @li StopOnCrash - The application won't be restarted.
42 * @li RestartOnCrash - The application is restarted with the same arguments.
51 * Creates a new process control.
53 * @param parent The parent object.
55 ProcessControl( QObject
*parent
= 0 );
58 * Destroys the process control.
63 * Starts the @p application with the given list of @p arguments.
65 bool start( const QString
&application
, const QStringList
&arguments
= QStringList(),
66 CrashPolicy policy
= RestartOnCrash
, int maxCrashes
= 5 );
69 * Stops the currently running application.
74 * Sets the crash policy.
76 void setCrashPolicy( CrashPolicy policy
);
78 bool isRunning() const;
82 * This signal is emitted whenever the observed application
83 * writes something to stderr.
85 * @param errorMsg The error output of the observed application.
87 void processErrorMessages( const QString
&errorMsg
);
89 void finished( bool clean
);
92 void slotError( QProcess::ProcessError
);
93 void slotFinished( int, QProcess::ExitStatus
);
94 void slotErrorMessages();
95 void slotStdoutMessages();
101 QString mApplication
;
102 QStringList mArguments
;