annotate Core/FileStorage/MemoryStorageArea.cpp @ 2823:807169f85ba9

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