annotate OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp @ 5447:dacdce5e5c22

now accepting GET requests on the /tools/create-archive route and siblings
author Alain Mazy <am@osimis.io>
date Fri, 24 Nov 2023 18:14:52 +0100
parents b83192e7ad10
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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.
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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.
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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/>.
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../PrecompiledHeaders.h"
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "MemoryStorageArea.h"
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
27 #include "../Logging.h"
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../OrthancException.h"
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
29 #include "../StringMemoryBuffer.h"
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5398
diff changeset
30 #include "../Toolbox.h"
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace Orthanc
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 MemoryStorageArea::~MemoryStorageArea()
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (it->second != NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 delete it->second;
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 void MemoryStorageArea::Create(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 const void* content,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 size_t size,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
50 LOG(INFO) << "Creating attachment \"" << uuid << "\" of \"" << static_cast<int>(type)
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5398
diff changeset
51 << "\" type (size: " << Toolbox::GetHumanFileSize(size) << ")";
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
52
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
53 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (size != 0 &&
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 content == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 throw OrthancException(ErrorCode_NullPointer);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 else if (content_.find(uuid) != content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 content_[uuid] = new std::string(reinterpret_cast<const char*>(content), size);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
71 IMemoryBuffer* MemoryStorageArea::Read(const std::string& uuid,
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 FileContentType type)
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
74 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
75 << static_cast<int>(type) << "\" content type";
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
76
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
77 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Content::const_iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 throw OrthancException(ErrorCode_InexistentFile);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
91 return StringMemoryBuffer::CreateFromCopy(*found->second);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
96 IMemoryBuffer* MemoryStorageArea::ReadRange(const std::string& uuid,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
97 FileContentType type,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
98 uint64_t start /* inclusive */,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
99 uint64_t end /* exclusive */)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
100 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
101 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
102 << static_cast<int>(type) << "\" content type "
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
103 << "(range from " << start << " to " << end << ")";
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
104
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
105 if (start > end)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
106 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
107 throw OrthancException(ErrorCode_BadRange);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
108 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
109 else if (start == end)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
110 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
111 return new StringMemoryBuffer;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
112 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
113 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
114 {
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
115 Mutex::ScopedLock lock(mutex_);
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
116
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
117 Content::const_iterator found = content_.find(uuid);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
118
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
119 if (found == content_.end())
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
120 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
121 throw OrthancException(ErrorCode_InexistentFile);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
122 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
123 else if (found->second == NULL)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
124 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
125 throw OrthancException(ErrorCode_InternalError);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
126 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
127 else if (end > found->second->size())
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
128 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
129 throw OrthancException(ErrorCode_BadRange);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
130 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
131 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
132 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
133 std::string range;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
134 range.resize(end - start);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
135 assert(!range.empty());
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
136
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
137 memcpy(&range[0], &found->second[start], range.size());
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
138
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
139 return StringMemoryBuffer::CreateFromSwap(range);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
140 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
141 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
142 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
143
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
144
4498
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
145 bool MemoryStorageArea::HasReadRange() const
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
146 {
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
147 return true;
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
148 }
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
149
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
150
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 void MemoryStorageArea::Remove(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
154 LOG(INFO) << "Deleting attachment \"" << uuid << "\" of type " << static_cast<int>(type);
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
155
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
156 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 Content::iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 // Ignore second removal
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 delete found->second;
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 content_.erase(found);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }