]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
Add #include <sys/types.h> // needed for pid_t
[lyx.git] / src / support / forkedcontr.h
1 // -*- C++ -*-
2 /**
3  * \file forkedcontr.h
4  * Copyright 2001 The LyX Team
5  * Read COPYING
6  *
7  * \author Asger Alstrup Nielsen
8  * \author Angus Leeming
9  *
10  * A class for the control of child processes launched using
11  * fork() and execvp().
12  */
13
14 #ifndef FORKEDCONTR_H
15 #define FORKEDCONTR_H
16
17 #include <list>
18 #include <vector>
19 #include "LString.h"
20 #include <sigc++/signal_system.h>
21 #include <sys/types.h> // needed for pid_t
22
23 #ifdef __GNUG__
24 #pragma interface
25 #endif
26
27 class Forkedcall;
28 class Timeout;
29
30 class ForkedcallsController : public SigC::Object {
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(Forkedcall const & newcall);
37
38         /** This method is connected to the timer. Every XX ms it is called
39          *  so that we can check on the status of the children. Those that
40          *  are found to have finished are removed from the list and their
41          *  callback function is passed the final return state.
42          */
43         void timer();
44
45         /// Return a vector of the pids of all the controlled processes.
46         std::vector<pid_t> const getPIDs() const;
47
48         /// Get the command string of the process.
49         string const getCommand(pid_t) const;
50
51         /** Kill this process prematurely and remove it from the list.
52          *  The process is killed within tolerance secs.
53          *  See forkedcall.[Ch] for details.
54          */
55         void kill(pid_t, int tolerance = 5);
56
57         /// Signal emitted when the list of current child processes changes.
58         SigC::Signal0<void> childrenChanged;
59         
60 private:
61         /// Can't create multiple instances of ForkedcallsController.
62         ForkedcallsController();
63         ///
64         ForkedcallsController(ForkedcallsController const &);
65         ///
66         ~ForkedcallsController();
67
68         /// The child processes
69         typedef std::list<Forkedcall *> ListType;
70         ///
71         ListType forkedCalls;
72
73         /** The timer. Enables us to check the status of the children
74          *  every XX ms and to invoke a callback on completion.
75          */
76         Timeout * timeout_;
77 };
78
79 #endif // FORKEDCONTR_H