2003-02-25 18:56:09 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file forkedcallqueue.h
|
|
|
|
* 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-06-30 23:56:22 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-30 23:56:22 +00:00
|
|
|
*
|
|
|
|
* This class implements a queue of forked processes. In order not to
|
|
|
|
* hose the system with multiple processes running simultaneously, you can
|
|
|
|
* request the addition of your process to this queue and it will be
|
2003-02-25 18:56:09 +00:00
|
|
|
* executed when its turn comes.
|
2003-06-30 23:56:22 +00:00
|
|
|
*
|
2003-02-25 18:56:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FORKEDCALLQUEUE_H
|
|
|
|
#define FORKEDCALLQUEUE_H
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
#include "support/forkedcall.h"
|
2003-02-25 18:56:09 +00:00
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
#include <utility>
|
2003-10-06 15:43:21 +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
|
|
|
class ForkedCallQueue {
|
|
|
|
public:
|
|
|
|
/// A process in the queue
|
2003-10-06 15:43:21 +00:00
|
|
|
typedef std::pair<std::string, Forkedcall::SignalTypePtr> Process;
|
2006-04-05 23:39:11 +00:00
|
|
|
/** Add a process to the queue. Processes are forked sequentially
|
|
|
|
* only one is running at a time.
|
|
|
|
* Connect to the returned signal and you'll be informed when
|
|
|
|
* the process has ended.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
Forkedcall::SignalTypePtr add(std::string const & process);
|
2006-04-05 23:39:11 +00:00
|
|
|
/// Query whether the queue is running a forked process now.
|
2003-02-25 18:56:09 +00:00
|
|
|
bool running() const;
|
|
|
|
/// Get the and only instance of the class
|
|
|
|
static ForkedCallQueue & get();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
/** this class is a singleton class... use
|
2003-02-25 18:56:09 +00:00
|
|
|
* ForkedCallQueue::get() instead
|
|
|
|
*/
|
|
|
|
ForkedCallQueue();
|
2003-06-30 23:56:22 +00:00
|
|
|
/// in-progress queue
|
2003-02-25 18:56:09 +00:00
|
|
|
std::queue<Process> callQueue_;
|
|
|
|
///
|
|
|
|
bool running_;
|
|
|
|
///
|
|
|
|
void callNext();
|
|
|
|
///
|
|
|
|
void startCaller();
|
|
|
|
///
|
|
|
|
void stopCaller();
|
|
|
|
///
|
|
|
|
void callback(pid_t, int);
|
|
|
|
};
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-25 18:56:09 +00:00
|
|
|
#endif // FORKEDCALLQUEUE_H
|