annotate Framework/Plugins/StorageBackend.cpp @ 258:9856290c3cfd

todo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Apr 2021 17:45:11 +0200
parents d663d9e44f8d
children cd73e34d5411
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
193
3236894320d6 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "StorageBackend.h"
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #if HAS_ORTHANC_EXCEPTION != 1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # error HAS_ORTHANC_EXCEPTION must be set to 1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #endif
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
28 #include "../../Framework/Common/BinaryStringValue.h"
245
9d00e5e073e8 rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 244
diff changeset
29 #include "../../Framework/Common/ResultFileValue.h"
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
30
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
31 #include <Compatibility.h> // For std::unique_ptr<>
249
7f5ee2b42a86 better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 246
diff changeset
32 #include <Logging.h>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
33 #include <OrthancException.h>
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
231
0a9b48d19643 removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
35 #include <cassert>
194
a51ce147dbe0 refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
36 #include <limits>
a51ce147dbe0 refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
37
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #define ORTHANC_PLUGINS_DATABASE_CATCH \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 catch (::Orthanc::OrthancException& e) \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 { \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 } \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 catch (::std::runtime_error& e) \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 { \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 std::string s = "Exception in storage area back-end: " + std::string(e.what()); \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 OrthancPluginLogError(context_, s.c_str()); \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 return OrthancPluginErrorCode_DatabasePlugin; \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 } \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 catch (...) \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 { \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 OrthancPluginLogError(context_, "Native exception"); \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 return OrthancPluginErrorCode_DatabasePlugin; \
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 namespace OrthancDatabases
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
59 StorageBackend::StorageBackend(IDatabaseFactory* factory) :
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
60 manager_(factory)
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
63
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
64 void StorageBackend::AccessorBase::Create(const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
65 const void* content,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
66 size_t size,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
67 OrthancPluginContentType type)
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
68 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
69 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
70
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
71 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
72 DatabaseManager::CachedStatement statement(
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
73 STATEMENT_FROM_HERE, manager_,
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
74 "INSERT INTO StorageArea VALUES (${uuid}, ${content}, ${type})");
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
75
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
76 statement.SetParameterType("uuid", ValueType_Utf8String);
244
02cd7254c949 separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
77 statement.SetParameterType("content", ValueType_InputFile);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
78 statement.SetParameterType("type", ValueType_Integer64);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
79
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
80 Dictionary args;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
81 args.SetUtf8Value("uuid", uuid);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
82 args.SetFileValue("content", content, size);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
83 args.SetIntegerValue("type", type);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
84
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
85 statement.Execute(args);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
86 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
87
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
88 transaction.Commit();
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
89 }
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
90
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
91
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
92 void StorageBackend::AccessorBase::ReadWhole(StorageBackend::IFileContentVisitor& visitor,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
93 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
94 OrthancPluginContentType type)
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
95 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
96 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadOnly);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
97
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
98 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
99 DatabaseManager::CachedStatement statement(
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
100 STATEMENT_FROM_HERE, manager_,
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
101 "SELECT content FROM StorageArea WHERE uuid=${uuid} AND type=${type}");
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
102
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
103 statement.SetParameterType("uuid", ValueType_Utf8String);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
104 statement.SetParameterType("type", ValueType_Integer64);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
105
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
106 Dictionary args;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
107 args.SetUtf8Value("uuid", uuid);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
108 args.SetIntegerValue("type", type);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
109
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
110 statement.Execute(args);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
111
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
112 if (statement.IsDone())
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
113 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
115 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
116 else if (statement.GetResultFieldsCount() != 1)
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
117 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
119 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
120 else
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
121 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
122 const IValue& value = statement.GetResultField(0);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
123
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
124 switch (value.GetType())
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
125 {
245
9d00e5e073e8 rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 244
diff changeset
126 case ValueType_ResultFile:
246
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
127 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
128 std::string content;
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
129 dynamic_cast<const ResultFileValue&>(value).ReadWhole(content);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
130 visitor.Assign(content);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
131 break;
246
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
132 }
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
133
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
134 case ValueType_BinaryString:
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
135 visitor.Assign(dynamic_cast<const BinaryStringValue&>(value).GetContent());
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
136 break;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
137
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
138 default:
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
140 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
141 }
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
142 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
143
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
144 transaction.Commit();
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
145
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
146 if (!visitor.IsSuccess())
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
147 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Could not read attachment from the storage area");
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
149 }
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
150 }
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
151
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
152
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
153 void StorageBackend::AccessorBase::ReadRange(IFileContentVisitor& visitor,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
154 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
155 OrthancPluginContentType type,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
156 uint64_t start,
246
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
157 size_t length)
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
158 {
246
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
159 /**
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
160 * This is a generic implementation, that will only work if
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
161 * "ResultFileValue" is implemented by the database backend. For
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
162 * instance, this will *not* work with MySQL, as the latter uses
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
163 * BLOB columns to store files.
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
164 **/
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
165 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadOnly);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
166
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
167 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
168 DatabaseManager::CachedStatement statement(
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
169 STATEMENT_FROM_HERE, manager_,
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
170 "SELECT content FROM StorageArea WHERE uuid=${uuid} AND type=${type}");
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
171
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
172 statement.SetParameterType("uuid", ValueType_Utf8String);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
173 statement.SetParameterType("type", ValueType_Integer64);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
174
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
175 Dictionary args;
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
176 args.SetUtf8Value("uuid", uuid);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
177 args.SetIntegerValue("type", type);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
178
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
179 statement.Execute(args);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
180
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
181 if (statement.IsDone())
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
182 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
183 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
184 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
185 else if (statement.GetResultFieldsCount() != 1)
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
186 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
187 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
188 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
189 else
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
190 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
191 const IValue& value = statement.GetResultField(0);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
192 if (value.GetType() == ValueType_ResultFile)
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
193 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
194 std::string content;
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
195 dynamic_cast<const ResultFileValue&>(value).ReadRange(content, start, length);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
196 visitor.Assign(content);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
197 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
198 else
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
199 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
200 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
201 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
202 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
203 }
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
204
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
205 transaction.Commit();
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
206
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
207 if (!visitor.IsSuccess())
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
208 {
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
209 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Could not read attachment from the storage area");
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
210 }
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
211 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
212
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
213
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
214 void StorageBackend::AccessorBase::Remove(const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
215 OrthancPluginContentType type)
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
216 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
217 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
218
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
219 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
220 DatabaseManager::CachedStatement statement(
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
221 STATEMENT_FROM_HERE, manager_,
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
222 "DELETE FROM StorageArea WHERE uuid=${uuid} AND type=${type}");
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
223
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
224 statement.SetParameterType("uuid", ValueType_Utf8String);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
225 statement.SetParameterType("type", ValueType_Integer64);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
226
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
227 Dictionary args;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
228 args.SetUtf8Value("uuid", uuid);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
229 args.SetIntegerValue("type", type);
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
230
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
231 statement.Execute(args);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
232 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
233
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
234 transaction.Commit();
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
235 }
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
236
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
237
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
238
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 static OrthancPluginContext* context_ = NULL;
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
240 static std::unique_ptr<StorageBackend> backend_;
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
242
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 static OrthancPluginErrorCode StorageCreate(const char* uuid,
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 const void* content,
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 int64_t size,
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 OrthancPluginContentType type)
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 try
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
250 if (backend_.get() == NULL)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
251 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
252 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
253 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
254 else
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
255 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
256 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
257 accessor->Create(uuid, content, static_cast<size_t>(size), type);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
258 return OrthancPluginErrorCode_Success;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
259 }
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 ORTHANC_PLUGINS_DATABASE_CATCH;
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
265 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 0)
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
266 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target,
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
267 const char* uuid,
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
268 OrthancPluginContentType type)
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
269 {
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
270 class Visitor : public StorageBackend::IFileContentVisitor
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
271 {
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
272 private:
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
273 OrthancPluginMemoryBuffer64* target_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
274 bool success_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
275
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
276 public:
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
277 Visitor(OrthancPluginMemoryBuffer64* target) :
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
278 target_(target),
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
279 success_(false)
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
280 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
281 if (target == NULL)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
282 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
283 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
284 }
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
285 }
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
286
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
287 virtual bool IsSuccess() const ORTHANC_OVERRIDE
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
288 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
289 return success_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
290 }
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
291
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
292 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
293 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
294 if (success_)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
295 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
296 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
297 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
298 else
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
299 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
300 assert(context_ != NULL);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
301
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
302 if (OrthancPluginCreateMemoryBuffer64(context_, target_, static_cast<uint64_t>(content.size())) !=
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
303 OrthancPluginErrorCode_Success)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
304 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
305 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
306 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
307
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
308 if (!content.empty())
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
309 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
310 memcpy(target_->data, content.c_str(), content.size());
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
311 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
312
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
313 success_ = true;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
314 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
315 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
316 };
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
317
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
318
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 try
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
321 if (backend_.get() == NULL)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
322 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
323 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
324 }
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
325 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
326 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
327 Visitor visitor(target);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
328
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
329 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
330 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
331 accessor->ReadWhole(visitor, uuid, type);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
332 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
333
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
334 return OrthancPluginErrorCode_Success;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
335 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
336 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
337 ORTHANC_PLUGINS_DATABASE_CATCH;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
338 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
339
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
340
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
341 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
342 const char* uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
343 OrthancPluginContentType type,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
344 uint64_t start)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
345 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
346 class Visitor : public StorageBackend::IFileContentVisitor
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
347 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
348 private:
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
349 OrthancPluginMemoryBuffer64* target_; // This buffer is already allocated by the Orthanc core
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
350 bool success_;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
351
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
352 public:
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
353 Visitor(OrthancPluginMemoryBuffer64* target) :
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
354 target_(target),
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
355 success_(false)
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
356 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
357 if (target == NULL)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
358 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
359 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
360 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
361 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
362
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
363 virtual bool IsSuccess() const ORTHANC_OVERRIDE
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
364 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
365 return success_;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
366 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
367
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
368 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
369 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
370 if (success_)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
371 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
372 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
373 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
374 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
375 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
376 if (content.size() != target_->size)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
377 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
378 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
379 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
380
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
381 if (!content.empty())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
382 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
383 memcpy(target_->data, content.c_str(), content.size());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
384 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
385
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
386 success_ = true;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
387 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
388 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
389 };
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
390
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
391
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
392 try
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
393 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
394 if (backend_.get() == NULL)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
395 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
396 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
397 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
398 else
194
a51ce147dbe0 refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
399 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
400 Visitor visitor(target);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
401
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
402 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
403 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
404 accessor->ReadRange(visitor, uuid, type, start, target->size);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
405 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
406
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
407 return OrthancPluginErrorCode_Success;
194
a51ce147dbe0 refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
408 }
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 ORTHANC_PLUGINS_DATABASE_CATCH;
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
412 #endif
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
414
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
415 static OrthancPluginErrorCode StorageRead(void** data,
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
416 int64_t* size,
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
417 const char* uuid,
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
418 OrthancPluginContentType type)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
419 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
420 class Visitor : public StorageBackend::IFileContentVisitor
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
421 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
422 private:
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
423 void** data_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
424 int64_t* size_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
425 bool success_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
426
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
427 public:
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
428 Visitor(void** data,
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
429 int64_t* size) :
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
430 data_(data),
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
431 size_(size),
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
432 success_(false)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
433 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
434 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
435
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
436 ~Visitor()
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
437 {
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
438 if (data_ != NULL /* this condition is invalidated by "Release()" */ &&
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
439 *data_ != NULL)
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
440 {
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
441 free(*data_);
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
442 }
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
443 }
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
444
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
445 void Release()
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
446 {
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
447 data_ = NULL;
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
448 }
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
449
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
450 virtual bool IsSuccess() const ORTHANC_OVERRIDE
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
451 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
452 return success_;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
453 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
454
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
455 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
456 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
457 if (success_)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
458 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
460 }
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
461 else if (data_ == NULL)
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
462 {
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
463 // "Release()" has been called
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
464 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
465 }
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
466 else
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
467 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
468 if (content.empty())
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
469 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
470 *data_ = NULL;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
471 *size_ = 0;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
472 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
473 else
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
474 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
475 *size_ = static_cast<int64_t>(content.size());
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
476
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
477 if (static_cast<size_t>(*size_) != content.size())
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
478 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
479 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory,
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
480 "File cannot be stored in a 63bit buffer");
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
481 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
482
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
483 *data_ = malloc(*size_);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
484 if (*data_ == NULL)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
485 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
486 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
487 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
488
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
489 memcpy(*data_, content.c_str(), *size_);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
490 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
491
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
492 success_ = true;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
493 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
494 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
495 };
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
496
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
497
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
498 try
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
499 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
500 if (backend_.get() == NULL)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
501 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
502 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
503 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
504 else if (data == NULL ||
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
505 size == NULL)
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
506 {
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
507 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
508 }
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
509 else
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
510 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
511 Visitor visitor(data, size);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
512
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
513 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
514 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
515 accessor->ReadWhole(visitor, uuid, type);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
516 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
517
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
518 visitor.Release();
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
519
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
520 return OrthancPluginErrorCode_Success;
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
521 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
522 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
523 ORTHANC_PLUGINS_DATABASE_CATCH;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
524 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
525
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 static OrthancPluginErrorCode StorageRemove(const char* uuid,
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 OrthancPluginContentType type)
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 try
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
532 if (backend_.get() == NULL)
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
533 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
534 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
535 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
536 else
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
537 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
538 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
539 accessor->Remove(uuid, type);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
540 return OrthancPluginErrorCode_Success;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
541 }
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 ORTHANC_PLUGINS_DATABASE_CATCH;
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 void StorageBackend::Register(OrthancPluginContext* context,
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 StorageBackend* backend)
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 if (context == NULL ||
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 backend == NULL)
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 if (context_ != NULL ||
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 backend_.get() != NULL)
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 // This function can only be invoked once in the plugin
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 else
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 context_ = context;
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 backend_.reset(backend);
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
567 bool hasLoadedV2 = false;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
568
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
569 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
570 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 0)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
571 if (OrthancPluginCheckVersionAdvanced(context, 1, 9, 0) == 1)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
572 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
573 OrthancPluginStorageReadRange readRange = NULL;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
574 if (backend_->HasReadRange())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
575 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
576 readRange = StorageReadRange;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
577 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
578
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
579 OrthancPluginRegisterStorageArea2(context_, StorageCreate, StorageReadWhole, readRange, StorageRemove);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
580 hasLoadedV2 = true;
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
581 }
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
582 # endif
195
53bd9022c58b Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 194
diff changeset
583 #endif
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
584
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
585 if (!hasLoadedV2)
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
586 {
249
7f5ee2b42a86 better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 246
diff changeset
587 LOG(WARNING) << "Performance warning: Your version of the Orthanc SDK doesn't support reading of file ranges";
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
588 OrthancPluginRegisterStorageArea(context_, StorageCreate, StorageRead, StorageRemove);
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
589 }
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 }
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 void StorageBackend::Finalize()
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 {
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 backend_.reset(NULL);
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 context_ = NULL;
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 }
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
599
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
600
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
601 class StorageBackend::StringVisitor : public StorageBackend::IFileContentVisitor
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
602 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
603 private:
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
604 std::string& target_;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
605 bool success_;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
606
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
607 public:
252
33fa478c119a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
608 explicit StringVisitor(std::string& target) :
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
609 target_(target),
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
610 success_(false)
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
611 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
612 }
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
613
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
614 virtual bool IsSuccess() const ORTHANC_OVERRIDE
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
615 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
616 return success_;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
617 }
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
618
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
619 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
620 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
621 if (success_)
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
622 {
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
623 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
624 }
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
625 else
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
626 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
627 target_.assign(content);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
628 success_ = true;
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
629 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
630 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
631 };
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
632
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
633
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
634 void StorageBackend::ReadWholeToString(std::string& target,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
635 IAccessor& accessor,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
636 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
637 OrthancPluginContentType type)
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
638 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
639 StringVisitor visitor(target);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
640 accessor.ReadWhole(visitor, uuid, type);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
641
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
642 if (!visitor.IsSuccess())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
643 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
644 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
645 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
646 }
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
647
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
648
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
649 void StorageBackend::ReadRangeToString(std::string& target,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
650 IAccessor& accessor,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
651 const std::string& uuid,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
652 OrthancPluginContentType type,
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
653 uint64_t start,
246
483af3f35a4b turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 245
diff changeset
654 size_t length)
242
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
655 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
656 StringVisitor visitor(target);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
657 accessor.ReadRange(visitor, uuid, type, start, length);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
658
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
659 if (!visitor.IsSuccess())
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
660 {
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
661 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b97a537f4613 MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
662 }
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 208
diff changeset
663 }
1
d17b2631bb67 starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 }