]> git.lyx.org Git - lyx.git/blob - src/support/Systemcall.h
Allow immediate output of spawned processes for all platforms.
[lyx.git] / src / support / Systemcall.h
1 // -*- C++ -*-
2 /**
3  * \file Systemcall.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  *
9  * Interface cleaned up by
10  * \author Angus Leeming
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef SYSTEMCALL_H
16 #define SYSTEMCALL_H
17
18 #include <string>
19 #include <QObject>
20
21 class QProcess;
22
23 namespace lyx {
24 namespace support {
25
26 /**
27  * An instance of Class Systemcall represents a single child process.
28  *
29  * Class Systemcall uses system() to launch the child process.
30  * The user can choose to wait or not wait for the process to complete, but no
31  * callback is invoked upon completion of the child.
32  *
33  * The child process is not killed when the Systemcall instance goes out of
34  * scope.
35  */
36 class Systemcall {
37 public:
38         /// whether to wait for completion
39         enum Starttype {
40                 Wait, //< wait for completion before returning from startscript()
41                 DontWait //< don't wait for completion
42         };
43
44         /** Start child process.
45          *  The string "what" contains a commandline with arguments separated
46          *  by spaces.
47          */
48         int startscript(Starttype how, std::string const & what);
49 };
50
51
52 /**
53  * Outputs to the console terminal the line buffered standard output and
54  * error of a spawned process when there is a controlling terminal and 
55  * stdout/stderr have not been redirected.
56  */
57 class ConOut : public QObject
58 {
59         Q_OBJECT
60 public:
61         ConOut(QProcess * proc);
62         ~ConOut();
63
64         /// Should the standard output be displayed?
65         void showout() { showout_ = true; }
66
67         /// Should the standard error be displayed?
68         void showerr() { showerr_ = true; }
69
70 private:
71         /// Pointer to the process to monitor.
72         QProcess * proc_;
73         /// Index to the standard output buffer.
74         size_t outindex_;
75         /// Index to the standard error buffer.
76         size_t errindex_;
77         /// Size of buffers.
78         static size_t const bufsize_ = 200;
79         /// Standard output buffer.
80         char outdata_[bufsize_];
81         /// Standard error buffer.
82         char errdata_[bufsize_];
83         /// 
84         bool showout_;
85         /// 
86         bool showerr_;
87
88 public Q_SLOTS:
89         void stdOut();
90         void stdErr();
91 };
92
93 } // namespace support
94 } // namespace lyx
95
96 #endif // SYSTEMCALL_H