2003-02-25 18:56:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file forkedcallqueue.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Alfredo Braunstein (based on an idea from Angus Leeming)
|
2003-05-06 20:34:12 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-25 18:56:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-05-06 20:34:12 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
|
#include "support/forkedcallqueue.h"
|
2003-02-25 18:56:09 +00:00
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-02-25 18:56:09 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-02-25 18:56:09 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace support {
|
|
|
|
|
|
2003-02-25 18:56:09 +00:00
|
|
|
|
ForkedCallQueue & ForkedCallQueue::get()
|
|
|
|
|
{
|
|
|
|
|
static ForkedCallQueue singleton;
|
|
|
|
|
return singleton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forkedcall::SignalTypePtr ForkedCallQueue::add(string const & process)
|
|
|
|
|
{
|
|
|
|
|
Forkedcall::SignalTypePtr ptr;
|
|
|
|
|
ptr.reset(new Forkedcall::SignalType);
|
|
|
|
|
callQueue_.push(Process(process, ptr));
|
|
|
|
|
if (!running_) {
|
|
|
|
|
startCaller();
|
|
|
|
|
}
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ForkedCallQueue::callNext()
|
|
|
|
|
{
|
|
|
|
|
if (callQueue_.empty())
|
|
|
|
|
return;
|
|
|
|
|
Process pro = callQueue_.front();
|
|
|
|
|
callQueue_.pop();
|
|
|
|
|
// Bind our chain caller
|
2003-05-06 20:34:12 +00:00
|
|
|
|
pro.second->connect(boost::bind(&ForkedCallQueue::callback,
|
2003-02-25 18:56:09 +00:00
|
|
|
|
this, _1, _2));
|
|
|
|
|
Forkedcall call;
|
|
|
|
|
//<2F>If<49>we<77>fail<69>to<74>fork<72>the<68>process,<2C>then<65>emit<69>the<68>signal
|
|
|
|
|
//<2F>to<74>tell<6C>the<68>outside<64>world<6C>that<61>it<69>failed.
|
|
|
|
|
if (call.startscript(pro.first, pro.second) > 0) {
|
|
|
|
|
pro.second->operator()(0,1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ForkedCallQueue::callback(pid_t, int)
|
|
|
|
|
{
|
2004-07-24 16:40:21 +00:00
|
|
|
|
if (callQueue_.empty()) {
|
2003-02-25 18:56:09 +00:00
|
|
|
|
stopCaller();
|
|
|
|
|
} else {
|
|
|
|
|
callNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ForkedCallQueue::ForkedCallQueue() : running_(false)
|
|
|
|
|
{}
|
|
|
|
|
|
2003-05-06 20:34:12 +00:00
|
|
|
|
|
2003-02-25 18:56:09 +00:00
|
|
|
|
void ForkedCallQueue::startCaller()
|
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "ForkedCallQueue: waking up" << endl;
|
2003-02-25 18:56:09 +00:00
|
|
|
|
running_ = true ;
|
|
|
|
|
callNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ForkedCallQueue::stopCaller()
|
|
|
|
|
{
|
|
|
|
|
running_ = false ;
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS) << "ForkedCallQueue: I'm going to sleep"
|
2003-02-25 18:56:09 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ForkedCallQueue::running() const
|
|
|
|
|
{
|
|
|
|
|
return running_ ;
|
|
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
|
} // namespace lyx
|