]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
final compilation: wheel was already invented :(
[lyx.git] / src / support / forkedcontr.h
1 // -*- C++ -*-
2 /**
3  * \file forkedcontr.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 Nielsen
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * A class for the control of child processes launched using
13  * fork() and execvp().
14  */
15
16 #ifndef FORKEDCONTR_H
17 #define FORKEDCONTR_H
18
19 #include <boost/shared_ptr.hpp>
20
21 #ifdef HAVE_SYS_TYPES_H
22 # include <sys/types.h>
23 #endif
24
25 #include <list>
26 #include <string>
27 #include <vector>
28
29
30 namespace lyx {
31 namespace support {
32
33 class ForkedProcess;
34
35 class ForkedcallsController {
36 public:
37         /// Get hold of the only controller that can exist inside the process.
38         static ForkedcallsController & get();
39
40         /// Add a new child process to the list of controlled processes.
41         void addCall(ForkedProcess const &);
42
43         /** Those child processes that are found to have finished are removed
44          *  from the list and their callback function is passed the final
45          *  return state.
46          */
47         void handleCompletedProcesses();
48
49         /** Kill this process prematurely and remove it from the list.
50          *  The process is killed within tolerance secs.
51          *  See forkedcall.[Ch] for details.
52          */
53         void kill(pid_t, int tolerance = 5);
54
55 private:
56         ForkedcallsController();
57         ForkedcallsController(ForkedcallsController const &);
58         ~ForkedcallsController();
59
60         typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
61         typedef std::list<ForkedProcessPtr> ListType;
62         typedef ListType::iterator iterator;
63
64         iterator find_pid(pid_t);
65
66         /// The child processes
67         ListType forkedCalls;
68 };
69
70
71 #if defined(_WIN32)
72 // a wrapper for GetLastError() and FormatMessage().
73 std::string const getChildErrorMessage();
74 #endif
75
76 } // namespace support
77 } // namespace lyx
78
79 #endif // FORKEDCONTR_H