$ cat guitone/src/monotone/Monotone.h
/***************************************************************************
* Copyright (C) 2006 by Thomas Keller *
* me@thomaskeller.biz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MONOTONE_H
#define MONOTONE_H
#include "../model/AutomateCommand.h"
#include <QProcess>
#include <QDir>
#include <QMutex>
class Monotone : public QObject
{
Q_OBJECT
public:
static Monotone* singleton(QObject * parent = 0);
static bool runCommand(const QString &, const QStringList &, QString &);
static bool checkProgramVersion(const QString &);
static bool checkInterfaceVersion(const QString &);
static const QString RequiredProgramVersion;
static const QString RequiredInterfaceVersion;
static const int StdioBufferSize;
static const int TimeoutWaitForOtherCommand;
void setup(QDir*);
virtual ~Monotone();
QString getWorkspaceDir() const;
bool triggerCommand(AutomateCommand*, const QStringList &);
bool triggerCommand(AutomateCommand*, const QStringList &, const QStringList &);
bool executeCommand(const QStringList &, int &);
bool executeCommand(const QStringList &, const QStringList &, int &);
inline QString getOutput() { return output; }
private:
Monotone(QObject *);
bool newCommandSetup();
void writeStdin(const QStringList &, const QStringList &);
bool readAndParseStdout(int &);
QMutex mutex;
bool timeout;
QString input;
QString output;
QString commandLine;
AutomateCommand* lastCaller;
bool isProcessingData;
bool isCleanExit;
static Monotone* instance;
QProcess * process;
QDir * workDir;
private slots:
void readAndProcessCommand();
void processTerminated(int, QProcess::ExitStatus);
void startupError(QProcess::ProcessError);
void timedOut();
signals:
void commandFinished(AutomateCommand*);
void criticalError(const QString &);
};
#endif