]> git.lyx.org Git - features.git/blob - src/support/SystemcallPrivate.h
only guard terminal output.
[features.git] / src / support / SystemcallPrivate.h
1 // -*- C++ -*-
2 /**
3  * \file SystemcallPrivate.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Enrico Forestieri
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef SYSTEMCALLPRIVATE_H
13 #define SYSTEMCALLPRIVATE_H
14
15 #include <QObject>
16 #include <QProcess>
17
18 #include <string>
19
20 namespace lyx {
21 namespace support {
22
23 class Systemcall;
24
25 /**
26  * Outputs to the console terminal the line buffered standard output and
27  * error of a spawned process when there is a controlling terminal and 
28  * stdout/stderr have not been redirected.
29  */
30 class SystemcallPrivate : public QObject
31 {
32         Q_OBJECT
33 public:
34         SystemcallPrivate(std::string const & outfile);
35         ~SystemcallPrivate();
36
37         enum State {
38                 Starting,
39                 Running,
40                 Finished,
41                 Error
42         };
43         State state;
44
45         bool waitWhile(State, bool processEvents, int timeout = -1);
46         void startProcess(const QString& cmd);
47         
48         int exitCode();
49
50         QString errorMessage() const;
51         QString exitStatusMessage() const;
52
53         void flush();
54
55         QProcess* releaseProcess();
56         
57         static void killProcess(QProcess * p);
58
59 private:
60         /// Pointer to the process to monitor.
61         QProcess * proc_;
62         /// Index to the standard output buffer.
63         size_t outindex_;
64         /// Index to the standard error buffer.
65         size_t errindex_;
66         ///
67         std::string outfile;
68         /// Size of buffers.
69         static size_t const bufsize_ = 200;
70         /// Standard output buffer.
71         char outdata_[bufsize_];
72         /// Standard error buffer.
73         char errdata_[bufsize_];
74         /// 
75         bool terminalErrExists_;
76         /// 
77         bool terminalOutExists_;
78         bool process_events;
79         QString cmd_;
80
81         void waitAndProcessEvents();
82         void processEvents();
83
84         void killProcess();
85
86 public Q_SLOTS:
87         void stdOut();
88         void stdErr();
89         void processError(QProcess::ProcessError);
90         void processStarted();
91         void processFinished(int, QProcess::ExitStatus status);
92
93 Q_SIGNALS:
94
95 };
96
97 } // namespace support
98 } // namespace lyx
99
100 #endif // SYSTEMCALLPRIVATE_H