# HG changeset patch # User Sebastien Jodogne # Date 1561028126 -7200 # Node ID 9313f6157eef378ed2904e6997f5a647e2175879 # Parent 66139300c21ed39c9566a04b86b25d9c2eaf43d6 cont diff -r 66139300c21e -r 9313f6157eef Plugin/DicomWebClient.cpp --- a/Plugin/DicomWebClient.cpp Thu Jun 20 12:40:09 2019 +0200 +++ b/Plugin/DicomWebClient.cpp Thu Jun 20 12:55:26 2019 +0200 @@ -1041,9 +1041,11 @@ enum State { State_Headers, - State_Body + State_Body, + State_Stopped }; - + + boost::mutex mutex_; State state_; std::list instances_; std::auto_ptr reader_; @@ -1103,7 +1105,10 @@ void Close() { - if (reader_.get() != NULL) + boost::mutex::scoped_lock lock(mutex_); + + if (state_ != State_Stopped && + reader_.get() != NULL) { reader_->CloseStream(); } @@ -1112,7 +1117,13 @@ virtual void AddHeader(const std::string& key, const std::string& value) { - if (state_ != State_Headers) + boost::mutex::scoped_lock lock(mutex_); + + if (state_ == State_Stopped) + { + return; + } + else if (state_ != State_Headers) { throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } @@ -1147,10 +1158,16 @@ } } - virtual void AddChunk(const void* data, size_t size) { + boost::mutex::scoped_lock lock(mutex_); + + if (state_ == State_Stopped) + { + return; + } + if (reader_.get() == NULL) { throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, @@ -1162,9 +1179,17 @@ reader_->AddChunk(data, size); } - const std::list& GetReceivedInstances() const + void GetReceivedInstances(std::list& target) { - return instances_; + boost::mutex::scoped_lock lock(mutex_); + target = instances_; + } + + void Stop() + { + boost::mutex::scoped_lock lock(mutex_); + + state_ = State_Stopped; } }; @@ -1177,12 +1202,21 @@ OrthancPlugins::HttpClient client; ConfigureGetFromServer(client, request); - WadoRetrieveAnswer answer; - client.Execute(answer); - answer.Close(); + std::list instances; + + // Do some loop + { + WadoRetrieveAnswer answer; + client.Execute(answer); + answer.Close(); + + std::list tmp; + answer.GetReceivedInstances(tmp); + instances.splice(instances.end(), tmp); + } Json::Value result = Json::objectValue; - result["InstancesCount"] = static_cast(answer.GetReceivedInstances().size()); + result["InstancesCount"] = static_cast(instances.size()); std::string tmp = result.toStyledString(); OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output,