Mercurial > hg > orthanc
comparison OrthancServer/DicomProtocol/ReusableDicomUserConnection.cpp @ 1427:d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Jun 2015 12:42:54 +0200 |
parents | 6e7e5ed91c2d |
children | c0bdc47165ef |
comparison
equal
deleted
inserted
replaced
1426:2cf9a12c995a | 1427:d710ea64f0fd |
---|---|
42 static boost::posix_time::ptime Now() | 42 static boost::posix_time::ptime Now() |
43 { | 43 { |
44 return boost::posix_time::microsec_clock::local_time(); | 44 return boost::posix_time::microsec_clock::local_time(); |
45 } | 45 } |
46 | 46 |
47 void ReusableDicomUserConnection::Open(const std::string& remoteAet, | 47 void ReusableDicomUserConnection::Open(const std::string& localAet, |
48 const std::string& address, | 48 const RemoteModalityParameters& remote) |
49 int port, | |
50 ModalityManufacturer manufacturer) | |
51 { | 49 { |
52 if (connection_ != NULL && | 50 if (connection_ != NULL && |
53 connection_->GetRemoteApplicationEntityTitle() == remoteAet && | 51 connection_->GetLocalApplicationEntityTitle() == localAet && |
54 connection_->GetRemoteHost() == address && | 52 connection_->GetRemoteApplicationEntityTitle() == remote.GetApplicationEntityTitle() && |
55 connection_->GetRemotePort() == port && | 53 connection_->GetRemoteHost() == remote.GetHost() && |
56 connection_->GetRemoteManufacturer() == manufacturer) | 54 connection_->GetRemotePort() == remote.GetPort() && |
55 connection_->GetRemoteManufacturer() == remote.GetManufacturer()) | |
57 { | 56 { |
58 // The current connection can be reused | 57 // The current connection can be reused |
59 LOG(INFO) << "Reusing the previous SCU connection"; | 58 LOG(INFO) << "Reusing the previous SCU connection"; |
60 return; | 59 return; |
61 } | 60 } |
62 | 61 |
63 Close(); | 62 Close(); |
64 | 63 |
65 connection_ = new DicomUserConnection(); | 64 connection_ = new DicomUserConnection(); |
66 connection_->SetLocalApplicationEntityTitle(localAet_); | 65 connection_->SetLocalApplicationEntityTitle(localAet); |
67 connection_->SetRemoteApplicationEntityTitle(remoteAet); | 66 connection_->SetRemoteModality(remote); |
68 connection_->SetRemoteHost(address); | |
69 connection_->SetRemotePort(port); | |
70 connection_->SetRemoteManufacturer(manufacturer); | |
71 connection_->Open(); | 67 connection_->Open(); |
72 } | 68 } |
73 | 69 |
74 void ReusableDicomUserConnection::Close() | 70 void ReusableDicomUserConnection::Close() |
75 { | 71 { |
101 } | 97 } |
102 } | 98 } |
103 } | 99 } |
104 } | 100 } |
105 | 101 |
106 ReusableDicomUserConnection::Locker::Locker(ReusableDicomUserConnection& that, | |
107 const std::string& aet, | |
108 const std::string& address, | |
109 int port, | |
110 ModalityManufacturer manufacturer) : | |
111 ::Orthanc::Locker(that) | |
112 { | |
113 that.Open(aet, address, port, manufacturer); | |
114 connection_ = that.connection_; | |
115 } | |
116 | |
117 | 102 |
118 ReusableDicomUserConnection::Locker::Locker(ReusableDicomUserConnection& that, | 103 ReusableDicomUserConnection::Locker::Locker(ReusableDicomUserConnection& that, |
104 const std::string& localAet, | |
119 const RemoteModalityParameters& remote) : | 105 const RemoteModalityParameters& remote) : |
120 ::Orthanc::Locker(that) | 106 ::Orthanc::Locker(that) |
121 { | 107 { |
122 that.Open(remote.GetApplicationEntityTitle(), remote.GetHost(), | 108 that.Open(localAet, remote); |
123 remote.GetPort(), remote.GetManufacturer()); | |
124 connection_ = that.connection_; | 109 connection_ = that.connection_; |
125 } | 110 } |
126 | 111 |
127 | 112 |
128 DicomUserConnection& ReusableDicomUserConnection::Locker::GetConnection() | 113 DicomUserConnection& ReusableDicomUserConnection::Locker::GetConnection() |
135 return *connection_; | 120 return *connection_; |
136 } | 121 } |
137 | 122 |
138 ReusableDicomUserConnection::ReusableDicomUserConnection() : | 123 ReusableDicomUserConnection::ReusableDicomUserConnection() : |
139 connection_(NULL), | 124 connection_(NULL), |
140 timeBeforeClose_(boost::posix_time::seconds(5)), // By default, close connection after 5 seconds | 125 timeBeforeClose_(boost::posix_time::seconds(5)) // By default, close connection after 5 seconds |
141 localAet_("ORTHANC") | |
142 { | 126 { |
143 lastUse_ = Now(); | 127 lastUse_ = Now(); |
144 continue_ = true; | 128 continue_ = true; |
145 closeThread_ = boost::thread(CloseThread, this); | 129 closeThread_ = boost::thread(CloseThread, this); |
146 } | 130 } |
162 } | 146 } |
163 | 147 |
164 timeBeforeClose_ = boost::posix_time::milliseconds(ms); | 148 timeBeforeClose_ = boost::posix_time::milliseconds(ms); |
165 } | 149 } |
166 | 150 |
167 void ReusableDicomUserConnection::SetLocalApplicationEntityTitle(const std::string& aet) | |
168 { | |
169 boost::mutex::scoped_lock lock(mutex_); | |
170 Close(); | |
171 localAet_ = aet; | |
172 } | |
173 | |
174 void ReusableDicomUserConnection::Lock() | 151 void ReusableDicomUserConnection::Lock() |
175 { | 152 { |
176 mutex_.lock(); | 153 mutex_.lock(); |
177 } | 154 } |
178 | 155 |