Mercurial > hg > orthanc
comparison Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp @ 3851:6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 20 Apr 2020 16:46:44 +0200 |
parents | d729d6e8b484 |
children |
comparison
equal
deleted
inserted
replaced
3850:d729d6e8b484 | 3851:6498739a3c3c |
---|---|
41 | 41 |
42 namespace Orthanc | 42 namespace Orthanc |
43 { | 43 { |
44 static const char* CURRENT = "Current"; | 44 static const char* CURRENT = "Current"; |
45 static const char* DESCRIPTION = "Description"; | 45 static const char* DESCRIPTION = "Description"; |
46 static const char* DICOM_TIMEOUT = "DicomTimeout"; | |
47 static const char* NEXT_OPERATIONS = "Next"; | 46 static const char* NEXT_OPERATIONS = "Next"; |
48 static const char* OPERATION = "Operation"; | 47 static const char* OPERATION = "Operation"; |
49 static const char* OPERATIONS = "Operations"; | 48 static const char* OPERATIONS = "Operations"; |
50 static const char* ORIGINAL_INPUTS = "OriginalInputs"; | 49 static const char* ORIGINAL_INPUTS = "OriginalInputs"; |
51 static const char* TRAILING_TIMEOUT = "TrailingTimeout"; | 50 static const char* TRAILING_TIMEOUT = "TrailingTimeout"; |
125 bool IsDone() const | 124 bool IsDone() const |
126 { | 125 { |
127 return currentInput_ >= originalInputs_->GetSize() + workInputs_->GetSize(); | 126 return currentInput_ >= originalInputs_->GetSize() + workInputs_->GetSize(); |
128 } | 127 } |
129 | 128 |
130 void Step(TimeoutDicomConnectionManager& connectionManager) | 129 void Step() |
131 { | 130 { |
132 if (IsDone()) | 131 if (IsDone()) |
133 { | 132 { |
134 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 133 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
135 } | 134 } |
144 { | 143 { |
145 input = &workInputs_->GetValue(currentInput_ - originalInputs_->GetSize()); | 144 input = &workInputs_->GetValue(currentInput_ - originalInputs_->GetSize()); |
146 } | 145 } |
147 | 146 |
148 JobOperationValues outputs; | 147 JobOperationValues outputs; |
149 operation_->Apply(outputs, *input, connectionManager); | 148 operation_->Apply(outputs, *input); |
150 | 149 |
151 if (!nextOperations_.empty()) | 150 if (!nextOperations_.empty()) |
152 { | 151 { |
153 std::list<Operation*>::iterator first = nextOperations_.begin(); | 152 std::list<Operation*>::iterator first = nextOperations_.begin(); |
154 outputs.Move(*(*first)->workInputs_); | 153 outputs.Move(*(*first)->workInputs_); |
252 { | 251 { |
253 that_.trailingTimeout_ = boost::posix_time::milliseconds(timeout); | 252 that_.trailingTimeout_ = boost::posix_time::milliseconds(timeout); |
254 } | 253 } |
255 | 254 |
256 | 255 |
257 void SequenceOfOperationsJob::Lock::SetDicomAssociationTimeout(unsigned int timeout) | |
258 { | |
259 that_.connectionManager_.SetTimeout(timeout); | |
260 } | |
261 | |
262 | |
263 size_t SequenceOfOperationsJob::Lock::AddOperation(IJobOperation* operation) | 256 size_t SequenceOfOperationsJob::Lock::AddOperation(IJobOperation* operation) |
264 { | 257 { |
265 if (IsDone()) | 258 if (IsDone()) |
266 { | 259 { |
267 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 260 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
339 it != observers_.end(); ++it) | 332 it != observers_.end(); ++it) |
340 { | 333 { |
341 (*it)->SignalDone(*this); | 334 (*it)->SignalDone(*this); |
342 } | 335 } |
343 | 336 |
344 connectionManager_.Close(); | |
345 return JobStepResult::Success(); | 337 return JobStepResult::Success(); |
346 } | 338 } |
347 else | 339 else |
348 { | 340 { |
349 LOG(INFO) << "New operation were added to the sequence of operations"; | 341 LOG(INFO) << "New operation were added to the sequence of operations"; |
358 current_++; | 350 current_++; |
359 } | 351 } |
360 | 352 |
361 if (current_ < operations_.size()) | 353 if (current_ < operations_.size()) |
362 { | 354 { |
363 operations_[current_]->Step(connectionManager_); | 355 operations_[current_]->Step(); |
364 } | 356 } |
365 | |
366 connectionManager_.CheckTimeout(); | |
367 | 357 |
368 return JobStepResult::Continue(); | 358 return JobStepResult::Continue(); |
369 } | 359 } |
370 | 360 |
371 | 361 |
378 | 368 |
379 for (size_t i = 0; i < operations_.size(); i++) | 369 for (size_t i = 0; i < operations_.size(); i++) |
380 { | 370 { |
381 operations_[i]->Reset(); | 371 operations_[i]->Reset(); |
382 } | 372 } |
383 } | |
384 | |
385 | |
386 void SequenceOfOperationsJob::Stop(JobStopReason reason) | |
387 { | |
388 boost::mutex::scoped_lock lock(mutex_); | |
389 connectionManager_.Close(); | |
390 } | 373 } |
391 | 374 |
392 | 375 |
393 float SequenceOfOperationsJob::GetProgress() | 376 float SequenceOfOperationsJob::GetProgress() |
394 { | 377 { |
418 GetJobType(jobType); | 401 GetJobType(jobType); |
419 value[TYPE] = jobType; | 402 value[TYPE] = jobType; |
420 | 403 |
421 value[DESCRIPTION] = description_; | 404 value[DESCRIPTION] = description_; |
422 value[TRAILING_TIMEOUT] = static_cast<unsigned int>(trailingTimeout_.total_milliseconds()); | 405 value[TRAILING_TIMEOUT] = static_cast<unsigned int>(trailingTimeout_.total_milliseconds()); |
423 value[DICOM_TIMEOUT] = connectionManager_.GetTimeout(); | |
424 value[CURRENT] = static_cast<unsigned int>(current_); | 406 value[CURRENT] = static_cast<unsigned int>(current_); |
425 | 407 |
426 Json::Value tmp = Json::arrayValue; | 408 Json::Value tmp = Json::arrayValue; |
427 for (size_t i = 0; i < operations_.size(); i++) | 409 for (size_t i = 0; i < operations_.size(); i++) |
428 { | 410 { |
452 } | 434 } |
453 | 435 |
454 description_ = SerializationToolbox::ReadString(serialized, DESCRIPTION); | 436 description_ = SerializationToolbox::ReadString(serialized, DESCRIPTION); |
455 trailingTimeout_ = boost::posix_time::milliseconds | 437 trailingTimeout_ = boost::posix_time::milliseconds |
456 (SerializationToolbox::ReadUnsignedInteger(serialized, TRAILING_TIMEOUT)); | 438 (SerializationToolbox::ReadUnsignedInteger(serialized, TRAILING_TIMEOUT)); |
457 connectionManager_.SetTimeout | |
458 (SerializationToolbox::ReadUnsignedInteger(serialized, DICOM_TIMEOUT)); | |
459 current_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT); | 439 current_ = SerializationToolbox::ReadUnsignedInteger(serialized, CURRENT); |
460 | 440 |
461 const Json::Value& ops = serialized[OPERATIONS]; | 441 const Json::Value& ops = serialized[OPERATIONS]; |
462 | 442 |
463 // Unserialize the individual operations | 443 // Unserialize the individual operations |