comparison 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
comparison
equal deleted inserted replaced
466:9da3596069b8 467:322c1b497036
38 38
39 namespace Orthanc 39 namespace Orthanc
40 { 40 {
41 class ThreadedCommandProcessor 41 class ThreadedCommandProcessor
42 { 42 {
43 public:
44 class IListener
45 {
46 public:
47 virtual ~IListener()
48 {
49 }
50
51 virtual void SignalProgress(unsigned int current,
52 unsigned int total) = 0;
53
54 virtual void SignalSuccess(unsigned int total) = 0;
55
56 virtual void SignalFailure() = 0;
57
58 virtual void SignalCancel() = 0;
59 };
60
43 private: 61 private:
44 SharedMessageQueue queue_; 62 SharedMessageQueue queue_;
45 bool done_; 63 bool done_;
64 bool cancel_;
46 std::vector<boost::thread*> threads_; 65 std::vector<boost::thread*> threads_;
66 IListener* listener_;
47 67
48 boost::mutex mutex_; 68 boost::mutex mutex_;
49 bool success_; 69 bool success_;
50 unsigned int remainingCommands_; 70 unsigned int remainingCommands_, totalCommands_;
51 boost::condition_variable processedCommand_; 71 boost::condition_variable processedCommand_;
52 72
53 static void Processor(ThreadedCommandProcessor* that); 73 static void Processor(ThreadedCommandProcessor* that);
54 74
55 public: 75 public:
59 79
60 // This takes the ownership of the command 80 // This takes the ownership of the command
61 void Post(ICommand* command); 81 void Post(ICommand* command);
62 82
63 bool Join(); 83 bool Join();
84
85 void Cancel();
86
87 void SetListener(IListener& listener);
88
89 IListener& GetListener() const
90 {
91 return *listener_;
92 }
64 }; 93 };
65 } 94 }