2002-02-27 09:59:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file forkedcontr.h
|
2002-09-25 10:03:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
|
|
|
* \author Asger Alstrup Nielsen
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* A class for the control of child processes launched using
|
|
|
|
* fork() and execvp().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FORKEDCONTR_H
|
|
|
|
#define FORKEDCONTR_H
|
|
|
|
|
|
|
|
#include "LString.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
|
|
#include <boost/signals/signal0.hpp>
|
|
|
|
#include <boost/signals/trackable.hpp>
|
|
|
|
|
2002-02-27 12:51:20 +00:00
|
|
|
#include <sys/types.h> // needed for pid_t
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
|
2002-10-31 12:42:26 +00:00
|
|
|
class ForkedProcess;
|
2002-02-27 09:59:52 +00:00
|
|
|
class Timeout;
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
class ForkedcallsController : public boost::signals::trackable {
|
2002-02-27 09:59:52 +00:00
|
|
|
public:
|
2002-03-02 22:57:10 +00:00
|
|
|
/// We need this to avoid warnings.
|
|
|
|
ForkedcallsController();
|
2002-03-01 17:12:13 +00:00
|
|
|
/** This d-tor should really be private, but making it public
|
|
|
|
* allows egcs 1.1 to compile the class.
|
|
|
|
*/
|
|
|
|
~ForkedcallsController();
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Get hold of the only controller that can exist inside the process.
|
2002-03-21 17:09:55 +00:00
|
|
|
static ForkedcallsController & get();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Add a new child process to the list of controlled processes.
|
2002-10-31 12:42:26 +00:00
|
|
|
void addCall(ForkedProcess const &);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** This method is connected to the timer. Every XX ms it is called
|
|
|
|
* so that we can check on the status of the children. Those that
|
|
|
|
* are found to have finished are removed from the list and their
|
|
|
|
* callback function is passed the final return state.
|
|
|
|
*/
|
|
|
|
void timer();
|
|
|
|
|
|
|
|
/// Return a vector of the pids of all the controlled processes.
|
|
|
|
std::vector<pid_t> const getPIDs() const;
|
|
|
|
|
|
|
|
/// Get the command string of the process.
|
|
|
|
string const getCommand(pid_t) const;
|
|
|
|
|
|
|
|
/** Kill this process prematurely and remove it from the list.
|
|
|
|
* The process is killed within tolerance secs.
|
|
|
|
* See forkedcall.[Ch] for details.
|
|
|
|
*/
|
|
|
|
void kill(pid_t, int tolerance = 5);
|
|
|
|
|
|
|
|
/// Signal emitted when the list of current child processes changes.
|
2002-05-29 16:21:03 +00:00
|
|
|
boost::signal0<void> childrenChanged;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
ForkedcallsController(ForkedcallsController const &);
|
|
|
|
|
|
|
|
/// The child processes
|
2002-10-31 12:42:26 +00:00
|
|
|
typedef std::list<ForkedProcess *> ListType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
|
|
|
ListType forkedCalls;
|
|
|
|
|
|
|
|
/** The timer. Enables us to check the status of the children
|
|
|
|
* every XX ms and to invoke a callback on completion.
|
|
|
|
*/
|
2002-03-21 17:09:55 +00:00
|
|
|
Timeout * timeout_;
|
2002-02-27 09:59:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FORKEDCONTR_H
|