annotate OrthancServer/DicomProtocol/ReusableDicomUserConnection.cpp @ 2213:95d1d758abb7

FindMatcher::IsMatch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 10 Dec 2016 10:17:44 +0100
parents b1291df2f780
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1285
diff changeset
4 * Department, University Hospital of Liege, Belgium
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "../PrecompiledHeadersServer.h"
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ReusableDicomUserConnection.h"
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1453
diff changeset
36 #include "../../Core/Logging.h"
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/OrthancException.h"
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 static boost::posix_time::ptime Now()
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 return boost::posix_time::microsec_clock::local_time();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
46 void ReusableDicomUserConnection::Open(const std::string& localAet,
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
47 const RemoteModalityParameters& remote)
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if (connection_ != NULL &&
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
50 connection_->GetLocalApplicationEntityTitle() == localAet &&
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
51 connection_->GetRemoteApplicationEntityTitle() == remote.GetApplicationEntityTitle() &&
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
52 connection_->GetRemoteHost() == remote.GetHost() &&
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
53 connection_->GetRemotePort() == remote.GetPort() &&
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
54 connection_->GetRemoteManufacturer() == remote.GetManufacturer())
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 // The current connection can be reused
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 772
diff changeset
57 LOG(INFO) << "Reusing the previous SCU connection";
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 Close();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 connection_ = new DicomUserConnection();
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
64 connection_->SetLocalApplicationEntityTitle(localAet);
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
65 connection_->SetRemoteModality(remote);
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 connection_->Open();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 void ReusableDicomUserConnection::Close()
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if (connection_ != NULL)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 delete connection_;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 connection_ = NULL;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 void ReusableDicomUserConnection::CloseThread(ReusableDicomUserConnection* that)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 for (;;)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (!that->continue_)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
774
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
85 //LOG(INFO) << "Finishing the thread watching the global SCU connection";
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 boost::mutex::scoped_lock lock(that->mutex_);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if (that->connection_ != NULL &&
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 772
diff changeset
92 Now() >= that->lastUse_ + that->timeBeforeClose_)
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 LOG(INFO) << "Closing the global SCU connection after timeout";
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 that->Close();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
772
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
101
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
102 ReusableDicomUserConnection::Locker::Locker(ReusableDicomUserConnection& that,
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
103 const std::string& localAet,
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
104 const RemoteModalityParameters& remote) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
105 ::Orthanc::Locker(that)
772
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
106 {
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
107 that.Open(localAet, remote);
772
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
108 connection_ = that.connection_;
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
109 }
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
110
31cc399c7762 RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
111
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
112 DicomUserConnection& ReusableDicomUserConnection::Locker::GetConnection()
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (connection_ == NULL)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 throw OrthancException(ErrorCode_InternalError);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 return *connection_;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ReusableDicomUserConnection::ReusableDicomUserConnection() :
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 connection_(NULL),
1427
d710ea64f0fd Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
124 timeBeforeClose_(boost::posix_time::seconds(5)) // By default, close connection after 5 seconds
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 lastUse_ = Now();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 continue_ = true;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 closeThread_ = boost::thread(CloseThread, this);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ReusableDicomUserConnection::~ReusableDicomUserConnection()
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
133 if (continue_)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
134 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
135 LOG(ERROR) << "INTERNAL ERROR: ReusableDicomUserConnection::Finalize() should be invoked manually to avoid mess in the destruction order!";
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
136 Finalize();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
137 }
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
1284
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
140 void ReusableDicomUserConnection::SetMillisecondsBeforeClose(uint64_t ms)
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 boost::mutex::scoped_lock lock(mutex_);
1284
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
143
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
144 if (ms == 0)
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
145 {
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
146 ms = 1;
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
147 }
21ea32170764 Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1017
diff changeset
148
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 timeBeforeClose_ = boost::posix_time::milliseconds(ms);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 void ReusableDicomUserConnection::Lock()
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 mutex_.lock();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 void ReusableDicomUserConnection::Unlock()
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
1017
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
159 if (connection_ != NULL &&
1285
5730f374e4e6 Access to called AET and remote AET from Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1284
diff changeset
160 connection_->GetRemoteManufacturer() == ModalityManufacturer_StoreScp)
1017
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
161 {
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
162 // "storescp" from DCMTK has problems when reusing a
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
163 // connection. Always close.
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
164 Close();
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
165 }
9d0c7301596e storescp modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
166
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 lastUse_ = Now();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 mutex_.unlock();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
170
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
171
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
172 void ReusableDicomUserConnection::Finalize()
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
173 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
174 if (continue_)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
175 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
176 continue_ = false;
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
177
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
178 if (closeThread_.joinable())
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
179 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
180 closeThread_.join();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
181 }
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
182
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
183 Close();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
184 }
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
185 }
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187