]> git.lyx.org Git - lyx.git/blob - src/support/ForkedCallQueue.cpp
remove reference to LaTeXStream
[lyx.git] / src / support / ForkedCallQueue.cpp
1 /**
2  * \file ForkedCallQueue.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein (based on an idea from Angus Leeming)
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/ForkedCallQueue.h"
14
15 #include "debug.h"
16
17 #include <boost/bind.hpp>
18
19
20 using std::string;
21 using std::endl;
22
23
24 namespace lyx {
25 namespace support {
26
27 ForkedCallQueue & ForkedCallQueue::get()
28 {
29         static ForkedCallQueue singleton;
30         return singleton;
31 }
32
33
34 Forkedcall::SignalTypePtr ForkedCallQueue::add(string const & process)
35 {
36         Forkedcall::SignalTypePtr ptr;
37         ptr.reset(new Forkedcall::SignalType);
38         callQueue_.push(Process(process, ptr));
39         if (!running_) {
40                 startCaller();
41         }
42         return ptr;
43 }
44
45
46 void ForkedCallQueue::callNext()
47 {
48         if (callQueue_.empty())
49                 return;
50         Process pro = callQueue_.front();
51         callQueue_.pop();
52         // Bind our chain caller
53         pro.second->connect(boost::bind(&ForkedCallQueue::callback,
54                                          this, _1, _2));
55         Forkedcall call;
56         // If we fail to fork the process, then emit the signal
57         // to tell the outside world that it failed.
58         if (call.startscript(pro.first, pro.second) > 0) {
59                 pro.second->operator()(0,1);
60         }
61 }
62
63
64 void ForkedCallQueue::callback(pid_t, int)
65 {
66         if (callQueue_.empty()) {
67                 stopCaller();
68         } else {
69                 callNext();
70         }
71 }
72
73 ForkedCallQueue::ForkedCallQueue() : running_(false)
74 {}
75
76
77 void ForkedCallQueue::startCaller()
78 {
79         LYXERR(Debug::GRAPHICS) << "ForkedCallQueue: waking up" << endl;
80         running_ = true ;
81         callNext();
82 }
83
84
85 void ForkedCallQueue::stopCaller()
86 {
87         running_ = false ;
88         LYXERR(Debug::GRAPHICS) << "ForkedCallQueue: I'm going to sleep"
89                                 << endl;
90 }
91
92
93 bool ForkedCallQueue::running() const
94 {
95         return running_ ;
96 }
97
98 } // namespace support
99 } // namespace lyx