]> git.lyx.org Git - lyx.git/blobdiff - src/support/ForkedCalls.h
add generic helper class for calling functions in gui thread
[lyx.git] / src / support / ForkedCalls.h
index 0a226fcb7c933bb3a2270cec6e61e43a61a8b305..caeba526e0eaf9a9afe703635fbc12ae651f9259 100644 (file)
@@ -14,7 +14,7 @@
 #ifndef FORKEDCALLS_H
 #define FORKEDCALLS_H
 
-#include <boost/shared_ptr.hpp>
+#include "support/shared_ptr.h"
 #include <boost/signal.hpp>
 
 #ifdef HAVE_SYS_TYPES_H
@@ -41,9 +41,9 @@ public:
        ///
        virtual ~ForkedProcess() {}
        ///
-       virtual boost::shared_ptr<ForkedProcess> clone() const = 0;
+       virtual shared_ptr<ForkedProcess> clone() const = 0;
 
-       /** A SignalType signal is can be emitted once the forked process
+       /** A SignalType signal can be emitted once the forked process
         *  has finished. It passes:
         *  the PID of the child and;
         *  the return value from the child.
@@ -62,7 +62,7 @@ public:
         *
         *  It doesn't matter if the slot disappears, SigC takes care of that.
         */
-       typedef boost::shared_ptr<SignalType> SignalTypePtr;
+       typedef shared_ptr<SignalType> SignalTypePtr;
 
        /** Invoking the following methods makes sense only if the command
         *  is running asynchronously!
@@ -97,12 +97,21 @@ public:
         */
        void kill(int tolerance = 5);
 
+       /// Returns true if this is a child process
+       static bool iAmAChild() { return IAmAChild; }
+
 protected:
        /** Spawn the child process.
         *  Returns returncode from child.
         */
        int run(Starttype type);
 
+       /// implement our own version of fork()
+       /// it just returns -1 if ::fork() is not defined
+       /// otherwise, it forks and sets the global child-process
+       /// boolean IAmAChild
+       pid_t fork();
+
        /// Callback function
        SignalTypePtr signal_;
 
@@ -118,12 +127,15 @@ private:
        /// generate child in background
        virtual int generateChild() = 0;
 
+       ///
+       static bool IAmAChild;
+
        /// Wait for child process to finish. Updates returncode from child.
        int waitForChild();
 };
 
 
-/* 
+/** 
  * An instance of class ForkedCall represents a single child process.
  *
  * Class ForkedCall uses fork() and execvp() to lauch the child process.
@@ -139,8 +151,8 @@ private:
 class ForkedCall : public ForkedProcess {
 public:
        ///
-       virtual boost::shared_ptr<ForkedProcess> clone() const {
-               return boost::shared_ptr<ForkedProcess>(new ForkedCall(*this));
+       virtual shared_ptr<ForkedProcess> clone() const {
+               return shared_ptr<ForkedProcess>(new ForkedCall(*this));
        }
 
        /** Start the child process.