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