]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
The graphics inset now has:
[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
22 #ifdef __GNUG__
23 #pragma interface
24 #endif
25
26 class Forkedcall;
27 class Timeout;
28
29 class ForkedcallsController : public SigC::Object {
30 public:
31         /// Get hold of the only controller that can exist inside the process.
32         static ForkedcallsController & get();
33
34         /// Add a new child process to the list of controlled processes.
35         void addCall(Forkedcall const & newcall);
36
37         /** This method is connected to the timer. Every XX ms it is called
38          *  so that we can check on the status of the children. Those that
39          *  are found to have finished are removed from the list and their
40          *  callback function is passed the final return state.
41          */
42         void timer();
43
44         /// Return a vector of the pids of all the controlled processes.
45         std::vector<pid_t> const getPIDs() const;
46
47         /// Get the command string of the process.
48         string const getCommand(pid_t) const;
49
50         /** Kill this process prematurely and remove it from the list.
51          *  The process is killed within tolerance secs.
52          *  See forkedcall.[Ch] for details.
53          */
54         void kill(pid_t, int tolerance = 5);
55
56         /// Signal emitted when the list of current child processes changes.
57         SigC::Signal0<void> childrenChanged;
58         
59 private:
60         /// Can't create multiple instances of ForkedcallsController.
61         ForkedcallsController();
62         ///
63         ForkedcallsController(ForkedcallsController const &);
64         ///
65         ~ForkedcallsController();
66
67         /// The child processes
68         typedef std::list<Forkedcall *> ListType;
69         ///
70         ListType forkedCalls;
71
72         /** The timer. Enables us to check the status of the children
73          *  every XX ms and to invoke a callback on completion.
74          */
75         Timeout * timeout_;
76 };
77
78 #endif // FORKEDCONTR_H