changeset 771:537837f50fbb

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Apr 2014 14:15:26 +0200
parents 3f946e5c3802
children 31cc399c7762
files OrthancServer/OrthancInitialization.cpp OrthancServer/OrthancInitialization.h OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 5 files changed, 32 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- 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();
-  }
 }
--- 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,
--- 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<std::string> 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<std::string> 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);
   }
 }
--- 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 <glog/logging.h>
 #include <EmbeddedResources.h>
@@ -65,6 +66,7 @@
     provider_(*this),
     dicomCache_(provider_, DICOM_CACHE_SIZE)
   {
+    scu_.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
     lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
   }
 
--- 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_;
+    }
   };
 }