]> git.lyx.org Git - lyx.git/blob - src/support/forkedcallqueue.h
* src/text2.C: deleteEmptyParagraphMechanism(): fix a crash in
[lyx.git] / src / support / forkedcallqueue.h
1 // -*- C++ -*-
2 /**
3  * \file forkedcallqueue.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alfredo Braunstein (based on an idea from Angus Leeming)
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * This class implements a queue of forked processes. In order not to
12  * hose the system with multiple processes running simultaneously, you can
13  * request the addition of your process to this queue and it will be
14  * executed when its turn comes.
15  *
16  */
17
18 #ifndef FORKEDCALLQUEUE_H
19 #define FORKEDCALLQUEUE_H
20
21 #include "support/forkedcall.h"
22
23 #include <queue>
24 #include <utility>
25
26
27 namespace lyx {
28 namespace support {
29
30 class ForkedCallQueue {
31 public:
32         /// A process in the queue
33         typedef std::pair<std::string, Forkedcall::SignalTypePtr> Process;
34         /** Add a process to the queue. Processes are forked sequentially
35          *  only one is running at a time.
36          *  Connect to the returned signal and you'll be informed when
37          *  the process has ended.
38          */
39         Forkedcall::SignalTypePtr add(std::string const & process);
40         /// Query whether the queue is running a forked process now.
41         bool running() const;
42         /// Get the and only instance of the class
43         static ForkedCallQueue & get();
44
45 private:
46
47         /** this class is a singleton class... use
48          *  ForkedCallQueue::get() instead
49          */
50         ForkedCallQueue();
51         /// in-progress queue
52         std::queue<Process> callQueue_;
53         ///
54         bool running_;
55         ///
56         void callNext();
57         ///
58         void startCaller();
59         ///
60         void stopCaller();
61         ///
62         void callback(pid_t, int);
63 };
64
65 } // namespace support
66 } // namespace lyx
67
68 #endif // FORKEDCALLQUEUE_H