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
|
2010-07-16 06:08:12 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
public:
|
2012-01-22 12:35:07 +00:00
|
|
|
SystemcallPrivate(std::string const & infile, std::string const & outfile,
|
|
|
|
std::string const & errfile);
|
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);
|
2013-07-16 04:39:28 +00:00
|
|
|
void startProcess(QString const & cmd, std::string const & path, bool detach);
|
2009-12-04 09:51:13 +00:00
|
|
|
|
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: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
|
|
|
|
2010-07-16 06:08:12 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void stdOut();
|
|
|
|
void stdErr();
|
|
|
|
void processError(QProcess::ProcessError);
|
|
|
|
void processStarted();
|
|
|
|
void processFinished(int, QProcess::ExitStatus status);
|
|
|
|
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
private:
|
|
|
|
/// Pointer to the process to monitor.
|
2010-07-16 06:08:12 +00:00
|
|
|
QProcess * process_;
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Index to the standard output buffer.
|
2010-07-16 08:09:38 +00:00
|
|
|
size_t out_index_;
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Index to the standard error buffer.
|
2010-07-16 08:09:38 +00:00
|
|
|
size_t err_index_;
|
2009-12-04 10:11:06 +00:00
|
|
|
///
|
2012-01-22 12:35:07 +00:00
|
|
|
std::string in_file_;
|
|
|
|
///
|
2010-07-16 08:09:38 +00:00
|
|
|
std::string out_file_;
|
2011-10-31 02:02:27 +00:00
|
|
|
///
|
|
|
|
std::string err_file_;
|
2010-07-16 06:08:12 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Size of buffers.
|
2010-07-16 14:30:46 +00:00
|
|
|
static size_t const buffer_size_ = 200;
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Standard output buffer.
|
2010-07-16 14:30:46 +00:00
|
|
|
char out_data_[buffer_size_];
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Standard error buffer.
|
2010-07-16 14:30:46 +00:00
|
|
|
char err_data_[buffer_size_];
|
2010-07-16 08:09:38 +00:00
|
|
|
|
|
|
|
QString cmd_;
|
|
|
|
bool process_events_;
|
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();
|
2010-07-16 08:09:38 +00:00
|
|
|
void killProcess();
|
2009-12-20 14:26:55 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // SYSTEMCALLPRIVATE_H
|