]> git.lyx.org Git - lyx.git/blob - src/support/forkedcontr.h
Remove executable status info from typeIndicator.
[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 <csignal>
22 //#include <sys/types.h> // needed for pid_t
23 #include <list>
24 #include <vector>
25
26 namespace lyx {
27 namespace support {
28
29 class ForkedProcess;
30
31 class ForkedcallsController {
32 public:
33         /// Get hold of the only controller that can exist inside the process.
34         static ForkedcallsController & get();
35
36         /// Are there any completed child processes to be cleaned-up after?
37         bool processesCompleted() const { return current_child != -1; }
38
39         /** Those child processes that are found to have finished are removed
40          *  from the list and their callback function is passed the final
41          *  return state.
42          */
43         void handleCompletedProcesses();
44
45         /// Add a new child process to the list of controlled processes.
46         void addCall(ForkedProcess const &);
47
48         /** Kill this process prematurely and remove it from the list.
49          *  The process is killed within tolerance secs.
50          *  See forkedcall.[Ch] for details.
51          */
52         void kill(pid_t, int tolerance = 5);
53
54         struct Data {
55                 Data() : pid(0), status(0) {}
56                 pid_t pid;
57                 int status;
58         };
59
60         /** These data are used by the SIGCHLD handler to populate a list
61          *  of child processes that have completed and been reaped.
62          *  The associated signals are then emitted within the main LyX
63          *  event loop.
64          */
65         std::vector<Data> reaped_children;
66         sig_atomic_t current_child;
67
68 private:
69         ForkedcallsController();
70         ForkedcallsController(ForkedcallsController const &);
71         ~ForkedcallsController();
72
73         typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
74         typedef std::list<ForkedProcessPtr> ListType;
75         typedef ListType::iterator iterator;
76
77         iterator find_pid(pid_t);
78
79         /// The child processes
80         ListType forkedCalls;
81
82         /// Used to block SIGCHLD signals.
83         sigset_t newMask, oldMask;
84 };
85
86 } // namespace support
87 } // namespace lyx
88
89 #endif // FORKEDCONTR_H