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