Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Cache/SharedArchive.cpp @ 4596:2b64cc3cea99
added OrthancPluginContentType_DicomUntilPixelData
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 17 Mar 2021 15:31:26 +0100 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
rev | line source |
---|---|
1367 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1367 | 4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1367 | 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. |
1367 | 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. |
1367 | 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/>. |
1367 | 20 **/ |
21 | |
22 | |
23 #include "../PrecompiledHeaders.h" | |
24 #include "SharedArchive.h" | |
25 | |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
26 #include "../Toolbox.h" |
2172
84d1d392a9ab
GenerateUuid() not available in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
27 |
1367 | 28 |
29 namespace Orthanc | |
30 { | |
31 void SharedArchive::RemoveInternal(const std::string& id) | |
32 { | |
33 Archive::iterator it = archive_.find(id); | |
34 | |
35 if (it != archive_.end()) | |
36 { | |
37 delete it->second; | |
38 archive_.erase(it); | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
39 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
40 lru_.Invalidate(id); |
1367 | 41 } |
42 } | |
43 | |
44 | |
45 SharedArchive::Accessor::Accessor(SharedArchive& that, | |
46 const std::string& id) : | |
47 lock_(that.mutex_) | |
48 { | |
49 Archive::iterator it = that.archive_.find(id); | |
50 | |
51 if (it == that.archive_.end()) | |
52 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
53 item_ = NULL; |
1367 | 54 } |
55 else | |
56 { | |
57 that.lru_.MakeMostRecent(id); | |
58 item_ = it->second; | |
59 } | |
60 } | |
61 | |
4300 | 62 bool SharedArchive::Accessor::IsValid() const |
63 { | |
64 return item_ != NULL; | |
65 } | |
66 | |
1367 | 67 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
68 IDynamicObject& SharedArchive::Accessor::GetItem() const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
69 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
70 if (item_ == NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
71 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
72 // "IsValid()" should have been called |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
73 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
74 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
75 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
76 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
77 return *item_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
78 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
79 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
80 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
81 |
1368 | 82 SharedArchive::SharedArchive(size_t maxSize) : |
83 maxSize_(maxSize) | |
84 { | |
85 if (maxSize == 0) | |
86 { | |
87 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
88 } | |
89 } | |
90 | |
91 | |
1367 | 92 SharedArchive::~SharedArchive() |
93 { | |
94 for (Archive::iterator it = archive_.begin(); | |
1386 | 95 it != archive_.end(); ++it) |
1367 | 96 { |
97 delete it->second; | |
98 } | |
99 } | |
100 | |
101 | |
102 std::string SharedArchive::Add(IDynamicObject* obj) | |
103 { | |
104 boost::mutex::scoped_lock lock(mutex_); | |
105 | |
106 if (archive_.size() == maxSize_) | |
107 { | |
108 // The quota has been reached, remove the oldest element | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
109 RemoveInternal(lru_.GetOldest()); |
1367 | 110 } |
111 | |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
112 std::string id = Toolbox::GenerateUuid(); |
1367 | 113 RemoveInternal(id); // Should never be useful because of UUID |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
114 |
1367 | 115 archive_[id] = obj; |
116 lru_.Add(id); | |
117 | |
118 return id; | |
119 } | |
120 | |
121 | |
122 void SharedArchive::Remove(const std::string& id) | |
123 { | |
124 boost::mutex::scoped_lock lock(mutex_); | |
125 RemoveInternal(id); | |
126 } | |
127 | |
128 | |
129 void SharedArchive::List(std::list<std::string>& items) | |
130 { | |
131 items.clear(); | |
132 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
133 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
134 boost::mutex::scoped_lock lock(mutex_); |
1367 | 135 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
136 for (Archive::const_iterator it = archive_.begin(); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
137 it != archive_.end(); ++it) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
138 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
139 items.push_back(it->first); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
140 } |
1367 | 141 } |
142 } | |
143 } |