2009-05-16 15:55:08 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file SystemcallPrivate.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Enrico Forestieri
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SYSTEMCALLPRIVATE_H
|
|
|
|
#define SYSTEMCALLPRIVATE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2009-12-04 09:51:13 +00:00
|
|
|
#include <QProcess>
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2010-01-24 13:57:45 +00:00
|
|
|
#include <string>
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
class Systemcall;
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/**
|
|
|
|
* Outputs to the console terminal the line buffered standard output and
|
|
|
|
* error of a spawned process when there is a controlling terminal and
|
|
|
|
* stdout/stderr have not been redirected.
|
|
|
|
*/
|
2009-12-04 09:51:13 +00:00
|
|
|
class SystemcallPrivate : public QObject
|
2009-05-16 15:55:08 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2010-01-24 13:57:45 +00:00
|
|
|
SystemcallPrivate(std::string const & outfile);
|
2009-12-04 09:51:13 +00:00
|
|
|
~SystemcallPrivate();
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
enum State {
|
|
|
|
Starting,
|
|
|
|
Running,
|
|
|
|
Finished,
|
|
|
|
Error
|
|
|
|
};
|
|
|
|
State state;
|
|
|
|
|
|
|
|
bool waitWhile(State, bool processEvents, int timeout = -1);
|
|
|
|
void startProcess(const QString& cmd);
|
|
|
|
|
2009-12-04 10:11:06 +00:00
|
|
|
int exitCode();
|
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
QString errorMessage() const;
|
|
|
|
QString exitStatusMessage() const;
|
|
|
|
|
2009-12-04 10:11:06 +00:00
|
|
|
void flush();
|
2009-12-04 10:35:32 +00:00
|
|
|
|
|
|
|
QProcess* releaseProcess();
|
|
|
|
|
2009-12-04 10:11:06 +00:00
|
|
|
static void killProcess(QProcess * p);
|
2009-12-04 09:51:13 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
private:
|
|
|
|
/// Pointer to the process to monitor.
|
|
|
|
QProcess * proc_;
|
|
|
|
/// Index to the standard output buffer.
|
|
|
|
size_t outindex_;
|
|
|
|
/// Index to the standard error buffer.
|
|
|
|
size_t errindex_;
|
2009-12-04 10:11:06 +00:00
|
|
|
///
|
|
|
|
std::string outfile;
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Size of buffers.
|
|
|
|
static size_t const bufsize_ = 200;
|
|
|
|
/// Standard output buffer.
|
|
|
|
char outdata_[bufsize_];
|
|
|
|
/// Standard error buffer.
|
|
|
|
char errdata_[bufsize_];
|
|
|
|
///
|
2010-07-16 05:55:31 +00:00
|
|
|
bool terminalErrExists_;
|
2009-05-16 15:55:08 +00:00
|
|
|
///
|
2010-07-16 05:55:31 +00:00
|
|
|
bool terminalOutExists_;
|
2009-12-04 11:08:24 +00:00
|
|
|
bool process_events;
|
2009-12-20 14:26:55 +00:00
|
|
|
QString cmd_;
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
void waitAndProcessEvents();
|
2009-12-04 11:08:24 +00:00
|
|
|
void processEvents();
|
2009-12-04 09:51:13 +00:00
|
|
|
|
2009-12-04 10:35:32 +00:00
|
|
|
void killProcess();
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void stdOut();
|
|
|
|
void stdErr();
|
2009-12-04 09:51:13 +00:00
|
|
|
void processError(QProcess::ProcessError);
|
|
|
|
void processStarted();
|
|
|
|
void processFinished(int, QProcess::ExitStatus status);
|
|
|
|
|
2009-12-20 14:26:55 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // SYSTEMCALLPRIVATE_H
|