]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
The std::string mammoth path.
[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/signals/signal0.hpp>
20 #include <boost/signals/trackable.hpp>
21
22 #include <sys/types.h> // needed for pid_t
23
24 #include <list>
25 #include <vector>
26
27 class Timeout;
28
29 namespace lyx {
30 namespace support {
31
32 class ForkedProcess;
33
34 class ForkedcallsController : public boost::signals::trackable {
35 public:
36         /// We need this to avoid warnings.
37         ForkedcallsController();
38         /** This d-tor should really be private, but making it public
39          *   allows egcs 1.1 to compile the class.
40          */
41         ~ForkedcallsController();
42
43         /// Get hold of the only controller that can exist inside the process.
44         static ForkedcallsController & get();
45
46         /// Add a new child process to the list of controlled processes.
47         void addCall(ForkedProcess const &);
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         /// Return a vector of the pids of all the controlled processes.
57         std::vector<pid_t> const getPIDs() const;
58
59         /// Get the command string of the process.
60         std::string const getCommand(pid_t) const;
61
62         /** Kill this process prematurely and remove it from the list.
63          *  The process is killed within tolerance secs.
64          *  See forkedcall.[Ch] for details.
65          */
66         void kill(pid_t, int tolerance = 5);
67
68         /// Signal emitted when the list of current child processes changes.
69         boost::signal0<void> childrenChanged;
70
71 private:
72         ///
73         ForkedcallsController(ForkedcallsController const &);
74
75         /// The child processes
76         typedef std::list<ForkedProcess *> ListType;
77         ///
78         ListType forkedCalls;
79
80         /** The timer. Enables us to check the status of the children
81          *  every XX ms and to invoke a callback on completion.
82          */
83         Timeout * timeout_;
84 };
85
86 } // namespace support
87 } // namespace lyx
88
89 #endif // FORKEDCONTR_H