]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
4fee2c698bce075604c8d9ee770475245ca66e85
[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
17 #include <QProcess>
18
19 namespace lyx {
20 namespace support {
21
22 class Systemcall;
23
24 /**
25  * Outputs to the console terminal the line buffered standard output and
26  * error of a spawned process when there is a controlling terminal and 
27  * stdout/stderr have not been redirected.
28  */
29 class SystemcallPrivate : public QObject
30 {
31         Q_OBJECT
32 public:
33         SystemcallPrivate(const std::string& outfile);
34         ~SystemcallPrivate();
35
36         /// Should the standard output be displayed?
37         void setShowOut(bool val) { showout_ = val; }
38
39         /// Should the standard error be displayed?
40         void setShowErr(bool val) { showerr_ = val; }
41
42         enum State {
43                 Starting,
44                 Running,
45                 Finished,
46                 Error
47         };
48         State state;
49
50         bool waitWhile(State, bool processEvents, int timeout = -1);
51         void startProcess(const QString& cmd);
52         
53         int exitCode();
54
55         QString errorMessage() const;
56         QString exitStatusMessage() const;
57
58         void flush();
59
60         QProcess* releaseProcess();
61         
62         static void killProcess(QProcess * p);
63
64 private:
65         /// Pointer to the process to monitor.
66         QProcess * proc_;
67         /// Index to the standard output buffer.
68         size_t outindex_;
69         /// Index to the standard error buffer.
70         size_t errindex_;
71         ///
72         std::string outfile;
73         /// Size of buffers.
74         static size_t const bufsize_ = 200;
75         /// Standard output buffer.
76         char outdata_[bufsize_];
77         /// Standard error buffer.
78         char errdata_[bufsize_];
79         /// 
80         bool showout_;
81         /// 
82         bool showerr_;
83         bool process_events;
84         QString cmd_;
85
86         void waitAndProcessEvents();
87         void processEvents();
88
89         void killProcess();
90
91 public Q_SLOTS:
92         void stdOut();
93         void stdErr();
94         void processError(QProcess::ProcessError);
95         void processStarted();
96         void processFinished(int, QProcess::ExitStatus status);
97
98 Q_SIGNALS:
99
100 };
101
102 } // namespace support
103 } // namespace lyx
104
105 #endif // SYSTEMCALLPRIVATE_H