annotate OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5430
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * 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
10 * 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
11 * 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
12 * the License, or (at your option) any later version.
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * Lesser General Public License for more details.
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
2653
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
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "MemoryStorageArea.h"
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
28 #include "../Logging.h"
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #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
30 #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
31 #include "../Toolbox.h"
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 MemoryStorageArea::~MemoryStorageArea()
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 if (it->second != NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 delete it->second;
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
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 void MemoryStorageArea::Create(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 const void* content,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 size_t size,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
51 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
52 << "\" type (size: " << Toolbox::GetHumanFileSize(size) << ")";
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
53
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
54 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (size != 0 &&
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 content == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 throw OrthancException(ErrorCode_NullPointer);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 else if (content_.find(uuid) != content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 content_[uuid] = new std::string(reinterpret_cast<const char*>(content), size);
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
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 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
73 FileContentType type)
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
75 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
76 << static_cast<int>(type) << "\" content type";
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
77
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
78 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 Content::const_iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 throw OrthancException(ErrorCode_InexistentFile);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
92 return StringMemoryBuffer::CreateFromCopy(*found->second);
2653
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
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
97 IMemoryBuffer* MemoryStorageArea::ReadRange(const std::string& uuid,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
98 FileContentType type,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
99 uint64_t start /* inclusive */,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
100 uint64_t end /* exclusive */)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
101 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
102 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
103 << static_cast<int>(type) << "\" content type "
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
104 << "(range from " << start << " to " << 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 if (start > end)
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 throw OrthancException(ErrorCode_BadRange);
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 else if (start == end)
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 return new StringMemoryBuffer;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
113 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
114 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
115 {
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
116 Mutex::ScopedLock lock(mutex_);
4495
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 Content::const_iterator found = content_.find(uuid);
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 if (found == content_.end())
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 throw OrthancException(ErrorCode_InexistentFile);
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 else if (found->second == NULL)
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 throw OrthancException(ErrorCode_InternalError);
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 else if (end > found->second->size())
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 throw OrthancException(ErrorCode_BadRange);
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 else
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
133 {
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
134 std::string range;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
135 range.resize(end - start);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
136 assert(!range.empty());
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 memcpy(&range[0], &found->second[start], range.size());
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 return StringMemoryBuffer::CreateFromSwap(range);
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
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
145
4498
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
146 bool MemoryStorageArea::HasReadRange() const
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 return true;
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
7b99e8bb8246 IStorageArea::HasReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
151
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 void MemoryStorageArea::Remove(const std::string& uuid,
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 FileContentType type)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
2826
c277e0421200 unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
155 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
156
5398
08b5516c6e5e compatibility of OrthancFramework with latest releases of Emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
157 Mutex::ScopedLock lock(mutex_);
2653
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 Content::iterator found = content_.find(uuid);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (found == content_.end())
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 // Ignore second removal
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 else if (found->second == NULL)
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 throw OrthancException(ErrorCode_InternalError);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 else
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 delete found->second;
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 content_.erase(found);
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
d7815540bd81 MemoryStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }