Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/DelayedDeletion/Plugin.cpp @ 5858:66fd63b8601e find-refactoring tip
StorageAccessOnFind: cont
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 04 Nov 2024 22:34:14 +0100 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
5263
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
1 /** |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5452
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
5263
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
8 * |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
10 * modify it under the terms of the GNU General Public License as |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
11 * published by the Free Software Foundation, either version 3 of the |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
12 * License, or (at your option) any later version. |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
13 * |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
17 * General Public License for more details. |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
18 * |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
21 **/ |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
22 |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
23 |
5024 | 24 #include "PendingDeletionsDatabase.h" |
25 | |
26 #include "../../../../OrthancFramework/Sources/FileStorage/FilesystemStorage.h" | |
27 #include "../../../../OrthancFramework/Sources/Logging.h" | |
28 #include "../../../../OrthancFramework/Sources/MultiThreading/SharedMessageQueue.h" | |
5265 | 29 #include "../Common/OrthancPluginCppWrapper.h" |
5024 | 30 |
31 #include <boost/thread.hpp> | |
32 | |
33 | |
34 class PendingDeletion : public Orthanc::IDynamicObject | |
35 { | |
36 private: | |
37 Orthanc::FileContentType type_; | |
38 std::string uuid_; | |
39 | |
40 public: | |
41 PendingDeletion(Orthanc::FileContentType type, | |
42 const std::string& uuid) : | |
43 type_(type), | |
44 uuid_(uuid) | |
45 { | |
46 } | |
47 | |
48 Orthanc::FileContentType GetType() const | |
49 { | |
50 return type_; | |
51 } | |
52 | |
53 const std::string& GetUuid() const | |
54 { | |
55 return uuid_; | |
56 } | |
57 }; | |
58 | |
59 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
60 static const char* DELAYED_DELETION = "DelayedDeletion"; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
61 static bool continue_ = false; |
5024 | 62 static Orthanc::SharedMessageQueue queue_; |
63 static std::unique_ptr<Orthanc::FilesystemStorage> storage_; | |
64 static std::unique_ptr<PendingDeletionsDatabase> db_; | |
65 static std::unique_ptr<boost::thread> deletionThread_; | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
66 static const char* databaseServerIdentifier_ = NULL; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
67 static unsigned int throttleDelayMs_ = 0; |
5024 | 68 |
69 | |
5265 | 70 static Orthanc::FileContentType Convert(OrthancPluginContentType type) |
71 { | |
72 switch (type) | |
73 { | |
74 case OrthancPluginContentType_Dicom: | |
75 return Orthanc::FileContentType_Dicom; | |
76 | |
77 case OrthancPluginContentType_DicomAsJson: | |
78 return Orthanc::FileContentType_DicomAsJson; | |
79 | |
80 case OrthancPluginContentType_DicomUntilPixelData: | |
81 return Orthanc::FileContentType_DicomUntilPixelData; | |
82 | |
83 default: | |
84 return Orthanc::FileContentType_Unknown; | |
85 } | |
86 } | |
87 | |
88 | |
5024 | 89 static OrthancPluginErrorCode StorageCreate(const char* uuid, |
90 const void* content, | |
91 int64_t size, | |
92 OrthancPluginContentType type) | |
93 { | |
94 try | |
95 { | |
5265 | 96 storage_->Create(uuid, content, size, Convert(type)); |
5024 | 97 return OrthancPluginErrorCode_Success; |
98 } | |
99 catch (Orthanc::OrthancException& e) | |
100 { | |
101 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
102 } | |
103 catch (...) | |
104 { | |
105 return OrthancPluginErrorCode_StorageAreaPlugin; | |
106 } | |
107 } | |
108 | |
109 | |
110 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. | |
111 const char* uuid, | |
112 OrthancPluginContentType type) | |
113 { | |
114 try | |
115 { | |
5265 | 116 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->Read(uuid, Convert(type))); |
5024 | 117 |
118 // copy from a buffer allocated on plugin's heap into a buffer allocated on core's heap | |
119 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, buffer->GetSize()) != OrthancPluginErrorCode_Success) | |
120 { | |
5561
0b18690c1935
SDK: added OrthancPluginLogMessage to display plugin name + file and line from plugin
Alain Mazy <am@orthanc.team>
parents:
5538
diff
changeset
|
121 LOG(ERROR) << "Delayed deletion plugin: error while reading object " << uuid << ", cannot allocate memory of size " << buffer->GetSize() << " bytes"; |
5024 | 122 return OrthancPluginErrorCode_StorageAreaPlugin; |
123 } | |
124 | |
125 memcpy(target->data, buffer->GetData(), buffer->GetSize()); | |
126 | |
127 return OrthancPluginErrorCode_Success; | |
128 } | |
129 catch (Orthanc::OrthancException& e) | |
130 { | |
131 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
132 } | |
133 catch (...) | |
134 { | |
135 return OrthancPluginErrorCode_StorageAreaPlugin; | |
136 } | |
137 } | |
138 | |
139 | |
140 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer. | |
141 const char* uuid, | |
142 OrthancPluginContentType type, | |
143 uint64_t rangeStart) | |
144 { | |
145 try | |
146 { | |
5265 | 147 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->ReadRange(uuid, Convert(type), rangeStart, rangeStart + target->size)); |
5024 | 148 |
149 assert(buffer->GetSize() == target->size); | |
150 | |
151 memcpy(target->data, buffer->GetData(), buffer->GetSize()); | |
152 | |
153 return OrthancPluginErrorCode_Success; | |
154 } | |
155 catch (Orthanc::OrthancException& e) | |
156 { | |
157 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
158 } | |
159 catch (...) | |
160 { | |
161 return OrthancPluginErrorCode_StorageAreaPlugin; | |
162 } | |
163 | |
164 return OrthancPluginErrorCode_Success; | |
165 } | |
166 | |
167 | |
168 static OrthancPluginErrorCode StorageRemove(const char* uuid, | |
169 OrthancPluginContentType type) | |
170 { | |
171 try | |
172 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
173 LOG(INFO) << "DelayedDeletion - Scheduling delayed deletion of " << uuid; |
5265 | 174 db_->Enqueue(uuid, Convert(type)); |
5024 | 175 |
176 return OrthancPluginErrorCode_Success; | |
177 } | |
178 catch (Orthanc::OrthancException& e) | |
179 { | |
180 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
181 } | |
182 catch (...) | |
183 { | |
184 return OrthancPluginErrorCode_StorageAreaPlugin; | |
185 } | |
186 } | |
187 | |
188 static void DeletionWorker() | |
189 { | |
5452
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5265
diff
changeset
|
190 OrthancPluginSetCurrentThreadName(OrthancPlugins::GetGlobalContext(), "DELETION"); |
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5265
diff
changeset
|
191 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
192 static const unsigned int GRANULARITY = 100; // In milliseconds |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
193 |
5024 | 194 while (continue_) |
195 { | |
196 std::string uuid; | |
197 Orthanc::FileContentType type = Orthanc::FileContentType_Dicom; // Dummy initialization | |
198 | |
199 bool hasDeleted = false; | |
200 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
201 while (continue_ && db_->Dequeue(uuid, type)) |
5024 | 202 { |
203 if (!hasDeleted) | |
204 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
205 LOG(INFO) << "DelayedDeletion - Starting to process the pending deletions"; |
5024 | 206 } |
207 | |
208 hasDeleted = true; | |
209 | |
210 try | |
211 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
212 LOG(INFO) << "DelayedDeletion - Asynchronous removal of file: " << uuid; |
5024 | 213 storage_->Remove(uuid, type); |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
214 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
215 if (throttleDelayMs_ > 0) |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
216 { |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
217 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelayMs_)); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
218 } |
5024 | 219 } |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
220 catch (Orthanc::OrthancException& ex) |
5024 | 221 { |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
222 LOG(ERROR) << "DelayedDeletion - Cannot remove file: " << uuid << " " << ex.What(); |
5024 | 223 } |
224 } | |
225 | |
226 if (hasDeleted) | |
227 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
228 LOG(INFO) << "DelayedDeletion - All the pending deletions have been completed"; |
5024 | 229 } |
230 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
231 boost::this_thread::sleep(boost::posix_time::milliseconds(GRANULARITY)); |
5024 | 232 } |
233 } | |
234 | |
235 | |
236 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
237 OrthancPluginResourceType resourceType, | |
238 const char* resourceId) | |
239 { | |
240 switch (changeType) | |
241 { | |
242 case OrthancPluginChangeType_OrthancStarted: | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
243 assert(deletionThread_.get() == NULL); |
5024 | 244 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
245 LOG(WARNING) << "DelayedDeletion - Starting the deletion thread"; |
5024 | 246 continue_ = true; |
247 deletionThread_.reset(new boost::thread(DeletionWorker)); | |
248 break; | |
249 | |
250 case OrthancPluginChangeType_OrthancStopped: | |
251 | |
252 if (deletionThread_.get() != NULL) | |
253 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
254 LOG(WARNING) << "DelayedDeletion - Stopping the deletion thread"; |
5024 | 255 continue_ = false; |
256 if (deletionThread_->joinable()) | |
257 { | |
258 deletionThread_->join(); | |
259 } | |
260 } | |
261 | |
262 break; | |
263 | |
264 default: | |
265 break; | |
266 } | |
267 | |
268 return OrthancPluginErrorCode_Success; | |
269 } | |
270 | |
271 | |
272 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
273 void GetPluginStatus(OrthancPluginRestOutput* output, |
5024 | 274 const char* url, |
275 const OrthancPluginHttpRequest* request) | |
276 { | |
277 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
278 Json::Value status; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
279 status["FilesPendingDeletion"] = db_->GetSize(); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
280 status["DatabaseServerIdentifier"] = databaseServerIdentifier_; |
5024 | 281 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
282 std::string s = status.toStyledString(); |
5024 | 283 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), |
284 s.size(), "application/json"); | |
285 } | |
286 | |
287 | |
288 | |
289 extern "C" | |
290 { | |
291 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
292 { | |
5563 | 293 OrthancPlugins::SetGlobalContext(context, ORTHANC_PLUGIN_NAME); |
294 Orthanc::Logging::InitializePluginContext(context, ORTHANC_PLUGIN_NAME); | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
295 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
296 |
5024 | 297 /* Check the version of the Orthanc core */ |
298 if (OrthancPluginCheckVersion(context) == 0) | |
299 { | |
300 char info[1024]; | |
301 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
302 context->orthancVersion, | |
303 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
304 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
305 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
306 OrthancPluginLogError(context, info); | |
307 return -1; | |
308 } | |
309 | |
5538
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
310 OrthancPluginSetDescription2(context, ORTHANC_PLUGIN_NAME, "Plugin removing files from storage asynchronously."); |
5024 | 311 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
312 OrthancPlugins::OrthancConfiguration orthancConfig; |
5024 | 313 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
314 if (!orthancConfig.IsSection(DELAYED_DELETION)) |
5024 | 315 { |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
316 LOG(WARNING) << "DelayedDeletion - plugin is loaded but not enabled (no \"DelayedDeletion\" section found in configuration)"; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
317 return 0; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
318 } |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
319 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
320 OrthancPlugins::OrthancConfiguration delayedDeletionConfig; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
321 orthancConfig.GetSection(delayedDeletionConfig, DELAYED_DELETION); |
5024 | 322 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
323 if (delayedDeletionConfig.GetBooleanValue("Enable", true)) |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
324 { |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
325 databaseServerIdentifier_ = OrthancPluginGetDatabaseServerIdentifier(context); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
326 throttleDelayMs_ = delayedDeletionConfig.GetUnsignedIntegerValue("ThrottleDelayMs", 0); // delay in ms |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
327 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
328 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
329 std::string pathStorage = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorage"); |
5024 | 330 LOG(WARNING) << "DelayedDeletion - Path to the storage area: " << pathStorage; |
331 | |
332 storage_.reset(new Orthanc::FilesystemStorage(pathStorage)); | |
333 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
334 boost::filesystem::path defaultDbPath = boost::filesystem::path(pathStorage) / (std::string("pending-deletions.") + databaseServerIdentifier_ + ".db"); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
335 std::string dbPath = delayedDeletionConfig.GetStringValue("Path", defaultDbPath.string()); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
336 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
337 LOG(WARNING) << "DelayedDeletion - Path to the SQLite database: " << dbPath; |
5024 | 338 |
339 // This must run after the allocation of "storage_", to make sure | |
340 // that the folder actually exists | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
341 db_.reset(new PendingDeletionsDatabase(dbPath)); |
5024 | 342 |
343 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); | |
344 | |
345 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
346 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
347 OrthancPlugins::RegisterRestCallback<GetPluginStatus>(std::string("/plugins/") + ORTHANC_PLUGIN_NAME + "/status", true); |
5024 | 348 } |
349 else | |
350 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
351 LOG(WARNING) << "DelayedDeletion - plugin is loaded but disabled (check your \"DelayedDeletion.Enable\" configuration)"; |
5024 | 352 } |
353 | |
354 return 0; | |
355 } | |
356 | |
357 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
358 { | |
359 db_.reset(); | |
360 storage_.reset(); | |
361 } | |
362 | |
363 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
364 { | |
365 return ORTHANC_PLUGIN_NAME; | |
366 } | |
367 | |
368 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
369 { | |
370 return ORTHANC_PLUGIN_VERSION; | |
371 } | |
372 } |