ReusableDicomUserConnection::Locker::Locker(ReusableDicomUserConnection& that,
                                             const RemoteModalityParameters& remote) :
   ::Orthanc::Locker(that)
 {
   that.Open(remote.GetApplicationEntityTitle(), remote.GetHost(), 
             remote.GetPort(), remote.GetManufacturer());
   connection_ = that.connection_;    
 }
  void ReusableDicomUserConnection::Open(const std::string& localAet,
                                         const RemoteModalityParameters& remote)
  {
    if (connection_ != NULL &&
        connection_->GetLocalApplicationEntityTitle() == localAet &&
        connection_->GetRemoteApplicationEntityTitle() == remote.GetApplicationEntityTitle() &&
        connection_->GetRemoteHost() == remote.GetHost() &&
        connection_->GetRemotePort() == remote.GetPort() &&
        connection_->GetRemoteManufacturer() == remote.GetManufacturer())
    {
      // The current connection can be reused
      LOG(INFO) << "Reusing the previous SCU connection";
      return;
    }

    Close();

    connection_ = new DicomUserConnection();
    connection_->SetLocalApplicationEntityTitle(localAet);
    connection_->SetRemoteModality(remote);
    connection_->Open();
  }