NepomukDaemons
processcontrol.h
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> * 00003 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Library General Public License as * 00007 * published by the Free Software Foundation; either version 2 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU Library General Public * 00016 * License along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00019 ***************************************************************************/ 00020 00021 #ifndef _PROCESSCONTROL_H 00022 #define _PROCESSCONTROL_H 00023 00024 #include <QtCore/QObject> 00025 #include <QtCore/QProcess> 00026 00027 00032 class ProcessControl : public QObject 00033 { 00034 Q_OBJECT 00035 00036 public: 00044 enum CrashPolicy 00045 { 00046 StopOnCrash, 00047 RestartOnCrash 00048 }; 00049 00055 ProcessControl( QObject *parent = 0 ); 00056 00060 ~ProcessControl(); 00061 00065 bool start( const QString &application, const QStringList &arguments = QStringList(), 00066 CrashPolicy policy = RestartOnCrash, int maxCrashes = 5 ); 00067 00071 void stop(); 00072 00076 void setCrashPolicy( CrashPolicy policy ); 00077 00078 bool isRunning() const; 00079 00080 Q_SIGNALS: 00087 void processErrorMessages( const QString &errorMsg ); 00088 00089 void finished( bool clean ); 00090 00091 private Q_SLOTS: 00092 void slotError( QProcess::ProcessError ); 00093 void slotFinished( int, QProcess::ExitStatus ); 00094 void slotErrorMessages(); 00095 void slotStdoutMessages(); 00096 00097 private: 00098 bool start(); 00099 00100 QProcess mProcess; 00101 QString mApplication; 00102 QStringList mArguments; 00103 CrashPolicy mPolicy; 00104 bool mFailedToStart; 00105 int mCrashCount; 00106 }; 00107 00108 #endif