Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 4824:6e0305c9ed41 storage-cache
closing branch storage-cache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Nov 2021 13:26:02 +0100 |
parents | 434843934307 |
children | 7053502fbf97 |
rev | line source |
---|---|
221 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
221 | 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. |
221 | 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. |
221 | 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/>. |
221 | 20 **/ |
21 | |
22 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
221 | 24 #include "StorageAccessor.h" |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
25 #include "StorageCache.h" |
221 | 26 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
27 #include "../Logging.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
28 #include "../StringMemoryBuffer.h" |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
29 #include "../Compatibility.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
30 #include "../Compression/ZlibCompressor.h" |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
31 #include "../MetricsRegistry.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
32 #include "../OrthancException.h" |
2142 | 33 #include "../Toolbox.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
34 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
35 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
36 # include "../HttpServer/HttpStreamTranscoder.h" |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
37 #endif |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
38 |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
39 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
40 static const std::string METRICS_CREATE = "orthanc_storage_create_duration_ms"; |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
41 static const std::string METRICS_READ = "orthanc_storage_read_duration_ms"; |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
42 static const std::string METRICS_REMOVE = "orthanc_storage_remove_duration_ms"; |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
43 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
44 |
221 | 45 namespace Orthanc |
46 { | |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
47 class StorageAccessor::MetricsTimer : public boost::noncopyable |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
48 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
49 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
50 std::unique_ptr<MetricsRegistry::Timer> timer_; |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
51 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
52 public: |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
53 MetricsTimer(StorageAccessor& that, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
54 const std::string& name) |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
55 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
56 if (that.metrics_ != NULL) |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
57 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
58 timer_.reset(new MetricsRegistry::Timer(*that.metrics_, name)); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
59 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
60 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
61 }; |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
62 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
63 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
64 StorageAccessor::StorageAccessor(IStorageArea &area, StorageCache& cache) : |
4297 | 65 area_(area), |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
66 cache_(cache), |
4297 | 67 metrics_(NULL) |
68 { | |
69 } | |
70 | |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
71 StorageAccessor::StorageAccessor(IStorageArea &area, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
72 StorageCache& cache, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
73 MetricsRegistry &metrics) : |
4297 | 74 area_(area), |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
75 cache_(cache), |
4297 | 76 metrics_(&metrics) |
77 { | |
78 } | |
79 | |
80 | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
81 FileInfo StorageAccessor::Write(const void* data, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
82 size_t size, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
83 FileContentType type, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
84 CompressionType compression, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
85 bool storeMd5) |
221 | 86 { |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
87 std::string uuid = Toolbox::GenerateUuid(); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
88 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
89 std::string md5; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
90 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
91 if (storeMd5) |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
92 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
93 Toolbox::ComputeMD5(md5, data, size); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
94 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
95 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
96 switch (compression) |
221 | 97 { |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
98 case CompressionType_None: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
99 { |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
100 MetricsTimer timer(*this, METRICS_CREATE); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
101 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
102 area_.Create(uuid, data, size, type); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
103 cache_.Add(uuid, type, data, size); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
104 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
105 return FileInfo(uuid, type, size, md5); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
106 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
107 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
108 case CompressionType_ZlibWithSize: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
109 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
110 ZlibCompressor zlib; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
111 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
112 std::string compressed; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
113 zlib.Compress(compressed, data, size); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
114 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
115 std::string compressedMD5; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
116 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
117 if (storeMd5) |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
118 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
119 Toolbox::ComputeMD5(compressedMD5, compressed); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
120 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
121 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
122 { |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
123 MetricsTimer timer(*this, METRICS_CREATE); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
124 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
125 if (compressed.size() > 0) |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
126 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
127 area_.Create(uuid, &compressed[0], compressed.size(), type); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
128 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
129 else |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
130 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
131 area_.Create(uuid, NULL, 0, type); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
132 } |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
133 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
134 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
135 cache_.Add(uuid, type, data, size); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
136 return FileInfo(uuid, type, size, md5, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
137 CompressionType_ZlibWithSize, compressed.size(), compressedMD5); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
138 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
139 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
140 default: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
141 throw OrthancException(ErrorCode_NotImplemented); |
221 | 142 } |
143 } | |
144 | |
4297 | 145 FileInfo StorageAccessor::Write(const std::string &data, |
146 FileContentType type, | |
147 CompressionType compression, | |
148 bool storeMd5) | |
149 { | |
150 return Write((data.size() == 0 ? NULL : data.c_str()), | |
151 data.size(), type, compression, storeMd5); | |
152 } | |
153 | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
154 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
155 void StorageAccessor::Read(std::string& content, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
156 const FileInfo& info) |
221 | 157 { |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
158 if (cache_.Fetch(content, info.GetUuid(), info.GetContentType())) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
159 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
160 LOG(INFO) << "Read attachment \"" << info.GetUuid() << "\" " |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
161 << "content type from cache"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
162 return; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
163 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
164 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
165 switch (info.GetCompressionType()) |
221 | 166 { |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
167 case CompressionType_None: |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
168 { |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
169 MetricsTimer timer(*this, METRICS_READ); |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
170 |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
171 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
172 buffer->MoveToString(content); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
173 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
174 cache_.Add(info.GetUuid(), info.GetContentType(), content); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
175 break; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
176 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
177 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
178 case CompressionType_ZlibWithSize: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
179 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
180 ZlibCompressor zlib; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
181 |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
182 std::unique_ptr<IMemoryBuffer> compressed; |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
183 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
184 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
185 MetricsTimer timer(*this, METRICS_READ); |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
186 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType())); |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
187 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
188 |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
189 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize()); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
190 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
191 cache_.Add(info.GetUuid(), info.GetContentType(), content); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
192 break; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
193 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
194 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
195 default: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
196 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
197 throw OrthancException(ErrorCode_NotImplemented); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
198 } |
221 | 199 } |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
200 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
201 // TODO Check the validity of the uncompressed MD5? |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
202 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
203 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
204 |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
205 void StorageAccessor::ReadRaw(std::string& content, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
206 const FileInfo& info) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
207 { |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
208 MetricsTimer timer(*this, METRICS_READ); |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
209 |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
210 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
211 buffer->MoveToString(content); |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
212 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
213 |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
214 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
215 void StorageAccessor::Remove(const std::string& fileUuid, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
216 FileContentType type) |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
217 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
218 MetricsTimer timer(*this, METRICS_REMOVE); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
219 area_.Remove(fileUuid, type); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
220 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
221 cache_.Invalidate(fileUuid, type); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
222 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
223 // in ReadStartRange, we might have cached only the start of the file -> try to remove it |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
224 if (type == FileContentType_Dicom) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
225 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
226 cache_.Invalidate(fileUuid, FileContentType_DicomUntilPixelData); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
227 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
228 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
229 |
4297 | 230 void StorageAccessor::Remove(const FileInfo &info) |
231 { | |
232 Remove(info.GetUuid(), info.GetContentType()); | |
233 } | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
234 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
235 IMemoryBuffer* StorageAccessor::ReadStartRange(const std::string& fileUuid, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
236 FileContentType contentType, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
237 uint64_t end /* exclusive */, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
238 FileContentType startFileContentType) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
239 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
240 std::string content; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
241 if (cache_.Fetch(content, fileUuid, contentType)) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
242 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
243 LOG(INFO) << "Read attachment \"" << fileUuid << "\" " |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
244 << "(range from " << 0 << " to " << end << ") from cache"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
245 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
246 return StringMemoryBuffer::CreateFromCopy(content, 0, end); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
247 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
248 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
249 if (cache_.Fetch(content, fileUuid, startFileContentType)) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
250 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
251 LOG(INFO) << "Read attachment \"" << fileUuid << "\" " |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
252 << "(range from " << 0 << " to " << end << ") from cache"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
253 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
254 assert(content.size() == end); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
255 return StringMemoryBuffer::CreateFromCopy(content); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
256 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
257 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
258 std::unique_ptr<IMemoryBuffer> buffer(area_.ReadRange(fileUuid, contentType, 0, end)); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
259 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
260 // we've read only the first part of the file -> add an entry in the cache |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
261 // note the uuid is still the uuid of the full file but the type is the type of the start of the file ! |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
262 assert(buffer->GetSize() == end); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
263 cache_.Add(fileUuid, startFileContentType, buffer->GetData(), buffer->GetSize()); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
264 return buffer.release(); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
265 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
266 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
267 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
268 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
269 void StorageAccessor::SetupSender(BufferHttpSender& sender, |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
270 const FileInfo& info, |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
271 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
272 { |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
273 if (cache_.Fetch(sender.GetBuffer(), info.GetUuid(), info.GetContentType())) |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
274 { |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
275 LOG(INFO) << "Read attachment \"" << info.GetUuid() << "\" " |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
276 << "content type from cache"; |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
277 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
278 else |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
279 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
280 MetricsTimer timer(*this, METRICS_READ); |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
281 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
282 buffer->MoveToString(sender.GetBuffer()); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
283 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
284 cache_.Add(info.GetUuid(), info.GetContentType(), sender.GetBuffer()); |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
285 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
286 |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
287 sender.SetContentType(mime); |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
288 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
289 const char* extension; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
290 switch (info.GetContentType()) |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
291 { |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
292 case FileContentType_Dicom: |
4512
cff7fdfc83a4
added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4484
diff
changeset
|
293 case FileContentType_DicomUntilPixelData: |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
294 extension = ".dcm"; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
295 break; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
296 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
297 case FileContentType_DicomAsJson: |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
298 extension = ".json"; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
299 break; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
300 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
301 default: |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
302 // Non-standard content type |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
303 extension = ""; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
304 } |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
305 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
306 sender.SetContentFilename(info.GetUuid() + std::string(extension)); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
307 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
308 #endif |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
309 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
310 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
311 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
312 void StorageAccessor::AnswerFile(HttpOutput& output, |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
313 const FileInfo& info, |
4297 | 314 MimeType mime) |
315 { | |
316 AnswerFile(output, info, EnumerationToString(mime)); | |
317 } | |
318 #endif | |
319 | |
320 | |
321 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
322 void StorageAccessor::AnswerFile(HttpOutput& output, | |
323 const FileInfo& info, | |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
324 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
325 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
326 BufferHttpSender sender; |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
327 SetupSender(sender, info, mime); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
328 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
329 HttpStreamTranscoder transcoder(sender, info.GetCompressionType()); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
330 output.Answer(transcoder); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
331 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
332 #endif |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
333 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
334 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
335 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
336 void StorageAccessor::AnswerFile(RestApiOutput& output, |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
337 const FileInfo& info, |
4297 | 338 MimeType mime) |
339 { | |
340 AnswerFile(output, info, EnumerationToString(mime)); | |
341 } | |
342 #endif | |
343 | |
344 | |
345 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
346 void StorageAccessor::AnswerFile(RestApiOutput& output, | |
347 const FileInfo& info, | |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
348 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
349 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
350 BufferHttpSender sender; |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
351 SetupSender(sender, info, mime); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
352 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
353 HttpStreamTranscoder transcoder(sender, info.GetCompressionType()); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
354 output.AnswerStream(transcoder); |
221 | 355 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
356 #endif |
221 | 357 } |