comparison Core/DicomNetworking/DicomAssociationParameters.cpp @ 3875:ea1d32861cfc transcoding

moving timeout from DicomAssocation to DicomAssociationParameters
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 May 2020 14:49:31 +0200
parents 3d1bb2193832
children 661c931f22ad
comparison
equal deleted inserted replaced
3874:2effa961f67f 3875:ea1d32861cfc
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()); 97 }
99 SetRemoteManufacturer(parameters.GetManufacturer()); 98
99
100 void DicomAssociationParameters::SetTimeout(uint32_t seconds)
101 {
102 assert(seconds != -1);
103 timeout_ = seconds;
100 } 104 }
101 105
102 106
103 bool DicomAssociationParameters::IsEqual(const DicomAssociationParameters& other) const 107 bool DicomAssociationParameters::IsEqual(const DicomAssociationParameters& other) const
104 { 108 {
105 return (localAet_ == other.localAet_ && 109 return (localAet_ == other.localAet_ &&
106 remoteAet_ == other.remoteAet_ && 110 remote_.GetApplicationEntityTitle() == other.remote_.GetApplicationEntityTitle() &&
107 remoteHost_ == other.remoteHost_ && 111 remote_.GetHost() == other.remote_.GetHost() &&
108 remotePort_ == other.remotePort_ && 112 remote_.GetPortNumber() == other.remote_.GetPortNumber() &&
109 manufacturer_ == other.manufacturer_); 113 remote_.GetManufacturer() == other.remote_.GetManufacturer() &&
114 timeout_ == other.timeout_);
110 } 115 }
111 116
117
118 static const char* const LOCAL_AET = "LocalAet";
119 static const char* const REMOTE = "Remote";
120 static const char* const TIMEOUT = "Timeout"; // New in Orthanc in 1.7.0
121
122
123 void DicomAssociationParameters::SerializeJob(Json::Value& target) const
124 {
125 if (target.type() != Json::objectValue)
126 {
127 throw OrthancException(ErrorCode_InternalError);
128 }
129 else
130 {
131 target[LOCAL_AET] = localAet_;
132 remote_.Serialize(target[REMOTE], true /* force advanced format */);
133 target[TIMEOUT] = timeout_;
134 }
135 }
136
137
138 DicomAssociationParameters DicomAssociationParameters::UnserializeJob(const Json::Value& serialized)
139 {
140 if (serialized.type() == Json::objectValue)
141 {
142 DicomAssociationParameters result;
112 143
144 result.remote_ = RemoteModalityParameters(serialized[REMOTE]);
145 result.localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET);
146 result.timeout_ = SerializationToolbox::ReadInteger(serialized, TIMEOUT, GetDefaultTimeout());
147
148 return result;
149 }
150 else
151 {
152 throw OrthancException(ErrorCode_BadFileFormat);
153 }
154 }
155
156
113 void DicomAssociationParameters::SetDefaultTimeout(uint32_t seconds) 157 void DicomAssociationParameters::SetDefaultTimeout(uint32_t seconds)
114 { 158 {
115 LOG(INFO) << "Default timeout for DICOM connections if Orthanc acts as SCU (client): " 159 LOG(INFO) << "Default timeout for DICOM connections if Orthanc acts as SCU (client): "
116 << seconds << " seconds (0 = no timeout)"; 160 << seconds << " seconds (0 = no timeout)";
117 161