]> git.lyx.org Git - lyx.git/blob - src/support/SystemcallPrivate.h
Update sk.po
[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 /**
24  * Outputs to the console terminal the line buffered standard output and
25  * error of a spawned process when there is a controlling terminal and
26  * stdout/stderr have not been redirected.
27  */
28 class SystemcallPrivate : public QObject
29 {
30         Q_OBJECT
31
32 public:
33         SystemcallPrivate(std::string const & infile, std::string const & outfile,
34                           std::string const & errfile);
35         ~SystemcallPrivate();
36
37         enum State {
38                 Starting,
39                 Running,
40                 Finished,
41                 Error,
42                 Killed
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                           std::string const & lpath, 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         // when true, kill any running script ASAP
60         static bool kill_script;
61
62
63 public Q_SLOTS:
64         void stdOut();
65         void stdErr();
66         void processError(QProcess::ProcessError);
67         void processStarted();
68         void processFinished(int, QProcess::ExitStatus status);
69
70
71 private:
72         /// Pointer to the process to monitor.
73         QProcess * process_;
74
75         /// Index to the standard output buffer.
76         size_t out_index_;
77         /// Index to the standard error buffer.
78         size_t err_index_;
79         ///
80         std::string in_file_;
81         ///
82         std::string out_file_;
83         ///
84         std::string err_file_;
85
86         /// Size of buffers.
87         static size_t const buffer_size_ = 200;
88         /// Standard output buffer.
89         char out_data_[buffer_size_];
90         /// Standard error buffer.
91         char err_data_[buffer_size_];
92
93         QString cmd_;
94         bool process_events_;
95
96         void waitAndProcessEvents();
97         void processEvents();
98         void killProcess();
99
100         /// returns false if we killed the process
101         /// actually returns Systemcall::ReturnValue
102         bool waitAndCheck();
103 };
104
105 } // namespace support
106 } // namespace lyx
107
108 #endif // SYSTEMCALLPRIVATE_H