comparison CppClient/ThreadedCommandProcessor.cpp @ 6:c584c25a74fd

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jun 2015 10:22:49 +0200
parents 798076adf9e9
children e59bf2554e59
comparison
equal deleted inserted replaced
5:798076adf9e9 6:c584c25a74fd
32 32
33 #include "ThreadedCommandProcessor.h" 33 #include "ThreadedCommandProcessor.h"
34 34
35 #include "../Orthanc/Core/OrthancException.h" 35 #include "../Orthanc/Core/OrthancException.h"
36 36
37 namespace Orthanc 37 namespace OrthancClient
38 { 38 {
39 static const int32_t TIMEOUT = 10; 39 static const int32_t TIMEOUT = 10;
40 40
41 41
42 void ThreadedCommandProcessor::Processor(ThreadedCommandProcessor* that) 42 void ThreadedCommandProcessor::Processor(ThreadedCommandProcessor* that)
43 { 43 {
44 while (!that->done_) 44 while (!that->done_)
45 { 45 {
46 std::auto_ptr<IDynamicObject> command(that->queue_.Dequeue(TIMEOUT)); 46 std::auto_ptr<Orthanc::IDynamicObject> command(that->queue_.Dequeue(TIMEOUT));
47 47
48 if (command.get() != NULL) 48 if (command.get() != NULL)
49 { 49 {
50 bool success = false; 50 bool success = false;
51 51
61 // of this command, yet mark it as succeeded. 61 // of this command, yet mark it as succeeded.
62 success = true; 62 success = true;
63 } 63 }
64 else 64 else
65 { 65 {
66 success = dynamic_cast<ICommand&>(*command).Execute(); 66 success = dynamic_cast<Orthanc::ICommand&>(*command).Execute();
67 } 67 }
68 } 68 }
69 else 69 else
70 { 70 {
71 // A command has already failed. Skip the execution of this command. 71 // A command has already failed. Skip the execution of this command.
72 } 72 }
73 } 73 }
74 catch (OrthancException) 74 catch (Orthanc::OrthancException&)
75 { 75 {
76 } 76 }
77 77
78 { 78 {
79 boost::mutex::scoped_lock lock(that->mutex_); 79 boost::mutex::scoped_lock lock(that->mutex_);
115 115
116 ThreadedCommandProcessor::ThreadedCommandProcessor(unsigned int numThreads) 116 ThreadedCommandProcessor::ThreadedCommandProcessor(unsigned int numThreads)
117 { 117 {
118 if (numThreads < 1) 118 if (numThreads < 1)
119 { 119 {
120 throw OrthancException(ErrorCode_ParameterOutOfRange); 120 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
121 } 121 }
122 122
123 listener_ = NULL; 123 listener_ = NULL;
124 success_ = true; 124 success_ = true;
125 done_ = false; 125 done_ = false;
154 } 154 }
155 } 155 }
156 } 156 }
157 157
158 158
159 void ThreadedCommandProcessor::Post(ICommand* command) 159 void ThreadedCommandProcessor::Post(Orthanc::ICommand* command)
160 { 160 {
161 if (command == NULL) 161 if (command == NULL)
162 { 162 {
163 throw OrthancException(ErrorCode_ParameterOutOfRange); 163 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
164 } 164 }
165 165
166 boost::mutex::scoped_lock lock(mutex_); 166 boost::mutex::scoped_lock lock(mutex_);
167 queue_.Enqueue(command); 167 queue_.Enqueue(command);
168 remainingCommands_++; 168 remainingCommands_++;