comparison Core/DicomNetworking/DicomAssociationParameters.cpp @ 3896:210af28c4087 transcoding

merge
author Alain Mazy <alain@mazy.be>
date Thu, 07 May 2020 11:32:15 +0200
parents 661c931f22ad
children
comparison
equal deleted inserted replaced
3895:37cf1889667a 3896:210af28c4087
35 #include "DicomAssociationParameters.h" 35 #include "DicomAssociationParameters.h"
36 36
37 #include "../Compatibility.h" 37 #include "../Compatibility.h"
38 #include "../Logging.h" 38 #include "../Logging.h"
39 #include "../OrthancException.h" 39 #include "../OrthancException.h"
40 #include "../SerializationToolbox.h"
40 #include "NetworkingCompatibility.h" 41 #include "NetworkingCompatibility.h"
41 42
42 #include <boost/thread/mutex.hpp> 43 #include <boost/thread/mutex.hpp>
43 44
44 // By default, the timeout for client DICOM connections is set to 10 seconds 45 // By default, the timeout for client DICOM connections is set to 10 seconds
46 static uint32_t defaultTimeout_ = 10; 47 static uint32_t defaultTimeout_ = 10;
47 48
48 49
49 namespace Orthanc 50 namespace Orthanc
50 { 51 {
51 void DicomAssociationParameters::ReadDefaultTimeout() 52 void DicomAssociationParameters::CheckHost(const std::string& host)
53 {
54 if (host.size() > HOST_NAME_MAX - 10)
55 {
56 throw OrthancException(ErrorCode_ParameterOutOfRange,
57 "Invalid host name (too long): " + host);
58 }
59 }
60
61
62 uint32_t DicomAssociationParameters::GetDefaultTimeout()
52 { 63 {
53 boost::mutex::scoped_lock lock(defaultTimeoutMutex_); 64 boost::mutex::scoped_lock lock(defaultTimeoutMutex_);
54 timeout_ = defaultTimeout_; 65 return defaultTimeout_;
55 } 66 }
56 67
57 68
58 DicomAssociationParameters::DicomAssociationParameters() : 69 DicomAssociationParameters::DicomAssociationParameters() :
59 localAet_("STORESCU"), 70 localAet_("ORTHANC"),
60 remoteAet_("ANY-SCP"), 71 timeout_(GetDefaultTimeout())
61 remoteHost_("127.0.0.1"),
62 remotePort_(104),
63 manufacturer_(ModalityManufacturer_Generic)
64 { 72 {
65 ReadDefaultTimeout(); 73 remote_.SetApplicationEntityTitle("ANY-SCP");
66 } 74 }
67 75
68 76
69 DicomAssociationParameters::DicomAssociationParameters(const std::string& localAet, 77 DicomAssociationParameters::DicomAssociationParameters(const std::string& localAet,
70 const RemoteModalityParameters& remote) : 78 const RemoteModalityParameters& remote) :
71 localAet_(localAet), 79 localAet_(localAet),
72 remoteAet_(remote.GetApplicationEntityTitle()), 80 timeout_(GetDefaultTimeout())
73 remoteHost_(remote.GetHost()),
74 remotePort_(remote.GetPortNumber()),
75 manufacturer_(remote.GetManufacturer()),
76 timeout_(defaultTimeout_)
77 { 81 {
78 ReadDefaultTimeout(); 82 SetRemoteModality(remote);
79 } 83 }
80 84
81 85
82 void DicomAssociationParameters::SetRemoteHost(const std::string& host) 86 void DicomAssociationParameters::SetRemoteModality(const RemoteModalityParameters& remote)
83 { 87 {
84 if (host.size() > HOST_NAME_MAX - 10) 88 CheckHost(remote.GetHost());
85 { 89 remote_ = remote;
86 throw OrthancException(ErrorCode_ParameterOutOfRange,
87 "Invalid host name (too long): " + host);
88 }
89
90 remoteHost_ = host;
91 } 90 }
92 91
93 92
94 void DicomAssociationParameters::SetRemoteModality(const RemoteModalityParameters& parameters) 93 void DicomAssociationParameters::SetRemoteHost(const std::string& host)
95 { 94 {
96 SetRemoteApplicationEntityTitle(parameters.GetApplicationEntityTitle()); 95 CheckHost(host);
97 SetRemoteHost(parameters.GetHost()); 96 remote_.SetHost(host);
98 SetRemotePort(parameters.GetPortNumber());
99 SetRemoteManufacturer(parameters.GetManufacturer());
100 } 97 }
101 98
102 99
103 bool DicomAssociationParameters::IsEqual(const DicomAssociationParameters& other) const 100 bool DicomAssociationParameters::IsEqual(const DicomAssociationParameters& other) const
104 { 101 {
105 return (localAet_ == other.localAet_ && 102 return (localAet_ == other.localAet_ &&
106 remoteAet_ == other.remoteAet_ && 103 remote_.GetApplicationEntityTitle() == other.remote_.GetApplicationEntityTitle() &&
107 remoteHost_ == other.remoteHost_ && 104 remote_.GetHost() == other.remote_.GetHost() &&
108 remotePort_ == other.remotePort_ && 105 remote_.GetPortNumber() == other.remote_.GetPortNumber() &&
109 manufacturer_ == other.manufacturer_); 106 remote_.GetManufacturer() == other.remote_.GetManufacturer() &&
107 timeout_ == other.timeout_);
110 } 108 }
111 109
110
111 static const char* const LOCAL_AET = "LocalAet";
112 static const char* const REMOTE = "Remote";
113 static const char* const TIMEOUT = "Timeout"; // New in Orthanc in 1.7.0
114
115
116 void DicomAssociationParameters::SerializeJob(Json::Value& target) const
117 {
118 if (target.type() != Json::objectValue)
119 {
120 throw OrthancException(ErrorCode_InternalError);
121 }
122 else
123 {
124 target[LOCAL_AET] = localAet_;
125 remote_.Serialize(target[REMOTE], true /* force advanced format */);
126 target[TIMEOUT] = timeout_;
127 }
128 }
129
130
131 DicomAssociationParameters DicomAssociationParameters::UnserializeJob(const Json::Value& serialized)
132 {
133 if (serialized.type() == Json::objectValue)
134 {
135 DicomAssociationParameters result;
112 136
137 result.remote_ = RemoteModalityParameters(serialized[REMOTE]);
138 result.localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET);
139 result.timeout_ = SerializationToolbox::ReadInteger(serialized, TIMEOUT, GetDefaultTimeout());
140
141 return result;
142 }
143 else
144 {
145 throw OrthancException(ErrorCode_BadFileFormat);
146 }
147 }
148
149
113 void DicomAssociationParameters::SetDefaultTimeout(uint32_t seconds) 150 void DicomAssociationParameters::SetDefaultTimeout(uint32_t seconds)
114 { 151 {
115 LOG(INFO) << "Default timeout for DICOM connections if Orthanc acts as SCU (client): " 152 LOG(INFO) << "Default timeout for DICOM connections if Orthanc acts as SCU (client): "
116 << seconds << " seconds (0 = no timeout)"; 153 << seconds << " seconds (0 = no timeout)";
117 154