Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/ParsedDicomCache.cpp @ 4706:dbee8bd8ee1f
display OpenSSL version in the logs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Jun 2021 09:13:03 +0200 |
parents | fa2311f94d9f |
children | 7053502fbf97 |
rev | line source |
---|---|
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * License along with this program. If not, see |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "ParsedDicomCache.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "../OrthancException.h" |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 namespace Orthanc |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 class ParsedDicomCache::Item : public ICacheable |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 private: |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 std::unique_ptr<ParsedDicomFile> dicom_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 size_t fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 public: |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 Item(ParsedDicomFile* dicom, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 size_t fileSize) : |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 dicom_(dicom), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 fileSize_(fileSize) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 if (dicom == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 throw OrthancException(ErrorCode_NullPointer); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 virtual size_t GetMemoryUsage() const ORTHANC_OVERRIDE |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 return fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 ParsedDicomFile& GetDicom() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 assert(dicom_.get() != NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 return *dicom_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 }; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 ParsedDicomCache::ParsedDicomCache(size_t size) : |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 cacheSize_(size), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 largeSize_(0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 if (size == 0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 throw OrthancException(ErrorCode_ParameterOutOfRange); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
72 size_t ParsedDicomCache::GetNumberOfItems() |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
73 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
74 #if !defined(__EMSCRIPTEN__) |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
75 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
76 #endif |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
77 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
78 if (cache_.get() == NULL) |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
79 { |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
80 return (largeDicom_.get() == NULL ? 0 : 1); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
81 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
82 else |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
83 { |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
84 assert(largeDicom_.get() == NULL); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
85 assert(largeSize_ == 0); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
86 return cache_->GetNumberOfItems(); |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
87 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
88 } |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
89 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
90 |
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
91 size_t ParsedDicomCache::GetCurrentSize() |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
93 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
95 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 if (cache_.get() == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 return largeSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 { |
4457
789676a8c96a
Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4456
diff
changeset
|
103 assert(largeDicom_.get() == NULL); |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 assert(largeSize_ == 0); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 return cache_->GetCurrentSize(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 void ParsedDicomCache::Invalidate(const std::string& id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
112 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
114 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 if (cache_.get() != NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 cache_->Invalidate(id); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 if (largeId_ == id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 largeDicom_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 largeSize_ = 0; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 void ParsedDicomCache::Acquire(const std::string& id, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 ParsedDicomFile* dicom, // Takes ownership |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 size_t fileSize) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 { |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
133 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 boost::mutex::scoped_lock lock(mutex_); |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
135 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 if (fileSize >= cacheSize_) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 cache_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 largeDicom_.reset(dicom); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 largeId_ = id; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 largeSize_ = fileSize; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 largeDicom_.reset(NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 largeSize_ = 0; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 if (cache_.get() == NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 cache_.reset(new MemoryObjectCache); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 cache_->SetMaximumSize(cacheSize_); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 cache_->Acquire(id, new Item(dicom, fileSize)); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 ParsedDicomCache::Accessor::Accessor(ParsedDicomCache& that, |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 const std::string& id) : |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
162 #if !defined(__EMSCRIPTEN__) |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 lock_(that.mutex_), |
4458
e4dae17035b9
fix ParsedDicomCache for emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4457
diff
changeset
|
164 #endif |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 id_(id), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 file_(NULL), |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 fileSize_(0) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 if (that.largeDicom_.get() != NULL && |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 that.largeId_ == id) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 file_ = that.largeDicom_.get(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 fileSize_ = that.largeSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 else if (that.cache_.get() != NULL) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 accessor_.reset(new MemoryObjectCache::Accessor( |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 *that.cache_, id, true /* unique */)); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 if (accessor_->IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 const Item& item = dynamic_cast<const Item&>(accessor_->GetValue()); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 file_ = &item.GetDicom(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 fileSize_ = item.GetMemoryUsage(); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
4495
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
189 bool ParsedDicomCache::Accessor::IsValid() const |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
190 { |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
191 return file_ != NULL; |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
192 } |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
193 |
fa2311f94d9f
IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4458
diff
changeset
|
194 |
4456
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 ParsedDicomFile& ParsedDicomCache::Accessor::GetDicom() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 if (IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 assert(file_ != NULL); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 return *file_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 size_t ParsedDicomCache::Accessor::GetFileSize() const |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 if (IsValid()) |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 return fileSize_; |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 else |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 { |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 } |
3e4f7b7840f0
new class: ParsedDicomCache()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 } |