]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
a7c25639006c4a5317c8d1a4a9b17e4d9b4c5f54
[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 showout() { showout_ = true; }
38
39         /// Should the standard error be displayed?
40         void showerr() { showerr_ = true; }
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         void killProcess();
60         static void killProcess(QProcess * p);
61
62 private:
63         /// Pointer to the process to monitor.
64         QProcess * proc_;
65         /// Index to the standard output buffer.
66         size_t outindex_;
67         /// Index to the standard error buffer.
68         size_t errindex_;
69         ///
70         std::string outfile;
71         /// Size of buffers.
72         static size_t const bufsize_ = 200;
73         /// Standard output buffer.
74         char outdata_[bufsize_];
75         /// Standard error buffer.
76         char errdata_[bufsize_];
77         /// 
78         bool showout_;
79         /// 
80         bool showerr_;
81
82         void waitAndProcessEvents();
83
84 public Q_SLOTS:
85         void stdOut();
86         void stdErr();
87         void processError(QProcess::ProcessError);
88         void processStarted();
89         void processFinished(int, QProcess::ExitStatus status);
90
91 };
92
93 } // namespace support
94 } // namespace lyx
95
96 #endif // SYSTEMCALLPRIVATE_H