# HG changeset patch # User Sebastien Jodogne # Date 1398860126 -7200 # Node ID 537837f50fbb03d92c050c41257f29c2883823f8 # Parent 3f946e5c3802d3ff36417a049d371785ab1b9090 refactoring diff -r 3f946e5c3802 -r 537837f50fbb OrthancServer/OrthancInitialization.cpp --- a/OrthancServer/OrthancInitialization.cpp Wed Apr 30 13:49:41 2014 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Wed Apr 30 14:15:26 2014 +0200 @@ -585,27 +585,4 @@ return LookupDicomModalityUsingAETitle(aet, symbolicName, address, port, manufacturer); } - - - void ConnectToModalityUsingAETitle(DicomUserConnection& connection, - const std::string& aet) - { - std::string symbolicName, address; - int port; - ModalityManufacturer manufacturer; - - if (!LookupDicomModalityUsingAETitle(aet, symbolicName, address, port, manufacturer)) - { - throw OrthancException("Unknown modality: " + aet); - } - - LOG(WARNING) << "Connecting to remote DICOM modality: AET=" << aet << ", address=" << address << ", port=" << port; - - connection.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); - connection.SetDistantApplicationEntityTitle(aet); - connection.SetDistantHost(address); - connection.SetDistantPort(port); - connection.SetDistantManufacturer(manufacturer); - connection.Open(); - } } diff -r 3f946e5c3802 -r 537837f50fbb OrthancServer/OrthancInitialization.h --- a/OrthancServer/OrthancInitialization.h Wed Apr 30 13:49:41 2014 +0200 +++ b/OrthancServer/OrthancInitialization.h Wed Apr 30 14:15:26 2014 +0200 @@ -89,9 +89,6 @@ void ConnectToModalityUsingSymbolicName(DicomUserConnection& connection, const std::string& name); - void ConnectToModalityUsingAETitle(DicomUserConnection& connection, - const std::string& aet); - bool IsKnownAETitle(const std::string& aet); bool IsSameAETitle(const std::string& aet1, diff -r 3f946e5c3802 -r 537837f50fbb OrthancServer/OrthancMoveRequestHandler.cpp --- a/OrthancServer/OrthancMoveRequestHandler.cpp Wed Apr 30 13:49:41 2014 +0200 +++ b/OrthancServer/OrthancMoveRequestHandler.cpp Wed Apr 30 14:15:26 2014 +0200 @@ -47,17 +47,21 @@ private: ServerContext& context_; std::vector instances_; - DicomUserConnection connection_; size_t position_; + std::string aet_, address_; + int port_; + ModalityManufacturer manufacturer_; + public: OrthancMoveRequestIterator(ServerContext& context, - const std::string& target, + const std::string& aet, const std::string& publicId) : context_(context), - position_(0) + position_(0), + aet_(aet) { - LOG(INFO) << "Sending resource " << publicId << " to modality \"" << target << "\""; + LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\""; std::list tmp; context_.GetIndex().GetChildInstances(tmp, publicId); @@ -67,8 +71,12 @@ { instances_.push_back(*it); } - - ConnectToModalityUsingAETitle(connection_, target); + + std::string symbolicName; + if (!LookupDicomModalityUsingAETitle(aet_, symbolicName, address_, port_, manufacturer_)) + { + throw OrthancException("Unknown modality: " + aet_); + } } virtual unsigned int GetSubOperationCount() const @@ -87,7 +95,12 @@ std::string dicom; context_.ReadFile(dicom, id, FileContentType_Dicom); - connection_.Store(dicom); + + { + ReusableDicomUserConnection::Connection connection(context_.GetReusableDicomUserConnection(), + aet_, address_, port_, manufacturer_); + connection.GetConnection().Store(dicom); + } return Status_Success; } @@ -121,10 +134,10 @@ } - IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& target, + IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet, const DicomMap& input) { - LOG(WARNING) << "Move-SCU request received for AET \"" << target << "\""; + LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\""; /** @@ -173,6 +186,6 @@ throw OrthancException(ErrorCode_BadRequest); } - return new OrthancMoveRequestIterator(context_, target, publicId); + return new OrthancMoveRequestIterator(context_, aet, publicId); } } diff -r 3f946e5c3802 -r 537837f50fbb OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Wed Apr 30 13:49:41 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Wed Apr 30 14:15:26 2014 +0200 @@ -35,6 +35,7 @@ #include "../Core/HttpServer/FilesystemHttpSender.h" #include "../Core/Lua/LuaFunctionCall.h" #include "ServerToolbox.h" +#include "OrthancInitialization.h" #include #include @@ -65,6 +66,7 @@ provider_(*this), dicomCache_(provider_, DICOM_CACHE_SIZE) { + scu_.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); } diff -r 3f946e5c3802 -r 537837f50fbb OrthancServer/ServerContext.h --- a/OrthancServer/ServerContext.h Wed Apr 30 13:49:41 2014 +0200 +++ b/OrthancServer/ServerContext.h Wed Apr 30 14:15:26 2014 +0200 @@ -39,6 +39,7 @@ #include "../Core/Lua/LuaContext.h" #include "ServerIndex.h" #include "FromDcmtkBridge.h" +#include "DicomProtocol/ReusableDicomUserConnection.h" namespace Orthanc { @@ -70,6 +71,7 @@ DicomCacheProvider provider_; MemoryCache dicomCache_; + ReusableDicomUserConnection scu_; LuaContext lua_; @@ -150,5 +152,10 @@ { return accessor_.IsStoreMD5(); } + + ReusableDicomUserConnection& GetReusableDicomUserConnection() + { + return scu_; + } }; }