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