]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
Revert the asynchronous child process code to that of LyX 1.3.6.
[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 #include <sys/types.h> // needed for pid_t
22
23 #include <list>
24 #include <string>
25 #include <vector>
26
27 namespace lyx {
28 namespace support {
29
30 class ForkedProcess;
31
32 class ForkedcallsController {
33 public:
34         /// Get hold of the only controller that can exist inside the process.
35         static ForkedcallsController & get();
36
37         /// Add a new child process to the list of controlled processes.
38         void addCall(ForkedProcess const &);
39
40         /** Those child processes that are found to have finished are removed
41          *  from the list and their callback function is passed the final
42          *  return state.
43          */
44         void handleCompletedProcesses();
45
46         /** Kill this process prematurely and remove it from the list.
47          *  The process is killed within tolerance secs.
48          *  See forkedcall.[Ch] for details.
49          */
50         void kill(pid_t, int tolerance = 5);
51
52 private:
53         ForkedcallsController();
54         ForkedcallsController(ForkedcallsController const &);
55         ~ForkedcallsController();
56
57         typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
58         typedef std::list<ForkedProcessPtr> ListType;
59         typedef ListType::iterator iterator;
60
61         iterator find_pid(pid_t);
62
63         /// The child processes
64         ListType forkedCalls;
65 };
66
67
68 #if defined(_WIN32)
69 // a wrapper for GetLastError() and FormatMessage().
70 std::string const getChildErrorMessage();
71 #endif
72
73 } // namespace support
74 } // namespace lyx
75
76 #endif // FORKEDCONTR_H