]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
Fix compilation with CMake on linux. (Am I the only one having this problem ?).
[lyx.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         /// Should the standard output be displayed?
38         void setShowOut(bool val) { showout_ = val; }
39
40         /// Should the standard error be displayed?
41         void setShowErr(bool val) { showerr_ = val; }
42
43         enum State {
44                 Starting,
45                 Running,
46                 Finished,
47                 Error
48         };
49         State state;
50
51         bool waitWhile(State, bool processEvents, int timeout = -1);
52         void startProcess(const QString& cmd);
53         
54         int exitCode();
55
56         QString errorMessage() const;
57         QString exitStatusMessage() const;
58
59         void flush();
60
61         QProcess* releaseProcess();
62         
63         static void killProcess(QProcess * p);
64
65 private:
66         /// Pointer to the process to monitor.
67         QProcess * proc_;
68         /// Index to the standard output buffer.
69         size_t outindex_;
70         /// Index to the standard error buffer.
71         size_t errindex_;
72         ///
73         std::string outfile;
74         /// Size of buffers.
75         static size_t const bufsize_ = 200;
76         /// Standard output buffer.
77         char outdata_[bufsize_];
78         /// Standard error buffer.
79         char errdata_[bufsize_];
80         /// 
81         bool showout_;
82         /// 
83         bool showerr_;
84         bool process_events;
85         QString cmd_;
86
87         void waitAndProcessEvents();
88         void processEvents();
89
90         void killProcess();
91
92 public Q_SLOTS:
93         void stdOut();
94         void stdErr();
95         void processError(QProcess::ProcessError);
96         void processStarted();
97         void processFinished(int, QProcess::ExitStatus status);
98
99 Q_SIGNALS:
100
101 };
102
103 } // namespace support
104 } // namespace lyx
105
106 #endif // SYSTEMCALLPRIVATE_H