]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
Store the forked calls in boost::shared_ptr rather than a raw pointer.
[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 #include <sys/types.h> // needed for pid_t
21 #include <list>
22
23 class Timeout;
24
25 namespace lyx {
26 namespace support {
27
28 class ForkedProcess;
29
30 class ForkedcallsController {
31 public:
32         /// Get hold of the only controller that can exist inside the process.
33         static ForkedcallsController & get();
34
35         /// Add a new child process to the list of controlled processes.
36         void addCall(ForkedProcess const &);
37
38         /** Kill this process prematurely and remove it from the list.
39          *  The process is killed within tolerance secs.
40          *  See forkedcall.[Ch] for details.
41          */
42         void kill(pid_t, int tolerance = 5);
43
44 private:
45         ForkedcallsController();
46         ForkedcallsController(ForkedcallsController const &);
47         ~ForkedcallsController();
48
49         /** This method is connected to the timer. Every XX ms it is called
50          *  so that we can check on the status of the children. Those that
51          *  are found to have finished are removed from the list and their
52          *  callback function is passed the final return state.
53          */
54         void timer();
55
56         /// The child processes
57         typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
58         typedef std::list<ForkedProcessPtr> ListType;
59         ///
60         ListType forkedCalls;
61
62         /** The timer. Enables us to check the status of the children
63          *  every XX ms and to invoke a callback on completion.
64          */
65         Timeout * timeout_;
66 };
67
68 } // namespace support
69 } // namespace lyx
70
71 #endif // FORKEDCONTR_H