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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 #include "PendingDeletionsDatabase.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 #include "../../../../OrthancFramework/Sources/FileStorage/FilesystemStorage.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 #include "../../../../OrthancFramework/Sources/Logging.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include "../../../../OrthancFramework/Sources/MultiThreading/SharedMessageQueue.h"
5265
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
29 #include "../Common/OrthancPluginCppWrapper.h"
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
30
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 #include <boost/thread.hpp>
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
32
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
33
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 class PendingDeletion : public Orthanc::IDynamicObject
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 private:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 Orthanc::FileContentType type_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 std::string uuid_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
39
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 public:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
41 PendingDeletion(Orthanc::FileContentType type,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 const std::string& uuid) :
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 type_(type),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
44 uuid_(uuid)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
47
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 Orthanc::FileContentType GetType() const
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 return type_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
52
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
53 const std::string& GetUuid() const
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 return uuid_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 };
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
58
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 static Orthanc::SharedMessageQueue queue_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 static std::unique_ptr<Orthanc::FilesystemStorage> storage_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 static std::unique_ptr<PendingDeletionsDatabase> db_;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
68
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
69
5265
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
70 static Orthanc::FileContentType Convert(OrthancPluginContentType type)
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
71 {
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
72 switch (type)
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
73 {
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
74 case OrthancPluginContentType_Dicom:
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
75 return Orthanc::FileContentType_Dicom;
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
76
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
77 case OrthancPluginContentType_DicomAsJson:
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
78 return Orthanc::FileContentType_DicomAsJson;
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
79
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
80 case OrthancPluginContentType_DicomUntilPixelData:
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
81 return Orthanc::FileContentType_DicomUntilPixelData;
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
82
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
83 default:
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
84 return Orthanc::FileContentType_Unknown;
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
85 }
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
86 }
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
87
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
88
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 static OrthancPluginErrorCode StorageCreate(const char* uuid,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 const void* content,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 int64_t size,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 OrthancPluginContentType type)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 try
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 {
5265
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
96 storage_->Create(uuid, content, size, Convert(type));
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 catch (Orthanc::OrthancException& e)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 catch (...)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 return OrthancPluginErrorCode_StorageAreaPlugin;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
108
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
109
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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.
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 const char* uuid,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 OrthancPluginContentType type)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 try
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 {
5265
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
116 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->Read(uuid, Convert(type)));
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
117
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 // copy from a buffer allocated on plugin's heap into a buffer allocated on core's heap
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, buffer->GetSize()) != OrthancPluginErrorCode_Success)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 return OrthancPluginErrorCode_StorageAreaPlugin;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
124
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 memcpy(target->data, buffer->GetData(), buffer->GetSize());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
126
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 catch (Orthanc::OrthancException& e)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 catch (...)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 return OrthancPluginErrorCode_StorageAreaPlugin;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
138
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
139
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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.
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
141 const char* uuid,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
142 OrthancPluginContentType type,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 uint64_t rangeStart)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
144 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 try
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 {
5265
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
147 std::unique_ptr<Orthanc::IMemoryBuffer> buffer(storage_->ReadRange(uuid, Convert(type), rangeStart, rangeStart + target->size));
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
148
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 assert(buffer->GetSize() == target->size);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
150
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
151 memcpy(target->data, buffer->GetData(), buffer->GetSize());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
152
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 catch (Orthanc::OrthancException& e)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
156 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 catch (...)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
160 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 return OrthancPluginErrorCode_StorageAreaPlugin;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
163
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
166
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
167
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
168 static OrthancPluginErrorCode StorageRemove(const char* uuid,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
169 OrthancPluginContentType type)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 try
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
0e8dfba67ac9 fix pch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5263
diff changeset
174 db_->Enqueue(uuid, Convert(type));
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
175
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 catch (Orthanc::OrthancException& e)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
179 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
180 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 catch (...)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
183 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 return OrthancPluginErrorCode_StorageAreaPlugin;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
187
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 static void DeletionWorker()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 while (continue_)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
195 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 std::string uuid;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
197 Orthanc::FileContentType type = Orthanc::FileContentType_Dicom; // Dummy initialization
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
198
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
199 bool hasDeleted = false;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
200
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
201 while (continue_ && db_->Dequeue(uuid, type))
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
202 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
203 if (!hasDeleted)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
207
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
208 hasDeleted = true;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
209
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
210 try
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
219 }
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
220 catch (Orthanc::OrthancException& ex)
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
223 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
224 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
225
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
226 if (hasDeleted)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
229 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
232 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
233 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
234
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
235
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
236 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
237 OrthancPluginResourceType resourceType,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
238 const char* resourceId)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
239 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
240 switch (changeType)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
246 continue_ = true;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
247 deletionThread_.reset(new boost::thread(DeletionWorker));
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
248 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
249
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
250 case OrthancPluginChangeType_OrthancStopped:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
251
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
252 if (deletionThread_.get() != NULL)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
255 continue_ = false;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
256 if (deletionThread_->joinable())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
257 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
258 deletionThread_->join();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
259 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
260 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
261
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
262 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
263
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
264 default:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
265 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
266 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
267
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
268 return OrthancPluginErrorCode_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
269 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
270
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
271
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
272
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
273 void GetPluginStatus(OrthancPluginRestOutput* output,
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
274 const char* url,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
275 const OrthancPluginHttpRequest* request)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
276 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
281
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
282 std::string s = status.toStyledString();
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
283 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
284 s.size(), "application/json");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
285 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
286
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
287
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
288
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
289 extern "C"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
290 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
291 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
292 {
5563
e02cdf358905 fix plugin init wrt logging
Alain Mazy <am@orthanc.team>
parents: 5561
diff changeset
293 OrthancPlugins::SetGlobalContext(context, ORTHANC_PLUGIN_NAME);
e02cdf358905 fix plugin init wrt logging
Alain Mazy <am@orthanc.team>
parents: 5561
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
297 /* Check the version of the Orthanc core */
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
298 if (OrthancPluginCheckVersion(context) == 0)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
299 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
300 char info[1024];
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
301 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
302 context->orthancVersion,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
303 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
304 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
305 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
306 OrthancPluginLogError(context, info);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
307 return -1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
308 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
311
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
312 OrthancPlugins::OrthancConfiguration orthancConfig;
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
313
5031
eec3e4a91663 DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents: 5024
diff changeset
314 if (!orthancConfig.IsSection(DELAYED_DELETION))
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
330 LOG(WARNING) << "DelayedDeletion - Path to the storage area: " << pathStorage;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
331
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
332 storage_.reset(new Orthanc::FilesystemStorage(pathStorage));
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
338
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
339 // This must run after the allocation of "storage_", to make sure
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
342
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
343 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
344
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
348 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
349 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
352 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
353
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
354 return 0;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
355 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
356
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
357 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
358 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
359 db_.reset();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
360 storage_.reset();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
361 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
362
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
363 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
364 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
365 return ORTHANC_PLUGIN_NAME;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
366 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
367
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
368 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
369 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
370 return ORTHANC_PLUGIN_VERSION;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
371 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
372 }