Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5398:08b5516c6e5e
compatibility of OrthancFramework with latest releases of Emscripten
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Oct 2023 15:26:45 +0200 |
parents | b376abae664a |
children | aaf7c49a9ddc d37dff2c0028 |
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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5184
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5184
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
221 | 7 * |
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
221 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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
|
16 * Lesser General Public License for more details. |
221 | 17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
221 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
221 | 25 #include "StorageAccessor.h" |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
26 #include "StorageCache.h" |
221 | 27 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
28 #include "../Logging.h" |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
29 #include "../StringMemoryBuffer.h" |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
30 #include "../Compatibility.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
31 #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
|
32 #include "../MetricsRegistry.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
33 #include "../OrthancException.h" |
2142 | 34 #include "../Toolbox.h" |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
35 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
36 #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
|
37 # include "../HttpServer/HttpStreamTranscoder.h" |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
38 #endif |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
39 |
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
|
40 |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
41 static const std::string METRICS_CREATE_DURATION = "orthanc_storage_create_duration_ms"; |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
42 static const std::string METRICS_READ_DURATION = "orthanc_storage_read_duration_ms"; |
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
43 static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms"; |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
44 static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes"; |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
45 static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes"; |
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
|
46 |
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 |
221 | 48 namespace Orthanc |
49 { | |
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
|
50 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
|
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 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
53 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
|
54 |
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 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
|
56 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
|
57 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
|
58 { |
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 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
|
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 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
|
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 } |
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
|
64 }; |
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
|
65 |
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
|
66 |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
67 StorageAccessor::StorageAccessor(IStorageArea& area) : |
4297 | 68 area_(area), |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
69 cache_(NULL), |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
70 metrics_(NULL) |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
71 { |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
72 } |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
73 |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
74 |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
75 StorageAccessor::StorageAccessor(IStorageArea& area, |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
76 StorageCache& cache) : |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
77 area_(area), |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
78 cache_(&cache), |
4297 | 79 metrics_(NULL) |
80 { | |
81 } | |
82 | |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
83 |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
84 StorageAccessor::StorageAccessor(IStorageArea& area, |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
85 MetricsRegistry& metrics) : |
4297 | 86 area_(area), |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
87 cache_(NULL), |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
88 metrics_(&metrics) |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
89 { |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
90 } |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
91 |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
92 StorageAccessor::StorageAccessor(IStorageArea& area, |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
93 StorageCache& cache, |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
94 MetricsRegistry& metrics) : |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
95 area_(area), |
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5059
diff
changeset
|
96 cache_(&cache), |
4297 | 97 metrics_(&metrics) |
98 { | |
99 } | |
100 | |
101 | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
102 FileInfo StorageAccessor::Write(const void* data, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
103 size_t size, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
104 FileContentType type, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
105 CompressionType compression, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
106 bool storeMd5) |
221 | 107 { |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
108 std::string uuid = Toolbox::GenerateUuid(); |
1549
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 std::string md5; |
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 if (storeMd5) |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
113 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
114 Toolbox::ComputeMD5(md5, data, size); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
115 } |
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 switch (compression) |
221 | 118 { |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
119 case CompressionType_None: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
120 { |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
121 { |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
122 MetricsTimer timer(*this, METRICS_CREATE_DURATION); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
123 area_.Create(uuid, data, size, type); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
124 } |
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
|
125 |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
126 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
127 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
128 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, size); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
129 } |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
130 |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
131 if (cache_ != NULL) |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
132 { |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
133 cache_->Add(uuid, type, data, size); |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
134 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
135 |
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 } |
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 case CompressionType_ZlibWithSize: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
140 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
141 ZlibCompressor zlib; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
142 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
143 std::string compressed; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
144 zlib.Compress(compressed, data, size); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
145 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
146 std::string compressedMD5; |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
147 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
148 if (storeMd5) |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
149 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
150 Toolbox::ComputeMD5(compressedMD5, compressed); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
151 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
152 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
153 { |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
154 MetricsTimer timer(*this, METRICS_CREATE_DURATION); |
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
|
155 |
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
|
156 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
|
157 { |
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
|
158 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
|
159 } |
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
|
160 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
|
161 { |
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
|
162 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
|
163 } |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
164 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
165 |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
166 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
167 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
168 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, compressed.size()); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
169 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
170 |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
171 if (cache_ != NULL) |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
172 { |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
173 cache_->Add(uuid, type, data, size); // always add uncompressed data to cache |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
174 } |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
175 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
176 return FileInfo(uuid, type, size, md5, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
177 CompressionType_ZlibWithSize, compressed.size(), compressedMD5); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
178 } |
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 default: |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
181 throw OrthancException(ErrorCode_NotImplemented); |
221 | 182 } |
183 } | |
184 | |
4297 | 185 FileInfo StorageAccessor::Write(const std::string &data, |
186 FileContentType type, | |
187 CompressionType compression, | |
188 bool storeMd5) | |
189 { | |
190 return Write((data.size() == 0 ? NULL : data.c_str()), | |
191 data.size(), type, compression, storeMd5); | |
192 } | |
193 | |
1549
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 void StorageAccessor::Read(std::string& content, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
196 const FileInfo& info) |
221 | 197 { |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
198 if (cache_ == NULL || |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
199 !cache_->Fetch(content, info.GetUuid(), info.GetContentType())) |
221 | 200 { |
5046 | 201 switch (info.GetCompressionType()) |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
202 { |
5046 | 203 case CompressionType_None: |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
204 { |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
205 std::unique_ptr<IMemoryBuffer> buffer; |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
206 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
207 { |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
208 MetricsTimer timer(*this, METRICS_READ_DURATION); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
209 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType())); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
210 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
211 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
212 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
213 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
214 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
215 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
216 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
217 buffer->MoveToString(content); |
5046 | 218 |
219 break; | |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
220 } |
4484
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
221 |
5046 | 222 case CompressionType_ZlibWithSize: |
223 { | |
224 ZlibCompressor zlib; | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
225 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
226 std::unique_ptr<IMemoryBuffer> compressed; |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
227 |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
228 { |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
229 MetricsTimer timer(*this, METRICS_READ_DURATION); |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
230 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType())); |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
231 } |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
232 |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
233 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
234 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
235 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, compressed->GetSize()); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
236 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
237 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
238 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize()); |
5046 | 239 |
240 break; | |
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
|
241 } |
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
|
242 |
5046 | 243 default: |
244 { | |
245 throw OrthancException(ErrorCode_NotImplemented); | |
246 } | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
247 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
248 |
5046 | 249 // always store the uncompressed data in cache |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
250 if (cache_ != NULL) |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
251 { |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
252 cache_->Add(info.GetUuid(), info.GetContentType(), content); |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
253 } |
221 | 254 } |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
255 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
256 // TODO Check the validity of the uncompressed MD5? |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
257 } |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
258 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
259 |
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
|
260 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
|
261 const FileInfo& info) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
262 { |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
263 if (cache_ == NULL || !cache_->Fetch(content, info.GetUuid(), info.GetContentType())) |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
264 { |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
265 std::unique_ptr<IMemoryBuffer> buffer; |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
266 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
267 { |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
268 MetricsTimer timer(*this, METRICS_READ_DURATION); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
269 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType())); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
270 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
271 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
272 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
273 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
274 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
275 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
276 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
277 buffer->MoveToString(content); |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
278 } |
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 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
280 |
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
|
281 |
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
|
282 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
|
283 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
|
284 { |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
285 if (cache_ != NULL) |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
286 { |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
287 cache_->Invalidate(fileUuid, type); |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
288 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
289 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
290 { |
5325
9c00e832985f
refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
291 MetricsTimer timer(*this, METRICS_REMOVE_DURATION); |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
292 area_.Remove(fileUuid, type); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
293 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
294 } |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
295 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
296 |
4297 | 297 void StorageAccessor::Remove(const FileInfo &info) |
298 { | |
299 Remove(info.GetUuid(), info.GetContentType()); | |
300 } | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1550
diff
changeset
|
301 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
302 |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
303 void StorageAccessor::ReadStartRange(std::string& target, |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
304 const std::string& fileUuid, |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
305 FileContentType contentType, |
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
306 uint64_t end /* exclusive */) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
307 { |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
308 if (cache_ == NULL || !cache_->FetchStartRange(target, fileUuid, contentType, end)) |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
309 { |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
310 std::unique_ptr<IMemoryBuffer> buffer; |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
311 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
312 { |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
313 MetricsTimer timer(*this, METRICS_READ_DURATION); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
314 buffer.reset(area_.ReadRange(fileUuid, contentType, 0, end)); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
315 assert(buffer->GetSize() == end); |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
316 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
317 |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
318 if (metrics_ != NULL) |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
319 { |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5329
diff
changeset
|
320 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize()); |
5329
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
321 } |
d0752fd53aec
added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5325
diff
changeset
|
322 |
4900
ea5f1c6ed07e
fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
323 buffer->MoveToString(target); |
4906
f656fb878b50
reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents:
4901
diff
changeset
|
324 |
5048
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
325 if (cache_ != NULL) |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
326 { |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
327 cache_->AddStartRange(fileUuid, contentType, target); |
22966345eaba
skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents:
5047
diff
changeset
|
328 } |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
329 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
330 } |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
331 |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
332 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
333 #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
|
334 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
|
335 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
|
336 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
337 { |
5059
5c997c72603c
Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5048
diff
changeset
|
338 Read(sender.GetBuffer(), info); |
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
|
339 |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
340 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
|
341 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
342 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
|
343 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
|
344 { |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
345 case FileContentType_Dicom: |
4512
cff7fdfc83a4
added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4484
diff
changeset
|
346 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
|
347 extension = ".dcm"; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
348 break; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
349 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
350 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
|
351 extension = ".json"; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
352 break; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
353 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
354 default: |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
355 // 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
|
356 extension = ""; |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
357 } |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
358 |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
359 sender.SetContentFilename(info.GetUuid() + std::string(extension)); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
360 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
361 #endif |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
362 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
363 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
364 #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
|
365 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
|
366 const FileInfo& info, |
4297 | 367 MimeType mime) |
368 { | |
369 AnswerFile(output, info, EnumerationToString(mime)); | |
370 } | |
371 #endif | |
372 | |
373 | |
374 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
375 void StorageAccessor::AnswerFile(HttpOutput& output, | |
376 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
|
377 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
378 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
379 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
|
380 SetupSender(sender, info, mime); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
381 |
5059
5c997c72603c
Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5048
diff
changeset
|
382 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
383 output.Answer(transcoder); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
384 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
385 #endif |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
386 |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
387 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
388 #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
|
389 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
|
390 const FileInfo& info, |
4297 | 391 MimeType mime) |
392 { | |
393 AnswerFile(output, info, EnumerationToString(mime)); | |
394 } | |
395 #endif | |
396 | |
397 | |
398 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
399 void StorageAccessor::AnswerFile(RestApiOutput& output, | |
400 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
|
401 const std::string& mime) |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
402 { |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
403 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
|
404 SetupSender(sender, info, mime); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
405 |
5059
5c997c72603c
Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5048
diff
changeset
|
406 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
407 output.AnswerStream(transcoder); |
221 | 408 } |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
409 #endif |
221 | 410 } |