Mercurial > hg > orthanc
annotate Core/FileStorage/MemoryStorageArea.cpp @ 3362:0b88d89e71d5 emscripten-logging
Close branch emscripten-logging
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 07 May 2019 11:12:29 +0000 |
parents | 4e43e67f8ecf |
children | 94f4a18a79cc |
rev | line source |
---|---|
2653 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2826
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
2653 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "MemoryStorageArea.h" | |
36 | |
37 #include "../OrthancException.h" | |
2826
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
38 #include "../Logging.h" |
2653 | 39 |
40 namespace Orthanc | |
41 { | |
42 MemoryStorageArea::~MemoryStorageArea() | |
43 { | |
44 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
45 { | |
46 if (it->second != NULL) | |
47 { | |
48 delete it->second; | |
49 } | |
50 } | |
51 } | |
52 | |
53 void MemoryStorageArea::Create(const std::string& uuid, | |
54 const void* content, | |
55 size_t size, | |
56 FileContentType type) | |
57 { | |
2826
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
58 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
|
59 << "\" type (size: " << (size / (1024 * 1024) + 1) << "MB)"; |
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
60 |
2653 | 61 boost::mutex::scoped_lock lock(mutex_); |
62 | |
63 if (size != 0 && | |
64 content == NULL) | |
65 { | |
66 throw OrthancException(ErrorCode_NullPointer); | |
67 } | |
68 else if (content_.find(uuid) != content_.end()) | |
69 { | |
70 throw OrthancException(ErrorCode_InternalError); | |
71 } | |
72 else | |
73 { | |
74 content_[uuid] = new std::string(reinterpret_cast<const char*>(content), size); | |
75 } | |
76 } | |
77 | |
78 | |
79 void MemoryStorageArea::Read(std::string& content, | |
80 const std::string& uuid, | |
81 FileContentType type) | |
82 { | |
2826
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
83 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" |
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
84 << static_cast<int>(type) << "\" content type"; |
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
85 |
2653 | 86 boost::mutex::scoped_lock lock(mutex_); |
87 | |
88 Content::const_iterator found = content_.find(uuid); | |
89 | |
90 if (found == content_.end()) | |
91 { | |
92 throw OrthancException(ErrorCode_InexistentFile); | |
93 } | |
94 else if (found->second == NULL) | |
95 { | |
96 throw OrthancException(ErrorCode_InternalError); | |
97 } | |
98 else | |
99 { | |
100 content.assign(*found->second); | |
101 } | |
102 } | |
103 | |
104 | |
105 void MemoryStorageArea::Remove(const std::string& uuid, | |
106 FileContentType type) | |
107 { | |
2826
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2653
diff
changeset
|
108 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
|
109 |
2653 | 110 boost::mutex::scoped_lock lock(mutex_); |
111 | |
112 Content::iterator found = content_.find(uuid); | |
113 | |
114 if (found == content_.end()) | |
115 { | |
116 // Ignore second removal | |
117 } | |
118 else if (found->second == NULL) | |
119 { | |
120 throw OrthancException(ErrorCode_InternalError); | |
121 } | |
122 else | |
123 { | |
124 delete found->second; | |
125 content_.erase(found); | |
126 } | |
127 } | |
128 } |