]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
tex2lyx: roundtrip support for the suppress_date option, for the remaining part I...
[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
34 public:
35         SystemcallPrivate(std::string const & outfile);
36         ~SystemcallPrivate();
37
38         enum State {
39                 Starting,
40                 Running,
41                 Finished,
42                 Error
43         };
44         State state;
45
46         bool waitWhile(State, bool processEvents, int timeout = -1);
47         void startProcess(QString const & cmd, std::string const & path);
48         
49         int exitCode();
50
51         QString errorMessage() const;
52         QString exitStatusMessage() const;
53
54         QProcess* releaseProcess();
55         
56         static void killProcess(QProcess * p);
57
58
59 public Q_SLOTS:
60         void stdOut();
61         void stdErr();
62         void processError(QProcess::ProcessError);
63         void processStarted();
64         void processFinished(int, QProcess::ExitStatus status);
65
66
67 private:
68         /// Pointer to the process to monitor.
69         QProcess * process_;
70
71         /// Index to the standard output buffer.
72         size_t out_index_;
73         /// Index to the standard error buffer.
74         size_t err_index_;
75         ///
76         std::string out_file_;
77
78         /// Size of buffers.
79         static size_t const buffer_size_ = 200;
80         /// Standard output buffer.
81         char out_data_[buffer_size_];
82         /// Standard error buffer.
83         char err_data_[buffer_size_];
84
85         QString cmd_;
86         bool process_events_;
87
88         void waitAndProcessEvents();
89         void processEvents();
90         void killProcess();     
91
92 };
93
94 } // namespace support
95 } // namespace lyx
96
97 #endif // SYSTEMCALLPRIVATE_H