Mercurial > hg > orthanc
annotate Core/DicomNetworking/TimeoutDicomConnectionManager.cpp @ 3803:e9834343d327
upgrade to openssl 1.1.1f
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 Apr 2020 13:25:48 +0200 |
parents | 94f4a18a79cc |
children | d729d6e8b484 |
rev | line source |
---|---|
2603 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3128
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2603 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "TimeoutDicomConnectionManager.h" | |
36 | |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
37 #include "../Logging.h" |
2603 | 38 #include "../OrthancException.h" |
39 | |
40 namespace Orthanc | |
41 { | |
42 static boost::posix_time::ptime GetNow() | |
43 { | |
44 return boost::posix_time::microsec_clock::universal_time(); | |
45 } | |
46 | |
47 class TimeoutDicomConnectionManager::Resource : public IDicomConnectionManager::IResource | |
48 { | |
49 private: | |
50 TimeoutDicomConnectionManager& that_; | |
51 | |
52 public: | |
53 Resource(TimeoutDicomConnectionManager& that) : | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
54 that_(that) |
2603 | 55 { |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
56 if (that_.connection_.get() == NULL) |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
57 { |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
58 throw OrthancException(ErrorCode_InternalError); |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
59 } |
2603 | 60 } |
61 | |
62 ~Resource() | |
63 { | |
64 that_.Touch(); | |
65 } | |
66 | |
67 DicomUserConnection& GetConnection() | |
68 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
69 assert(that_.connection_.get() != NULL); |
2603 | 70 return *that_.connection_; |
71 } | |
72 }; | |
73 | |
74 | |
75 void TimeoutDicomConnectionManager::Touch() | |
76 { | |
77 lastUse_ = GetNow(); | |
78 } | |
79 | |
80 | |
81 void TimeoutDicomConnectionManager::CheckTimeoutInternal() | |
82 { | |
83 if (connection_.get() != NULL && | |
84 (GetNow() - lastUse_) >= timeout_) | |
85 { | |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
86 Close(); |
2603 | 87 } |
88 } | |
89 | |
90 | |
91 void TimeoutDicomConnectionManager::SetTimeout(unsigned int timeout) | |
92 { | |
93 timeout_ = boost::posix_time::milliseconds(timeout); | |
94 CheckTimeoutInternal(); | |
95 } | |
96 | |
97 | |
98 unsigned int TimeoutDicomConnectionManager::GetTimeout() | |
99 { | |
3128
972cc98959a3
fix build of civetweb for Visual Studio 2008 and LSB
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
100 return static_cast<unsigned int>(timeout_.total_milliseconds()); |
2603 | 101 } |
102 | |
103 | |
104 void TimeoutDicomConnectionManager::Close() | |
105 { | |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
106 if (connection_.get() != NULL) |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
107 { |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
108 LOG(INFO) << "Closing inactive DICOM association with modality: " |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
109 << connection_->GetRemoteApplicationEntityTitle(); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
110 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
111 connection_.reset(NULL); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
112 } |
2603 | 113 } |
114 | |
115 | |
116 void TimeoutDicomConnectionManager::CheckTimeout() | |
117 { | |
118 CheckTimeoutInternal(); | |
119 } | |
120 | |
121 | |
122 IDicomConnectionManager::IResource* | |
123 TimeoutDicomConnectionManager::AcquireConnection(const std::string& localAet, | |
124 const RemoteModalityParameters& remote) | |
125 { | |
126 if (connection_.get() == NULL || | |
127 !connection_->IsSameAssociation(localAet, remote)) | |
128 { | |
129 connection_.reset(new DicomUserConnection(localAet, remote)); | |
130 } | |
131 | |
132 return new Resource(*this); | |
133 } | |
134 } |