changeset 3826:e82bd07c384e

putting DicomAssociation behind pimpl
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 10 Apr 2020 16:12:10 +0200
parents 4570c57668a8
children 638906dcfe32 3d1bb2193832
files Core/DicomNetworking/DicomControlUserConnection.cpp Core/DicomNetworking/DicomControlUserConnection.h Core/DicomNetworking/DicomStoreUserConnection.cpp Core/DicomNetworking/DicomStoreUserConnection.h
diffstat 4 files changed, 51 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomNetworking/DicomControlUserConnection.cpp	Fri Apr 10 16:04:54 2020 +0200
+++ b/Core/DicomNetworking/DicomControlUserConnection.cpp	Fri Apr 10 16:12:10 2020 +0200
@@ -34,9 +34,10 @@
 #include "../PrecompiledHeaders.h"
 #include "DicomControlUserConnection.h"
 
+#include "../DicomParsing/FromDcmtkBridge.h"
 #include "../Logging.h"
 #include "../OrthancException.h"
-#include "../DicomParsing/FromDcmtkBridge.h"
+#include "DicomAssociation.h"
 
 #include <dcmtk/dcmdata/dcdeftag.h>
 #include <dcmtk/dcmnet/diutil.h>
@@ -224,11 +225,11 @@
 
   void DicomControlUserConnection::SetupPresentationContexts()
   {
-    association_.ProposeGenericPresentationContext(UID_VerificationSOPClass);
-    association_.ProposeGenericPresentationContext(UID_FINDPatientRootQueryRetrieveInformationModel);
-    association_.ProposeGenericPresentationContext(UID_FINDStudyRootQueryRetrieveInformationModel);
-    association_.ProposeGenericPresentationContext(UID_MOVEStudyRootQueryRetrieveInformationModel);
-    association_.ProposeGenericPresentationContext(UID_FINDModalityWorklistInformationModel);
+    association_->ProposeGenericPresentationContext(UID_VerificationSOPClass);
+    association_->ProposeGenericPresentationContext(UID_FINDPatientRootQueryRetrieveInformationModel);
+    association_->ProposeGenericPresentationContext(UID_FINDStudyRootQueryRetrieveInformationModel);
+    association_->ProposeGenericPresentationContext(UID_MOVEStudyRootQueryRetrieveInformationModel);
+    association_->ProposeGenericPresentationContext(UID_FINDModalityWorklistInformationModel);
   }
     
 
@@ -240,7 +241,7 @@
   {
     assert(isWorklist ^ (level != NULL));
 
-    association_.Open(parameters_);
+    association_->Open(parameters_);
 
     FindPayload payload;
     payload.answers = &answers;
@@ -249,7 +250,7 @@
 
     // Figure out which of the accepted presentation contexts should be used
     int presID = ASC_findAcceptedPresentationContextID(
-      &association_.GetDcmtkAssociation(), sopClass);
+      &association_->GetDcmtkAssociation(), sopClass);
     if (presID == 0)
     {
       throw OrthancException(ErrorCode_DicomFindUnavailable,
@@ -258,7 +259,7 @@
 
     T_DIMSE_C_FindRQ request;
     memset(&request, 0, sizeof(request));
-    request.MessageID = association_.GetDcmtkAssociation().nextMsgID++;
+    request.MessageID = association_->GetDcmtkAssociation().nextMsgID++;
     strncpy(request.AffectedSOPClassUID, sopClass, DIC_UI_LEN);
     request.Priority = DIMSE_PRIORITY_MEDIUM;
     request.DataSetType = DIMSE_DATASET_PRESENT;
@@ -271,7 +272,7 @@
 #endif
 
     OFCondition cond = DIMSE_findUser(
-      &association_.GetDcmtkAssociation(), presID, &request, dataset,
+      &association_->GetDcmtkAssociation(), presID, &request, dataset,
 #if DCMTK_VERSION_NUMBER >= 364
       responseCount,
 #endif
@@ -323,7 +324,7 @@
                                                 ResourceType level,
                                                 const DicomMap& fields)
   {
-    association_.Open(parameters_);
+    association_->Open(parameters_);
 
     std::unique_ptr<ParsedDicomFile> query(
       ConvertQueryFields(fields, parameters_.GetRemoteManufacturer()));
@@ -353,7 +354,7 @@
     }
 
     // Figure out which of the accepted presentation contexts should be used
-    int presID = ASC_findAcceptedPresentationContextID(&association_.GetDcmtkAssociation(), sopClass);
+    int presID = ASC_findAcceptedPresentationContextID(&association_->GetDcmtkAssociation(), sopClass);
     if (presID == 0)
     {
       throw OrthancException(ErrorCode_DicomMoveUnavailable,
@@ -362,7 +363,7 @@
 
     T_DIMSE_C_MoveRQ request;
     memset(&request, 0, sizeof(request));
-    request.MessageID = association_.GetDcmtkAssociation().nextMsgID++;
+    request.MessageID = association_->GetDcmtkAssociation().nextMsgID++;
     strncpy(request.AffectedSOPClassUID, sopClass, DIC_UI_LEN);
     request.Priority = DIMSE_PRIORITY_MEDIUM;
     request.DataSetType = DIMSE_DATASET_PRESENT;
@@ -372,10 +373,10 @@
     DcmDataset* statusDetail = NULL;
     DcmDataset* responseIdentifiers = NULL;
     OFCondition cond = DIMSE_moveUser(
-      &association_.GetDcmtkAssociation(), presID, &request, dataset, NULL, NULL,
+      &association_->GetDcmtkAssociation(), presID, &request, dataset, NULL, NULL,
       /*opt_blockMode*/ (parameters_.HasTimeout() ? DIMSE_NONBLOCKING : DIMSE_BLOCKING),
       /*opt_dimse_timeout*/ parameters_.GetTimeout(),
-      &association_.GetDcmtkNetwork(), NULL, NULL,
+      &association_->GetDcmtkNetwork(), NULL, NULL,
       &response, &statusDetail, &responseIdentifiers);
 
     if (statusDetail)
@@ -422,7 +423,8 @@
     
 
   DicomControlUserConnection::DicomControlUserConnection(const DicomAssociationParameters& params) :
-    parameters_(params)
+    parameters_(params),
+    association_(new DicomAssociation)
   {
     SetupPresentationContexts();
   }
@@ -430,12 +432,12 @@
 
   bool DicomControlUserConnection::Echo()
   {
-    association_.Open(parameters_);
+    association_->Open(parameters_);
 
     DIC_US status;
     DicomAssociation::CheckCondition(
-      DIMSE_echoUser(&association_.GetDcmtkAssociation(),
-                     association_.GetDcmtkAssociation().nextMsgID++, 
+      DIMSE_echoUser(&association_->GetDcmtkAssociation(),
+                     association_->GetDcmtkAssociation().nextMsgID++, 
                      /*opt_blockMode*/ (parameters_.HasTimeout() ? DIMSE_NONBLOCKING : DIMSE_BLOCKING),
                      /*opt_dimse_timeout*/ parameters_.GetTimeout(),
                      &status, NULL),
--- a/Core/DicomNetworking/DicomControlUserConnection.h	Fri Apr 10 16:04:54 2020 +0200
+++ b/Core/DicomNetworking/DicomControlUserConnection.h	Fri Apr 10 16:12:10 2020 +0200
@@ -37,16 +37,20 @@
 #  error The macro ORTHANC_ENABLE_DCMTK_NETWORKING must be set to 1
 #endif
 
-#include "DicomAssociation.h"
+#include "DicomAssociationParameters.h"
 #include "DicomFindAnswers.h"
 
+#include <boost/noncopyable.hpp>
+
 namespace Orthanc
 {
+  class DicomAssociation;  // Forward declaration for PImpl design pattern
+  
   class DicomControlUserConnection : public boost::noncopyable
   {
   private:
-    DicomAssociationParameters  parameters_;
-    DicomAssociation            association_;
+    DicomAssociationParameters           parameters_;
+    boost::shared_ptr<DicomAssociation>  association_;
 
     void SetupPresentationContexts();
 
--- a/Core/DicomNetworking/DicomStoreUserConnection.cpp	Fri Apr 10 16:04:54 2020 +0200
+++ b/Core/DicomNetworking/DicomStoreUserConnection.cpp	Fri Apr 10 16:12:10 2020 +0200
@@ -34,6 +34,8 @@
 #include "../PrecompiledHeaders.h"
 #include "DicomStoreUserConnection.h"
 
+#include "DicomAssociation.h"
+
 #include "../Logging.h"
 #include "../OrthancException.h"
 
@@ -48,7 +50,7 @@
       requiredCount += 1;
     }
       
-    if (association_.GetRemainingPropositions() <= requiredCount)
+    if (association_->GetRemainingPropositions() <= requiredCount)
     {
       return false;  // Not enough room
     }
@@ -56,7 +58,7 @@
     for (std::set<DicomTransferSyntax>::const_iterator
            it = syntaxes.begin(); it != syntaxes.end(); ++it)
     {
-      association_.ProposePresentationContext(sopClassUid, *it);
+      association_->ProposePresentationContext(sopClassUid, *it);
     }
 
     if (proposeUncompressedSyntaxes_)
@@ -81,7 +83,7 @@
 
       if (!uncompressed.empty())
       {
-        association_.ProposePresentationContext(sopClassUid, uncompressed);
+        association_->ProposePresentationContext(sopClassUid, uncompressed);
       }
     }      
 
@@ -97,8 +99,8 @@
     typedef std::map<DicomTransferSyntax, uint8_t>  PresentationContexts;
 
     PresentationContexts pc;
-    if (association_.IsOpen() &&
-        association_.LookupAcceptedPresentationContext(pc, sopClassUid))
+    if (association_->IsOpen() &&
+        association_->LookupAcceptedPresentationContext(pc, sopClassUid))
     {
       PresentationContexts::const_iterator found = pc.find(transferSyntax);
       if (found != pc.end())
@@ -115,6 +117,7 @@
   DicomStoreUserConnection::DicomStoreUserConnection(
     const DicomAssociationParameters& params) :
     parameters_(params),
+    association_(new DicomAssociation),
     proposeCommonClasses_(true),
     proposeUncompressedSyntaxes_(true),
     proposeRetiredBigEndian_(false)
@@ -158,7 +161,7 @@
     // The association must be re-negotiated
     LOG(INFO) << "Re-negociating DICOM association with "
               << parameters_.GetRemoteApplicationEntityTitle();
-    association_.ClearPresentationContexts();
+    association_->ClearPresentationContexts();
     PrepareStorageClass(sopClassUid, transferSyntax);
 
       
@@ -231,7 +234,7 @@
      * class UID, transfer syntax) was accepted by the remote host.
      **/
 
-    association_.Open(parameters_);
+    association_->Open(parameters_);
     return LookupPresentationContext(presentationContextId, sopClassUid, transferSyntax);
   }
 }
--- a/Core/DicomNetworking/DicomStoreUserConnection.h	Fri Apr 10 16:04:54 2020 +0200
+++ b/Core/DicomNetworking/DicomStoreUserConnection.h	Fri Apr 10 16:12:10 2020 +0200
@@ -33,7 +33,12 @@
 
 #pragma once
 
-#include "DicomAssociation.h"
+#include "DicomAssociationParameters.h"
+
+#include <boost/shared_ptr.hpp>
+#include <boost/noncopyable.hpp>
+#include <set>
+#include <stdint.h>  // For uint8_t
 
 
 namespace Orthanc
@@ -56,19 +61,19 @@
 
   **/
 
+  class DicomAssociation;  // Forward declaration for PImpl design pattern
 
   class DicomStoreUserConnection : public boost::noncopyable
   {
   private:
     typedef std::map<std::string, std::set<DicomTransferSyntax> > StorageClasses;
     
-    DicomAssociationParameters  parameters_;
-    DicomAssociation            association_;
-    StorageClasses              storageClasses_;
-    bool                        proposeCommonClasses_;
-    bool                        proposeUncompressedSyntaxes_;
-    bool                        proposeRetiredBigEndian_;
-
+    DicomAssociationParameters           parameters_;
+    boost::shared_ptr<DicomAssociation>  association_;
+    StorageClasses                       storageClasses_;
+    bool                                 proposeCommonClasses_;
+    bool                                 proposeUncompressedSyntaxes_;
+    bool                                 proposeRetiredBigEndian_;
 
     // Return "false" if there is not enough room remaining in the association
     bool ProposeStorageClass(const std::string& sopClassUid,