Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/DelayedDeletion/Plugin.cpp @ 5264:99751c5a7cfe
added missing copyrights
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Apr 2023 17:43:05 +0200 |
parents | ae3f29be5ca5 |
children | 0e8dfba67ac9 |
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 |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
ae3f29be5ca5
fix compatibility with visual studio precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
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" | |
28 #include "../../../../OrthancServer/Plugins/Engine/PluginsEnumerations.h" | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
29 #include "../../../../OrthancServer/Plugins/Samples/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 | |
70 static OrthancPluginErrorCode StorageCreate(const char* uuid, | |
71 const void* content, | |
72 int64_t size, | |
73 OrthancPluginContentType type) | |
74 { | |
75 try | |
76 { | |
77 storage_->Create(uuid, content, size, Orthanc::Plugins::Convert(type)); | |
78 return OrthancPluginErrorCode_Success; | |
79 } | |
80 catch (Orthanc::OrthancException& e) | |
81 { | |
82 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
83 } | |
84 catch (...) | |
85 { | |
86 return OrthancPluginErrorCode_StorageAreaPlugin; | |
87 } | |
88 } | |
89 | |
90 | |
91 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. | |
92 const char* uuid, | |
93 OrthancPluginContentType type) | |
94 { | |
95 try | |
96 { | |
97 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->Read(uuid, Orthanc::Plugins::Convert(type))); | |
98 | |
99 // copy from a buffer allocated on plugin's heap into a buffer allocated on core's heap | |
100 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, buffer->GetSize()) != OrthancPluginErrorCode_Success) | |
101 { | |
102 OrthancPlugins::LogError("Delayed deletion plugin: error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(buffer->GetSize()) + " bytes"); | |
103 return OrthancPluginErrorCode_StorageAreaPlugin; | |
104 } | |
105 | |
106 memcpy(target->data, buffer->GetData(), buffer->GetSize()); | |
107 | |
108 return OrthancPluginErrorCode_Success; | |
109 } | |
110 catch (Orthanc::OrthancException& e) | |
111 { | |
112 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
113 } | |
114 catch (...) | |
115 { | |
116 return OrthancPluginErrorCode_StorageAreaPlugin; | |
117 } | |
118 } | |
119 | |
120 | |
121 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. | |
122 const char* uuid, | |
123 OrthancPluginContentType type, | |
124 uint64_t rangeStart) | |
125 { | |
126 try | |
127 { | |
128 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->ReadRange(uuid, Orthanc::Plugins::Convert(type), rangeStart, rangeStart + target->size)); | |
129 | |
130 assert(buffer->GetSize() == target->size); | |
131 | |
132 memcpy(target->data, buffer->GetData(), buffer->GetSize()); | |
133 | |
134 return OrthancPluginErrorCode_Success; | |
135 } | |
136 catch (Orthanc::OrthancException& e) | |
137 { | |
138 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
139 } | |
140 catch (...) | |
141 { | |
142 return OrthancPluginErrorCode_StorageAreaPlugin; | |
143 } | |
144 | |
145 return OrthancPluginErrorCode_Success; | |
146 } | |
147 | |
148 | |
149 static OrthancPluginErrorCode StorageRemove(const char* uuid, | |
150 OrthancPluginContentType type) | |
151 { | |
152 try | |
153 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
154 LOG(INFO) << "DelayedDeletion - Scheduling delayed deletion of " << uuid; |
5024 | 155 db_->Enqueue(uuid, Orthanc::Plugins::Convert(type)); |
156 | |
157 return OrthancPluginErrorCode_Success; | |
158 } | |
159 catch (Orthanc::OrthancException& e) | |
160 { | |
161 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
162 } | |
163 catch (...) | |
164 { | |
165 return OrthancPluginErrorCode_StorageAreaPlugin; | |
166 } | |
167 } | |
168 | |
169 static void DeletionWorker() | |
170 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
171 static const unsigned int GRANULARITY = 100; // In milliseconds |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
172 |
5024 | 173 while (continue_) |
174 { | |
175 std::string uuid; | |
176 Orthanc::FileContentType type = Orthanc::FileContentType_Dicom; // Dummy initialization | |
177 | |
178 bool hasDeleted = false; | |
179 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
180 while (continue_ && db_->Dequeue(uuid, type)) |
5024 | 181 { |
182 if (!hasDeleted) | |
183 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
184 LOG(INFO) << "DelayedDeletion - Starting to process the pending deletions"; |
5024 | 185 } |
186 | |
187 hasDeleted = true; | |
188 | |
189 try | |
190 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
191 LOG(INFO) << "DelayedDeletion - Asynchronous removal of file: " << uuid; |
5024 | 192 storage_->Remove(uuid, type); |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
193 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
194 if (throttleDelayMs_ > 0) |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
195 { |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
196 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelayMs_)); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
197 } |
5024 | 198 } |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
199 catch (Orthanc::OrthancException& ex) |
5024 | 200 { |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
201 LOG(ERROR) << "DelayedDeletion - Cannot remove file: " << uuid << " " << ex.What(); |
5024 | 202 } |
203 } | |
204 | |
205 if (hasDeleted) | |
206 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
207 LOG(INFO) << "DelayedDeletion - All the pending deletions have been completed"; |
5024 | 208 } |
209 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
210 boost::this_thread::sleep(boost::posix_time::milliseconds(GRANULARITY)); |
5024 | 211 } |
212 } | |
213 | |
214 | |
215 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
216 OrthancPluginResourceType resourceType, | |
217 const char* resourceId) | |
218 { | |
219 switch (changeType) | |
220 { | |
221 case OrthancPluginChangeType_OrthancStarted: | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
222 assert(deletionThread_.get() == NULL); |
5024 | 223 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
224 LOG(WARNING) << "DelayedDeletion - Starting the deletion thread"; |
5024 | 225 continue_ = true; |
226 deletionThread_.reset(new boost::thread(DeletionWorker)); | |
227 break; | |
228 | |
229 case OrthancPluginChangeType_OrthancStopped: | |
230 | |
231 if (deletionThread_.get() != NULL) | |
232 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
233 LOG(WARNING) << "DelayedDeletion - Stopping the deletion thread"; |
5024 | 234 continue_ = false; |
235 if (deletionThread_->joinable()) | |
236 { | |
237 deletionThread_->join(); | |
238 } | |
239 } | |
240 | |
241 break; | |
242 | |
243 default: | |
244 break; | |
245 } | |
246 | |
247 return OrthancPluginErrorCode_Success; | |
248 } | |
249 | |
250 | |
251 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
252 void GetPluginStatus(OrthancPluginRestOutput* output, |
5024 | 253 const char* url, |
254 const OrthancPluginHttpRequest* request) | |
255 { | |
256 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
257 Json::Value status; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
258 status["FilesPendingDeletion"] = db_->GetSize(); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
259 status["DatabaseServerIdentifier"] = databaseServerIdentifier_; |
5024 | 260 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
261 std::string s = status.toStyledString(); |
5024 | 262 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), |
263 s.size(), "application/json"); | |
264 } | |
265 | |
266 | |
267 | |
268 extern "C" | |
269 { | |
270 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
271 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
272 OrthancPlugins::SetGlobalContext(context); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
273 Orthanc::Logging::InitializePluginContext(context); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
274 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
275 |
5024 | 276 /* Check the version of the Orthanc core */ |
277 if (OrthancPluginCheckVersion(context) == 0) | |
278 { | |
279 char info[1024]; | |
280 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
281 context->orthancVersion, | |
282 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
283 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
284 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
285 OrthancPluginLogError(context, info); | |
286 return -1; | |
287 } | |
288 | |
289 OrthancPluginSetDescription(context, "Plugin removing files from storage asynchronously."); | |
290 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
291 OrthancPlugins::OrthancConfiguration orthancConfig; |
5024 | 292 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
293 if (!orthancConfig.IsSection(DELAYED_DELETION)) |
5024 | 294 { |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
295 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
|
296 return 0; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
297 } |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
298 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
299 OrthancPlugins::OrthancConfiguration delayedDeletionConfig; |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
300 orthancConfig.GetSection(delayedDeletionConfig, DELAYED_DELETION); |
5024 | 301 |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
302 if (delayedDeletionConfig.GetBooleanValue("Enable", true)) |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
303 { |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
304 databaseServerIdentifier_ = OrthancPluginGetDatabaseServerIdentifier(context); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
305 throttleDelayMs_ = delayedDeletionConfig.GetUnsignedIntegerValue("ThrottleDelayMs", 0); // delay in ms |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
306 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
307 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
308 std::string pathStorage = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorage"); |
5024 | 309 LOG(WARNING) << "DelayedDeletion - Path to the storage area: " << pathStorage; |
310 | |
311 storage_.reset(new Orthanc::FilesystemStorage(pathStorage)); | |
312 | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
313 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
|
314 std::string dbPath = delayedDeletionConfig.GetStringValue("Path", defaultDbPath.string()); |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
315 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
316 LOG(WARNING) << "DelayedDeletion - Path to the SQLite database: " << dbPath; |
5024 | 317 |
318 // This must run after the allocation of "storage_", to make sure | |
319 // that the folder actually exists | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
320 db_.reset(new PendingDeletionsDatabase(dbPath)); |
5024 | 321 |
322 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); | |
323 | |
324 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
325 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
326 OrthancPlugins::RegisterRestCallback<GetPluginStatus>(std::string("/plugins/") + ORTHANC_PLUGIN_NAME + "/status", true); |
5024 | 327 } |
328 else | |
329 { | |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
5024
diff
changeset
|
330 LOG(WARNING) << "DelayedDeletion - plugin is loaded but disabled (check your \"DelayedDeletion.Enable\" configuration)"; |
5024 | 331 } |
332 | |
333 return 0; | |
334 } | |
335 | |
336 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
337 { | |
338 db_.reset(); | |
339 storage_.reset(); | |
340 } | |
341 | |
342 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
343 { | |
344 return ORTHANC_PLUGIN_NAME; | |
345 } | |
346 | |
347 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
348 { | |
349 return ORTHANC_PLUGIN_VERSION; | |
350 } | |
351 } |