]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
Improve quotation mark opening/closing guess
[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,
49                           std::string const & lpath, bool detach);
50         
51         int exitCode();
52
53         QString errorMessage() const;
54         QString exitStatusMessage() const;
55
56         QProcess* releaseProcess();
57         
58         static void killProcess(QProcess * p);
59
60
61 public Q_SLOTS:
62         void stdOut();
63         void stdErr();
64         void processError(QProcess::ProcessError);
65         void processStarted();
66         void processFinished(int, QProcess::ExitStatus status);
67
68
69 private:
70         /// Pointer to the process to monitor.
71         QProcess * process_;
72
73         /// Index to the standard output buffer.
74         size_t out_index_;
75         /// Index to the standard error buffer.
76         size_t err_index_;
77         ///
78         std::string in_file_;
79         ///
80         std::string out_file_;
81         ///
82         std::string err_file_;
83
84         /// Size of buffers.
85         static size_t const buffer_size_ = 200;
86         /// Standard output buffer.
87         char out_data_[buffer_size_];
88         /// Standard error buffer.
89         char err_data_[buffer_size_];
90
91         QString cmd_;
92         bool process_events_;
93
94         void waitAndProcessEvents();
95         void processEvents();
96         void killProcess();     
97
98 };
99
100 } // namespace support
101 } // namespace lyx
102
103 #endif // SYSTEMCALLPRIVATE_H