Mercurial > hg > orthanc
annotate OrthancFramework/Sources/FileStorage/StorageAccessor.h @ 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:
1126
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:
4063
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:
4063
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:
4063
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:
4063
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:
4063
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:
4063
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:
4063
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
221 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
25 #if !defined(ORTHANC_SANDBOXED) |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
26 # error The macro ORTHANC_SANDBOXED must be defined |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
27 #endif |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
28 |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
29 #if ORTHANC_SANDBOXED == 1 |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
30 # error The class StorageAccessor cannot be used in sandboxed environments |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
31 #endif |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2394
diff
changeset
|
32 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
33 #if !defined(ORTHANC_ENABLE_CIVETWEB) |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
34 # error Macro ORTHANC_ENABLE_CIVETWEB must be defined to use this file |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
35 #endif |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
36 |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
37 #if !defined(ORTHANC_ENABLE_MONGOOSE) |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
38 # error Macro ORTHANC_ENABLE_MONGOOSE must be defined to use this file |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
39 #endif |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
40 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
41 #include "IStorageArea.h" |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
42 #include "FileInfo.h" |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
43 |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
44 #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
|
45 # include "../HttpServer/BufferHttpSender.h" |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
46 # include "../RestApi/RestApiOutput.h" |
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
47 #endif |
221 | 48 |
49 #include <vector> | |
50 #include <string> | |
51 #include <boost/noncopyable.hpp> | |
52 #include <stdint.h> | |
53 | |
54 namespace Orthanc | |
55 { | |
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
|
56 class MetricsRegistry; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
57 class StorageCache; |
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
|
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 /** |
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 * This class handles the compression/decompression of the raw files |
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 * contained in the storage area, and monitors timing metrics (if |
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 * enabled). |
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 **/ |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
64 class ORTHANC_PUBLIC StorageAccessor : boost::noncopyable |
221 | 65 { |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
66 private: |
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
|
67 class MetricsTimer; |
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
|
68 |
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
|
69 IStorageArea& area_; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
70 StorageCache& cache_; |
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
|
71 MetricsRegistry* metrics_; |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
72 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
73 #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
|
74 void 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
|
75 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
|
76 const std::string& mime); |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
77 #endif |
221 | 78 |
79 public: | |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
80 explicit StorageAccessor(IStorageArea& area, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
81 StorageCache& cache); |
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
|
82 |
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
|
83 StorageAccessor(IStorageArea& area, |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
84 StorageCache& cache, |
4297 | 85 MetricsRegistry& metrics); |
221 | 86 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
87 FileInfo Write(const void* data, |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
88 size_t size, |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
89 FileContentType type, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
90 CompressionType compression, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
91 bool storeMd5); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
92 |
4297 | 93 FileInfo Write(const std::string& data, |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
94 FileContentType type, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
95 CompressionType compression, |
4297 | 96 bool storeMd5); |
221 | 97 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
98 void Read(std::string& content, |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
99 const FileInfo& info); |
221 | 100 |
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
|
101 void 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
|
102 const FileInfo& info); |
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
|
103 |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
104 IMemoryBuffer* ReadStartRange(const std::string& fileUuid, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
105 FileContentType fullFileContentType, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
106 uint64_t end /* exclusive */, |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
107 FileContentType startFileContentType); |
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
108 |
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
|
109 void 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
|
110 FileContentType type); |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1549
diff
changeset
|
111 |
4297 | 112 void Remove(const FileInfo& info); |
221 | 113 |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
114 #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
|
115 void 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
|
116 const FileInfo& info, |
4297 | 117 MimeType mime); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
118 |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
119 void AnswerFile(HttpOutput& output, |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
120 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
|
121 const std::string& mime); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
122 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
123 void 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
|
124 const FileInfo& info, |
4297 | 125 MimeType mime); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
126 |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
127 void AnswerFile(RestApiOutput& output, |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
128 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
|
129 const std::string& mime); |
2394
75c779ca948c
fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
130 #endif |
221 | 131 }; |
132 } |