]> git.lyx.org Git - lyx.git/blobdiff - src/support/forkedcontr.h
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / forkedcontr.h
index c443a5da1ba3c38131dfc47dd5fbe6e1a2d42eec..b5dbe72340cdf653fa993135787fc79d33bf52b1 100644 (file)
@@ -1,12 +1,14 @@
 // -*- C++ -*-
 /**
  * \file forkedcontr.h
- * Copyright 2001 The LyX Team
- * Read COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author Asger Alstrup Nielsen
  * \author Angus Leeming
  *
+ * Full author contact details are available in file CREDITS.
+ *
  * A class for the control of child processes launched using
  * fork() and execvp().
  */
 #ifndef FORKEDCONTR_H
 #define FORKEDCONTR_H
 
+#include <boost/shared_ptr.hpp>
+#include <csignal>
+//#include <sys/types.h> // needed for pid_t
 #include <list>
 #include <vector>
-#include "LString.h"
-#include <sigc++/signal_system.h>
-#include <sys/types.h> // needed for pid_t
 
-#ifdef __GNUG__
-#pragma interface
-#endif
+namespace lyx {
+namespace support {
 
-class Forkedcall;
-class Timeout;
+class ForkedProcess;
 
-class ForkedcallsController : public SigC::Object {
+class ForkedcallsController {
 public:
-       /** This d-tor should really be private, but making it public
-        *   allows egcs 1.1 to compile the class.
-        */
-       ~ForkedcallsController();
-
        /// Get hold of the only controller that can exist inside the process.
-        static ForkedcallsController & get();
+       static ForkedcallsController & get();
 
-       /// Add a new child process to the list of controlled processes.
-       void addCall(Forkedcall const & newcall);
+       /// Are there any completed child processes to be cleaned-up after?
+       bool processesCompleted() const { return current_child != -1; }
 
-       /** 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.
+       /** Those child processes 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;
+       void handleCompletedProcesses();
 
-       /// Get the command string of the process.
-       string const getCommand(pid_t) const;
+       /// Add a new child process to the list of controlled processes.
+       void addCall(ForkedProcess const &);
 
        /** Kill this process prematurely and remove it from the list.
         *  The process is killed within tolerance secs.
@@ -59,24 +50,39 @@ public:
         */
        void kill(pid_t, int tolerance = 5);
 
-       /// Signal emitted when the list of current child processes changes.
-       SigC::Signal0<void> childrenChanged;
-       
+       struct Data {
+               Data() : pid(0), status(0) {}
+               pid_t pid;
+               int status;
+       };
+
+       /** These data are used by the SIGCHLD handler to populate a list
+        *  of child processes that have completed and been reaped.
+        *  The associated signals are then emitted within the main LyX
+        *  event loop.
+        */
+       std::vector<Data> reaped_children;
+       sig_atomic_t current_child;
+
 private:
-       /// Can't create multiple instances of ForkedcallsController.
        ForkedcallsController();
-       ///
        ForkedcallsController(ForkedcallsController const &);
+       ~ForkedcallsController();
+
+       typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
+       typedef std::list<ForkedProcessPtr> ListType;
+       typedef ListType::iterator iterator;
+
+       iterator find_pid(pid_t);
 
        /// The child processes
-       typedef std::list<Forkedcall *> ListType;
-       ///
        ListType forkedCalls;
 
-       /** The timer. Enables us to check the status of the children
-        *  every XX ms and to invoke a callback on completion.
-        */
-        Timeout * timeout_;
+       /// Used to block SIGCHLD signals.
+       sigset_t newMask, oldMask;
 };
 
+} // namespace support
+} // namespace lyx
+
 #endif // FORKEDCONTR_H