add more spacing
[personal-kdebase.git] / runtime / nepomuk / server / processcontrol.h
blob4f4e12f2b98acaf40da9bbd7ee828109957d400c
1 /***************************************************************************
2 * Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
3 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
4 * *
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. *
9 * *
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. *
14 * *
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>
28 /**
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
34 Q_OBJECT
36 public:
37 /**
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.
44 enum CrashPolicy
46 StopOnCrash,
47 RestartOnCrash
50 /**
51 * Creates a new process control.
53 * @param parent The parent object.
55 ProcessControl( QObject *parent = 0 );
57 /**
58 * Destroys the process control.
60 ~ProcessControl();
62 /**
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 );
68 /**
69 * Stops the currently running application.
71 void stop();
73 /**
74 * Sets the crash policy.
76 void setCrashPolicy( CrashPolicy policy );
78 bool isRunning() const;
80 Q_SIGNALS:
81 /**
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 );
91 private Q_SLOTS:
92 void slotError( QProcess::ProcessError );
93 void slotFinished( int, QProcess::ExitStatus );
94 void slotErrorMessages();
95 void slotStdoutMessages();
97 private:
98 bool start();
100 QProcess mProcess;
101 QString mApplication;
102 QStringList mArguments;
103 CrashPolicy mPolicy;
104 bool mFailedToStart;
105 int mCrashCount;
108 #endif