diff Core/MultiThreading/ThreadedCommandProcessor.h @ 467:322c1b497036

cancel and listener for commands
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2013 14:42:27 +0200
parents 9da3596069b8
children 2d0a347e8cfc
line wrap: on
line diff
--- a/Core/MultiThreading/ThreadedCommandProcessor.h	Fri Jul 12 12:11:45 2013 +0200
+++ b/Core/MultiThreading/ThreadedCommandProcessor.h	Fri Jul 12 14:42:27 2013 +0200
@@ -40,14 +40,34 @@
 {
   class ThreadedCommandProcessor
   {
+  public:
+    class IListener
+    {
+    public:
+      virtual ~IListener()
+      {
+      }
+
+      virtual void SignalProgress(unsigned int current,
+                                  unsigned int total) = 0;
+
+      virtual void SignalSuccess(unsigned int total) = 0;
+
+      virtual void SignalFailure() = 0;
+
+      virtual void SignalCancel() = 0;
+    };
+
   private:
     SharedMessageQueue  queue_;
     bool done_;
+    bool cancel_;
     std::vector<boost::thread*>  threads_;
+    IListener* listener_;
 
     boost::mutex mutex_;
     bool success_;
-    unsigned int remainingCommands_;
+    unsigned int remainingCommands_, totalCommands_;
     boost::condition_variable processedCommand_;
 
     static void Processor(ThreadedCommandProcessor* that);
@@ -61,5 +81,14 @@
     void Post(ICommand* command);
 
     bool Join();
+
+    void Cancel();
+
+    void SetListener(IListener& listener);
+
+    IListener& GetListener() const
+    {
+      return *listener_;
+    }
   };
 }