]> git.lyx.org Git - lyx.git/blob - src/support/forkedcallqueue.h
"Inter-word Space"
[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 "forkedcall.h"
22
23 #include <queue>
24 #include <utility>
25 #include "LString.h"
26
27 class ForkedCallQueue {
28 public:
29         /// A process in the queue
30         typedef std::pair<string, Forkedcall::SignalTypePtr> Process;
31         /** Add a process to the queue. Processes are forked sequentially
32          *  only one is running at a time.
33          *  Connect to the returned signal and you'll be informed when
34          *  the process has ended.
35          */
36         Forkedcall::SignalTypePtr add(string const & process);
37         /// Query whether the queue is running a forked process now.
38         bool running() const;
39         /// Get the and only instance of the class
40         static ForkedCallQueue & get();
41
42 private:
43
44         /** this class is a singleton class... use 
45          *  ForkedCallQueue::get() instead
46          */
47         ForkedCallQueue();
48         /// in-progress queue 
49         std::queue<Process> callQueue_;
50         ///
51         bool running_;
52         ///
53         void callNext();
54         ///
55         void startCaller();
56         ///
57         void stopCaller();
58         ///
59         void callback(pid_t, int);
60 };
61
62 #endif // FORKEDCALLQUEUE_H