]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
Move some code from the process branch into trunk.
[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(QProcess * proc);
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         QString errorMessage() const;
54         QString exitStatusMessage() const;
55
56
57
58 private:
59         /// Pointer to the process to monitor.
60         QProcess * proc_;
61         /// Index to the standard output buffer.
62         size_t outindex_;
63         /// Index to the standard error buffer.
64         size_t errindex_;
65         /// Size of buffers.
66         static size_t const bufsize_ = 200;
67         /// Standard output buffer.
68         char outdata_[bufsize_];
69         /// Standard error buffer.
70         char errdata_[bufsize_];
71         /// 
72         bool showout_;
73         /// 
74         bool showerr_;
75
76         void waitAndProcessEvents();
77
78 public Q_SLOTS:
79         void stdOut();
80         void stdErr();
81         void processError(QProcess::ProcessError);
82         void processStarted();
83         void processFinished(int, QProcess::ExitStatus status);
84
85 };
86
87 } // namespace support
88 } // namespace lyx
89
90 #endif // SYSTEMCALLPRIVATE_H