Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomNetworking/TimeoutDicomConnectionManager.cpp @ 4148:732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Aug 2020 16:56:33 +0200 |
parents | bf7b9edf6b81 |
children | 756126cd2219 |
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 | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
2603 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
2603 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
2603 | 20 **/ |
21 | |
22 | |
23 #include "../PrecompiledHeaders.h" | |
24 #include "TimeoutDicomConnectionManager.h" | |
25 | |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
26 #include "../Logging.h" |
2603 | 27 #include "../OrthancException.h" |
28 | |
29 namespace Orthanc | |
30 { | |
31 static boost::posix_time::ptime GetNow() | |
32 { | |
33 return boost::posix_time::microsec_clock::universal_time(); | |
34 } | |
35 | |
3850
d729d6e8b484
removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
36 |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
37 TimeoutDicomConnectionManager::Lock::Lock(TimeoutDicomConnectionManager& that, |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
38 const std::string& localAet, |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
39 const RemoteModalityParameters& remote) : |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
40 that_(that), |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
41 lock_(that_.mutex_) |
2603 | 42 { |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
43 // Calling "Touch()" will be done by the "~Lock()" destructor |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
44 that_.OpenInternal(localAet, remote); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
45 } |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
46 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
47 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
48 TimeoutDicomConnectionManager::Lock::~Lock() |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
49 { |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
50 that_.TouchInternal(); |
3850
d729d6e8b484
removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
51 } |
2603 | 52 |
3850
d729d6e8b484
removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
53 |
3863
9973d10bc5c4
switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
54 DicomStoreUserConnection& TimeoutDicomConnectionManager::Lock::GetConnection() |
3850
d729d6e8b484
removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
55 { |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
56 if (that_.connection_.get() == NULL) |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
57 { |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
58 // The allocation should have been done by "that_.Open()" in the constructor |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
59 throw OrthancException(ErrorCode_InternalError); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
60 } |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
61 else |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
62 { |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
63 return *that_.connection_; |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
64 } |
3850
d729d6e8b484
removing useless abstraction IDicomConnectionManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
65 } |
2603 | 66 |
67 | |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
68 // Mutex must be locked |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
69 void TimeoutDicomConnectionManager::TouchInternal() |
2603 | 70 { |
71 lastUse_ = GetNow(); | |
72 } | |
73 | |
74 | |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
75 // Mutex must be locked |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
76 void TimeoutDicomConnectionManager::OpenInternal(const std::string& localAet, |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
77 const RemoteModalityParameters& remote) |
2603 | 78 { |
3863
9973d10bc5c4
switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
79 DicomAssociationParameters other(localAet, remote); |
9973d10bc5c4
switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
80 |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
81 if (connection_.get() == NULL || |
3863
9973d10bc5c4
switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
82 !connection_->GetParameters().IsEqual(other)) |
2603 | 83 { |
3863
9973d10bc5c4
switch to DicomStoreUserConnection in Lua routing, C-MOVE handler and straight C-STORE
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
84 connection_.reset(new DicomStoreUserConnection(other)); |
2603 | 85 } |
86 } | |
87 | |
88 | |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
89 // Mutex must be locked |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
90 void TimeoutDicomConnectionManager::CloseInternal() |
2603 | 91 { |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
92 if (connection_.get() != NULL) |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
93 { |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
94 LOG(INFO) << "Closing inactive DICOM association with modality: " |
3875
ea1d32861cfc
moving timeout from DicomAssocation to DicomAssociationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3863
diff
changeset
|
95 << connection_->GetParameters().GetRemoteModality().GetApplicationEntityTitle(); |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
96 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
97 connection_.reset(NULL); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
98 } |
2603 | 99 } |
100 | |
101 | |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
102 void TimeoutDicomConnectionManager::SetInactivityTimeout(unsigned int milliseconds) |
2603 | 103 { |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
104 boost::mutex::scoped_lock lock(mutex_); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
105 timeout_ = boost::posix_time::milliseconds(milliseconds); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
106 CloseInternal(); |
2603 | 107 } |
108 | |
109 | |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
110 unsigned int TimeoutDicomConnectionManager::GetInactivityTimeout() |
2603 | 111 { |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
112 boost::mutex::scoped_lock lock(mutex_); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
113 return static_cast<unsigned int>(timeout_.total_milliseconds()); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
114 } |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
115 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
116 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
117 void TimeoutDicomConnectionManager::CloseIfInactive() |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
118 { |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
119 boost::mutex::scoped_lock lock(mutex_); |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
120 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
121 if (connection_.get() != NULL && |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
122 (GetNow() - lastUse_) >= timeout_) |
2603 | 123 { |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3850
diff
changeset
|
124 CloseInternal(); |
2603 | 125 } |
126 } | |
127 } |