lyx_mirror/src/support/forkedcallqueue.h

69 lines
1.6 KiB
C
Raw Normal View History

// -*- 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)
*
* Full author contact details are available in file CREDITS.
*
* 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
* executed when its turn comes.
*
*/
#ifndef FORKEDCALLQUEUE_H
#define FORKEDCALLQUEUE_H
#include "forkedcall.h"
#include <queue>
#include <utility>
#include "support/std_string.h"
namespace lyx {
namespace support {
class ForkedCallQueue {
public:
/// A process in the queue
typedef std::pair<string, Forkedcall::SignalTypePtr> Process;
/**<2A>Add<64>a<EFBFBD>process<73>to<74>the<68>queue.<2E>Processes<65>are<72>forked<65>sequentially
*<EFBFBD><EFBFBD>only<EFBFBD>one<EFBFBD>is<EFBFBD>running<EFBFBD>at<EFBFBD>a<EFBFBD>time.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*<EFBFBD><EFBFBD>Connect<EFBFBD>to<EFBFBD>the<EFBFBD>returned<EFBFBD>signal<EFBFBD>and<EFBFBD>you'll<EFBFBD>be<EFBFBD>informed<EFBFBD>when
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*<EFBFBD><EFBFBD>the<EFBFBD>process<EFBFBD>has<EFBFBD>ended.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
Forkedcall::SignalTypePtr add(string const & process);
///<2F>Query<72>whether<65>the<68>queue<75>is<69>running<6E>a<EFBFBD>forked<65>process<73>now.
bool running() const;
/// Get the and only instance of the class
static ForkedCallQueue & get();
private:
/** this class is a singleton class... use
* ForkedCallQueue::get() instead
*/
ForkedCallQueue();
/// in-progress queue
std::queue<Process> callQueue_;
///
bool running_;
///
void callNext();
///
void startCaller();
///
void stopCaller();
///
void callback(pid_t, int);
};
} // namespace support
} // namespace lyx
#endif // FORKEDCALLQUEUE_H