annotate OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp @ 5420:d37dff2c0028 am-new-cache

Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
author Alain Mazy <am@osimis.io>
date Mon, 13 Nov 2023 17:01:59 +0100
parents 08b5516c6e5e
children b83192e7ad10
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"
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 MemoryStorageArea::~MemoryStorageArea()
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (it->second != NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 delete it->second;
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
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 void MemoryStorageArea::Create(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 const void* content,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 size_t size,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
49 LOG(INFO) << "Creating attachment \"" << uuid << "\" of \"" << static_cast<int>(type)
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
50 << "\" type (size: " << (size / (1024 * 1024) + 1) << "MB)";
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
51
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
52 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 if (size != 0 &&
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 content == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 throw OrthancException(ErrorCode_NullPointer);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 else if (content_.find(uuid) != content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 content_[uuid] = new std::string(reinterpret_cast<const char*>(content), size);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
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
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
70 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
71 FileContentType type)
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
73 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
74 << static_cast<int>(type) << "\" content type";
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
75
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
76 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 Content::const_iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 throw OrthancException(ErrorCode_InexistentFile);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
90 return StringMemoryBuffer::CreateFromCopy(*found->second);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
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
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
95 IMemoryBuffer* MemoryStorageArea::ReadRange(const std::string& uuid,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
96 FileContentType type,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
97 uint64_t start /* inclusive */,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
98 uint64_t end /* exclusive */)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
99 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
100 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
101 << static_cast<int>(type) << "\" content type "
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
102 << "(range from " << start << " to " << end << ")";
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
103
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
104 if (start > end)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
105 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
106 throw OrthancException(ErrorCode_BadRange);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
107 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
108 else if (start == end)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
109 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
110 return new StringMemoryBuffer;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
111 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
112 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
113 {
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
114 Mutex::ScopedLock lock(mutex_);
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
115
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
116 Content::const_iterator found = content_.find(uuid);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
117
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
118 if (found == content_.end())
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
119 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
120 throw OrthancException(ErrorCode_InexistentFile);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
121 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
122 else if (found->second == NULL)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
123 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
124 throw OrthancException(ErrorCode_InternalError);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
125 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
126 else if (end > found->second->size())
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
127 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
128 throw OrthancException(ErrorCode_BadRange);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
129 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
130 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
131 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
132 std::string range;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
133 range.resize(end - start);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
134 assert(!range.empty());
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
135
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
136 memcpy(&range[0], &found->second[start], range.size());
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
137
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
138 return StringMemoryBuffer::CreateFromSwap(range);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
139 }
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
4498
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
144 bool MemoryStorageArea::HasReadRange() const
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
145 {
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
146 return true;
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
147 }
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
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 void MemoryStorageArea::Remove(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
153 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
154
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
155 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 Content::iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 // Ignore second removal
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 delete found->second;
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 content_.erase(found);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }