Mercurial > hg > orthanc
changeset 1005:84b6d7bca6db lua-scripting
refactoring of ServerContext::Store
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jul 2014 14:34:11 +0200 |
parents | a226e0959d8b |
children | 649d47854314 |
files | OrthancServer/DicomInstanceToStore.cpp OrthancServer/DicomInstanceToStore.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/main.cpp UnitTestsSources/MultiThreadingTests.cpp |
diffstat | 8 files changed, 40 insertions(+), 214 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/DicomInstanceToStore.cpp Tue Jul 08 14:34:11 2014 +0200 @@ -94,7 +94,7 @@ if (!parsed_.HasContent()) { - parsed_.TakeOwnership(new ParsedDicomFile(buffer_.GetContent())); + parsed_.TakeOwnership(new ParsedDicomFile(buffer_.GetConstContent())); } // At this point, we have parsed the DICOM file
--- a/OrthancServer/DicomInstanceToStore.h Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/DicomInstanceToStore.h Tue Jul 08 14:34:11 2014 +0200 @@ -87,10 +87,18 @@ Deallocate(); content_ = content; toDelete_ = true; - isReadOnly_ = true; + isReadOnly_ = false; } - void SetReference(const T& content) // Read-only assign, without transfering ownership + void SetReference(T& content) // Read and write assign, without transfering ownership + { + Deallocate(); + content_ = &content; + toDelete_ = false; + isReadOnly_ = false; + } + + void SetConstReference(const T& content) // Read-only assign, without transfering ownership { Deallocate(); content_ = &const_cast<T&>(content); @@ -186,7 +194,7 @@ public: void SetBuffer(const std::string& dicom) { - buffer_.SetReference(dicom); + buffer_.SetConstReference(dicom); } void SetParsedDicomFile(ParsedDicomFile& parsed) @@ -196,12 +204,12 @@ void SetSummary(const DicomMap& summary) { - summary_.SetReference(summary); + summary_.SetConstReference(summary); } void SetJson(const Json::Value& json) { - json_.SetReference(json); + json_.SetConstReference(json); } const std::string GetRemoteAet() const
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue Jul 08 14:34:11 2014 +0200 @@ -258,6 +258,9 @@ std::auto_ptr<ParsedDicomFile> modified(original.Clone()); modification.Apply(*modified); + DicomInstanceToStore toStore; + toStore.SetParsedDicomFile(*modified); + /** * Prepare the metadata information to associate with the @@ -265,25 +268,24 @@ **/ DicomInstanceHasher modifiedHasher = modified->GetHasher(); - ServerIndex::MetadataMap metadata; if (originalHasher.HashSeries() != modifiedHasher.HashSeries()) { - metadata[std::make_pair(ResourceType_Series, metadataType)] = originalHasher.HashSeries(); + toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher.HashSeries()); } if (originalHasher.HashStudy() != modifiedHasher.HashStudy()) { - metadata[std::make_pair(ResourceType_Study, metadataType)] = originalHasher.HashStudy(); + toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher.HashStudy()); } if (originalHasher.HashPatient() != modifiedHasher.HashPatient()) { - metadata[std::make_pair(ResourceType_Patient, metadataType)] = originalHasher.HashPatient(); + toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher.HashPatient()); } assert(*it == originalHasher.HashInstance()); - metadata[std::make_pair(ResourceType_Instance, metadataType)] = *it; + toStore.AddMetadata(ResourceType_Instance, metadataType, *it); /** @@ -291,7 +293,7 @@ **/ std::string modifiedInstance; - if (context.Store(modifiedInstance, *modified, metadata) != StoreStatus_Success) + if (context.Store(modifiedInstance, toStore) != StoreStatus_Success) { LOG(ERROR) << "Error while storing a modified instance " << *it; return; @@ -429,8 +431,11 @@ modification.Apply(dicom); + DicomInstanceToStore toStore; + toStore.SetParsedDicomFile(dicom); + std::string id; - StoreStatus status = OrthancRestApi::GetContext(call).Store(id, dicom); + StoreStatus status = OrthancRestApi::GetContext(call).Store(id, toStore); if (status == StoreStatus_Failure) {
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Tue Jul 08 14:34:11 2014 +0200 @@ -71,8 +71,11 @@ LOG(INFO) << "Receiving a DICOM file of " << postData.size() << " bytes through HTTP"; + DicomInstanceToStore toStore; + toStore.SetBuffer(postData); + std::string publicId; - StoreStatus status = context.Store(publicId, postData); + StoreStatus status = context.Store(publicId, toStore); OrthancRestApi::GetApi(call).AnswerStoredInstance(call, publicId, status); }
--- a/OrthancServer/ServerContext.cpp Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Tue Jul 08 14:34:11 2014 +0200 @@ -140,7 +140,7 @@ std::cout << result; } -#if 1 +#if 0 { // Autorouting test RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName("sample"); @@ -259,90 +259,6 @@ - StoreStatus ServerContext::Store(const char* dicomInstance, - size_t dicomSize, - const DicomMap& dicomSummary, - const Json::Value& dicomJson, - const std::string& remoteAet, - const ServerIndex::MetadataMap& metadata) - { - Json::Value simplified; - SimplifyTags(simplified, dicomJson); - - // Test if the instance must be filtered out - if (!ApplyReceivedInstanceFilter(simplified, remoteAet)) - { - LOG(INFO) << "An incoming instance has been discarded by the filter"; - return StoreStatus_FilteredOut; - } - - if (compressionEnabled_) - { - accessor_.SetCompressionForNextOperations(CompressionType_Zlib); - } - else - { - accessor_.SetCompressionForNextOperations(CompressionType_None); - } - - FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom); - FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_DicomAsJson); - - ServerIndex::Attachments attachments; - attachments.push_back(dicomInfo); - attachments.push_back(jsonInfo); - - // TODO REMOVE CONST_CAST !!!! - StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet, const_cast<ServerIndex::MetadataMap&>(metadata)); - - if (status != StoreStatus_Success) - { - storage_.Remove(dicomInfo.GetUuid()); - storage_.Remove(jsonInfo.GetUuid()); - } - - switch (status) - { - case StoreStatus_Success: - LOG(INFO) << "New instance stored"; - break; - - case StoreStatus_AlreadyStored: - LOG(INFO) << "Already stored"; - break; - - case StoreStatus_Failure: - LOG(ERROR) << "Store failure"; - break; - - default: - // This should never happen - break; - } - - if (status == StoreStatus_Success || - status == StoreStatus_AlreadyStored) - { - try - { - DicomInstanceHasher hasher(dicomSummary); - std::string instanceId = hasher.HashInstance(); - - Json::Value metadata; - index_.GetMetadata(metadata, instanceId); - - ApplyOnStoredInstance(instanceId, simplified, metadata); - } - catch (OrthancException&) - { - LOG(ERROR) << "Error when dealing with OnStoredInstance"; - } - } - - return status; - } - - void ServerContext::AnswerDicomFile(RestApiOutput& output, const std::string& instancePublicId, FileContentType content) @@ -432,91 +348,6 @@ } - static DcmFileFormat& GetDicom(ParsedDicomFile& file) - { - return *reinterpret_cast<DcmFileFormat*>(file.GetDcmtkObject()); - } - - - StoreStatus ServerContext::Store(std::string& resultPublicId, - ParsedDicomFile& dicomInstance, - const char* dicomBuffer, - size_t dicomSize, - const ServerIndex::MetadataMap& metadata) - { - DicomMap dicomSummary; - FromDcmtkBridge::Convert(dicomSummary, *GetDicom(dicomInstance).getDataset()); - - try - { - DicomInstanceHasher hasher(dicomSummary); - resultPublicId = hasher.HashInstance(); - - Json::Value dicomJson; - FromDcmtkBridge::ToJson(dicomJson, *GetDicom(dicomInstance).getDataset()); - - StoreStatus status = StoreStatus_Failure; - if (dicomSize > 0) - { - status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, "", metadata); - } - - return status; - } - catch (OrthancException& e) - { - if (e.GetErrorCode() == ErrorCode_InexistentTag) - { - LogMissingRequiredTag(dicomSummary); - } - - throw; - } - } - - - StoreStatus ServerContext::Store(std::string& resultPublicId, - ParsedDicomFile& dicomInstance, - const ServerIndex::MetadataMap& metadata) - { - std::string buffer; - if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, *GetDicom(dicomInstance).getDataset())) - { - throw OrthancException(ErrorCode_InternalError); - } - - if (buffer.size() == 0) - return Store(resultPublicId, dicomInstance, NULL, 0, metadata); - else - return Store(resultPublicId, dicomInstance, &buffer[0], buffer.size(), metadata); - } - - - StoreStatus ServerContext::Store(std::string& resultPublicId, - const char* dicomBuffer, - size_t dicomSize, - const ServerIndex::MetadataMap& metadata) - { - ParsedDicomFile dicom(dicomBuffer, dicomSize); - return Store(resultPublicId, dicom, dicomBuffer, dicomSize, metadata); - } - - - StoreStatus ServerContext::Store(std::string& resultPublicId, - const std::string& dicomContent, - const ServerIndex::MetadataMap& metadata) - { - if (dicomContent.size() == 0) - { - return Store(resultPublicId, NULL, 0); - } - else - { - return Store(resultPublicId, &dicomContent[0], dicomContent.size(), metadata); - } - } - - void ServerContext::SetStoreMD5ForAttachments(bool storeMD5) { LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
--- a/OrthancServer/ServerContext.h Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/ServerContext.h Tue Jul 08 14:34:11 2014 +0200 @@ -87,11 +87,6 @@ boost::mutex luaMutex_; LuaContext lua_; - StoreStatus Store(std::string& resultPublicId, - const char* dicomBuffer, - size_t dicomSize, - const ServerIndex::MetadataMap& metadata = ServerIndex::MetadataMap()); - public: class DicomCacheLocker : public boost::noncopyable { @@ -156,32 +151,9 @@ const void* data, size_t size); - - // TODO SIMPLIFY THESE MANY "Store" methods! StoreStatus Store(std::string& resultPublicId, DicomInstanceToStore& dicom); - StoreStatus Store(const char* dicomInstance, - size_t dicomSize, - const DicomMap& dicomSummary, - const Json::Value& dicomJson, - const std::string& remoteAet, - const ServerIndex::MetadataMap& metadata = ServerIndex::MetadataMap()); - - StoreStatus Store(std::string& resultPublicId, - ParsedDicomFile& dicomInstance, - const char* dicomBuffer, - size_t dicomSize, - const ServerIndex::MetadataMap& metadata = ServerIndex::MetadataMap()); - - StoreStatus Store(std::string& resultPublicId, - ParsedDicomFile& dicomInstance, - const ServerIndex::MetadataMap& metadata = ServerIndex::MetadataMap()); - - StoreStatus Store(std::string& resultPublicId, - const std::string& dicomContent, - const ServerIndex::MetadataMap& metadata = ServerIndex::MetadataMap()); - void AnswerDicomFile(RestApiOutput& output, const std::string& instancePublicId, FileContentType content);
--- a/OrthancServer/main.cpp Tue Jul 08 14:06:05 2014 +0200 +++ b/OrthancServer/main.cpp Tue Jul 08 14:34:11 2014 +0200 @@ -71,7 +71,14 @@ { if (dicomFile.size() > 0) { - server_.Store(&dicomFile[0], dicomFile.size(), dicomSummary, dicomJson, remoteAet); + DicomInstanceToStore toStore; + toStore.SetBuffer(dicomFile); + toStore.SetSummary(dicomSummary); + toStore.SetJson(dicomJson); + toStore.SetRemoteAet(remoteAet); + + std::string id; + server_.Store(id, toStore); } } };