annotate Sources/StorageArea.cpp @ 219:3678a028f1f6

making the project REUSE-compliant
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Jul 2024 18:05:11 +0200
parents 2db6c1f6417f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
219
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
1 /**
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
2 * SPDX-FileCopyrightText: 2020-2023 Osimis S.A., 2024-2024 Orthanc Team SRL, 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
3 * SPDX-License-Identifier: AGPL-3.0-or-later
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
4 */
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
5
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 /**
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * Python plugin for Orthanc
166
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
8 * Copyright (C) 2020-2023 Osimis S.A., Belgium
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
9 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
155
71d305c29cfa updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
10 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is free software: you can redistribute it and/or
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * modify it under the terms of the GNU Affero General Public License
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * as published by the Free Software Foundation, either version 3 of
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the License, or (at your option) any later version.
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful, but
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * Affero General Public License for more details.
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU Affero General Public License
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 **/
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "StorageArea.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
212
2db6c1f6417f documented orthanc.RegisterStorageArea()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
29 #include "PythonHeaderWrapper.h"
2db6c1f6417f documented orthanc.RegisterStorageArea()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
30
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "PythonString.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static PyObject* createCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 static PyObject* readCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static PyObject* removeCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 static OrthancPluginErrorCode RunCallback(PythonLock& lock,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 PyObject* callback,
80
ad31ac9a6fef cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 79
diff changeset
42 const PythonObject& args,
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 const std::string& name)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 PythonObject result(lock, PyObject_CallObject(callback, args.GetPyObject()));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if (lock.HasErrorOccurred(traceback))
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
50 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python " + name + " callback, traceback:\n" + traceback);
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return OrthancPluginErrorCode_Success;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 static OrthancPluginErrorCode StorageCreate(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 const void *content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 int64_t size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 OrthancPluginContentType type)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 try
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (createCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 PythonLock lock;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 PythonObject args(lock, PyTuple_New(3));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 PyTuple_SetItem(args.GetPyObject(), 2, PyBytes_FromStringAndSize(reinterpret_cast<const char*>(content), size));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 return RunCallback(lock, createCallback_, args, "StorageCreate");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 static OrthancPluginErrorCode StorageRead(void **content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 int64_t *size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 OrthancPluginContentType type)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 try
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if (readCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 PythonLock lock;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 PythonObject args(lock, PyTuple_New(2));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 PythonObject result(lock, PyObject_CallObject(readCallback_, args.GetPyObject()));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (lock.HasErrorOccurred(traceback))
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
115 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python StorageRead callback, traceback:\n" + traceback);
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 else if (!PyBytes_Check(result.GetPyObject()))
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
120 ORTHANC_PLUGINS_LOG_ERROR("The Python StorageRead callback has not returned a byte array as expected");
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 char* pythonBuffer = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 Py_ssize_t pythonSize = 0;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (PyBytes_AsStringAndSize(result.GetPyObject(), &pythonBuffer, &pythonSize) == 1)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
129 ORTHANC_PLUGINS_LOG_ERROR("Cannot access the byte buffer returned by the Python StorageRead callback");
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 if (pythonSize == 0)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 *content = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 *size = 0;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 *content = malloc(pythonSize);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 *size = pythonSize;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 if (*content == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return OrthancPluginErrorCode_NotEnoughMemory;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 memcpy(*content, pythonBuffer, pythonSize);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return OrthancPluginErrorCode_Success;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 static OrthancPluginErrorCode StorageRemove(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 OrthancPluginContentType type)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 try
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if (removeCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 PythonLock lock;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 PythonObject args(lock, PyTuple_New(2));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 return RunCallback(lock, removeCallback_, args, "StorageRemove");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 PyObject* RegisterStorageArea(PyObject* module, PyObject* args)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 // The GIL is locked at this point (no need to create "PythonLock")
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 PyObject* a = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 PyObject* b = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 PyObject* c = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 if (!PyArg_ParseTuple(args, "OOO", &a, &b, &c) ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 a == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 b == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 c == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 PyErr_SetString(PyExc_ValueError, "Expected three callback functions to register a custom storage area");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 else if (createCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 readCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 removeCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 PyErr_SetString(PyExc_RuntimeError, "Cannot register twice a custom storage area");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 return NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
214 ORTHANC_PLUGINS_LOG_INFO("Registering a custom storage area in Python");
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 OrthancPluginRegisterStorageArea(OrthancPlugins::GetGlobalContext(),
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 StorageCreate, StorageRead, StorageRemove);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 createCallback_ = a;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 Py_XINCREF(createCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 readCallback_ = b;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 Py_XINCREF(readCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 removeCallback_ = c;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 Py_XINCREF(removeCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 Py_INCREF(Py_None);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 return Py_None;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 void FinalizeStorageArea()
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 PythonLock lock;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 if (createCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 Py_XDECREF(createCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 if (readCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 Py_XDECREF(readCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (removeCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 Py_XDECREF(removeCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }