Mercurial > hg > orthanc
comparison Core/DicomNetworking/TimeoutDicomConnectionManager.h @ 3851:6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 20 Apr 2020 16:46:44 +0200 |
parents | d729d6e8b484 |
children | 9973d10bc5c4 |
comparison
equal
deleted
inserted
replaced
3850:d729d6e8b484 | 3851:6498739a3c3c |
---|---|
35 | 35 |
36 #if !defined(ORTHANC_ENABLE_DCMTK_NETWORKING) | 36 #if !defined(ORTHANC_ENABLE_DCMTK_NETWORKING) |
37 # error The macro ORTHANC_ENABLE_DCMTK_NETWORKING must be defined | 37 # error The macro ORTHANC_ENABLE_DCMTK_NETWORKING must be defined |
38 #endif | 38 #endif |
39 | 39 |
40 #if ORTHANC_ENABLE_DCMTK_NETWORKING == 0 | 40 #if ORTHANC_ENABLE_DCMTK_NETWORKING != 1 |
41 # error The macro ORTHANC_ENABLE_DCMTK_NETWORKING must be 1 to use this file | |
42 #endif | |
41 | 43 |
42 namespace Orthanc | |
43 { | |
44 class TimeoutDicomConnectionManager : public boost::noncopyable | |
45 { | |
46 public: | |
47 void SetTimeout(unsigned int timeout) | |
48 { | |
49 } | |
50 | |
51 unsigned int GetTimeout() | |
52 { | |
53 return 0; | |
54 } | |
55 | |
56 void Close() | |
57 { | |
58 } | |
59 | |
60 void CheckTimeout() | |
61 { | |
62 } | |
63 }; | |
64 } | |
65 | |
66 #else | |
67 | 44 |
68 #include "../Compatibility.h" | 45 #include "../Compatibility.h" |
69 #include "DicomUserConnection.h" | 46 #include "DicomUserConnection.h" |
70 | 47 |
71 #include <boost/date_time/posix_time/posix_time.hpp> | 48 #include <boost/date_time/posix_time/posix_time.hpp> |
49 #include <boost/thread/mutex.hpp> | |
72 | 50 |
73 namespace Orthanc | 51 namespace Orthanc |
74 { | 52 { |
53 /** | |
54 * This class corresponds to a singleton to a DICOM SCU connection. | |
55 **/ | |
75 class TimeoutDicomConnectionManager : public boost::noncopyable | 56 class TimeoutDicomConnectionManager : public boost::noncopyable |
76 { | 57 { |
77 private: | 58 private: |
59 boost::mutex mutex_; | |
78 std::unique_ptr<DicomUserConnection> connection_; | 60 std::unique_ptr<DicomUserConnection> connection_; |
79 boost::posix_time::ptime lastUse_; | 61 boost::posix_time::ptime lastUse_; |
80 boost::posix_time::time_duration timeout_; | 62 boost::posix_time::time_duration timeout_; |
81 | 63 |
82 void Touch(); | 64 // Mutex must be locked |
65 void TouchInternal(); | |
83 | 66 |
84 void CheckTimeoutInternal(); | 67 // Mutex must be locked |
68 void OpenInternal(const std::string& localAet, | |
69 const RemoteModalityParameters& remote); | |
70 | |
71 // Mutex must be locked | |
72 void CloseInternal(); | |
85 | 73 |
86 public: | 74 public: |
87 class Resource : public boost::noncopyable | 75 class Lock : public boost::noncopyable |
88 { | 76 { |
89 private: | 77 private: |
90 TimeoutDicomConnectionManager& that_; | 78 TimeoutDicomConnectionManager& that_; |
79 boost::mutex::scoped_lock lock_; | |
91 | 80 |
92 public: | 81 public: |
93 Resource(TimeoutDicomConnectionManager& that); | 82 Lock(TimeoutDicomConnectionManager& that, |
83 const std::string& localAet, | |
84 const RemoteModalityParameters& remote); | |
94 | 85 |
95 ~Resource(); | 86 ~Lock(); |
96 | 87 |
97 DicomUserConnection& GetConnection(); | 88 DicomUserConnection& GetConnection(); |
98 }; | 89 }; |
99 | 90 |
100 TimeoutDicomConnectionManager() : | 91 TimeoutDicomConnectionManager() : |
101 timeout_(boost::posix_time::milliseconds(1000)) | 92 timeout_(boost::posix_time::milliseconds(1000)) |
102 { | 93 { |
103 } | 94 } |
104 | 95 |
105 void SetTimeout(unsigned int timeout); | 96 void SetInactivityTimeout(unsigned int milliseconds); |
106 | 97 |
107 unsigned int GetTimeout(); | 98 unsigned int GetInactivityTimeout(); // In milliseconds |
108 | 99 |
109 void Close(); | 100 void Close(); |
110 | 101 |
111 void CheckTimeout(); | 102 void CloseIfInactive(); |
112 | |
113 Resource* AcquireConnection(const std::string& localAet, | |
114 const RemoteModalityParameters& remote); | |
115 }; | 103 }; |
116 } | 104 } |
117 | |
118 #endif |