annotate Sources/StorageArea.cpp @ 212:2db6c1f6417f

documented orthanc.RegisterStorageArea()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Jul 2024 14:39:25 +0200
parents c8de83fe7faa
children 3678a028f1f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Python plugin for Orthanc
166
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
3 * 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
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
155
71d305c29cfa updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
5 * 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
6 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * 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
8 * 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
9 * 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
10 * the License, or (at your option) any later version.
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 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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
15 * Affero General Public License for more details.
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 * 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
18 * 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
19 **/
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
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 #include "StorageArea.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
212
2db6c1f6417f documented orthanc.RegisterStorageArea()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
24 #include "PythonHeaderWrapper.h"
2db6c1f6417f documented orthanc.RegisterStorageArea()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
25
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "PythonString.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 static PyObject* createCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static PyObject* readCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static PyObject* removeCallback_ = NULL;
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 OrthancPluginErrorCode RunCallback(PythonLock& lock,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 PyObject* callback,
80
ad31ac9a6fef cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 79
diff changeset
37 const PythonObject& args,
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 const std::string& name)
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 PythonObject result(lock, PyObject_CallObject(callback, args.GetPyObject()));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (lock.HasErrorOccurred(traceback))
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
45 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
46 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return OrthancPluginErrorCode_Success;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
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
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 static OrthancPluginErrorCode StorageCreate(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const void *content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 int64_t size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 OrthancPluginContentType type)
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 try
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (createCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(3));
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 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 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
75
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 return RunCallback(lock, createCallback_, args, "StorageCreate");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
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
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 static OrthancPluginErrorCode StorageRead(void **content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 int64_t *size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 OrthancPluginContentType type)
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 try
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (readCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(2));
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 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 PythonObject result(lock, PyObject_CallObject(readCallback_, args.GetPyObject()));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (lock.HasErrorOccurred(traceback))
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
110 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
111 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 else if (!PyBytes_Check(result.GetPyObject()))
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("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
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 char* pythonBuffer = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 Py_ssize_t pythonSize = 0;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (PyBytes_AsStringAndSize(result.GetPyObject(), &pythonBuffer, &pythonSize) == 1)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
124 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
125 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (pythonSize == 0)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 *content = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 *size = 0;
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 else
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 = malloc(pythonSize);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 *size = pythonSize;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 if (*content == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return OrthancPluginErrorCode_NotEnoughMemory;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 memcpy(*content, pythonBuffer, pythonSize);
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return OrthancPluginErrorCode_Success;
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 }
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 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 return e.GetErrorCode();
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
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 static OrthancPluginErrorCode StorageRemove(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 OrthancPluginContentType type)
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 try
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 if (removeCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(2));
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 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 return RunCallback(lock, removeCallback_, args, "StorageRemove");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
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
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 PyObject* RegisterStorageArea(PyObject* module, PyObject* args)
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 // 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
187
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 PyObject* a = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 PyObject* b = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 PyObject* c = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 if (!PyArg_ParseTuple(args, "OOO", &a, &b, &c) ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 a == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 b == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 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 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
198 return NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 else if (createCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 readCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 removeCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 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
205 return NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
209 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
210
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 OrthancPluginRegisterStorageArea(OrthancPlugins::GetGlobalContext(),
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 StorageCreate, StorageRead, StorageRemove);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 createCallback_ = a;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Py_XINCREF(createCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 readCallback_ = b;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 Py_XINCREF(readCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 removeCallback_ = c;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 Py_XINCREF(removeCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 Py_INCREF(Py_None);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 return Py_None;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 void FinalizeStorageArea()
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 PythonLock lock;
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 if (createCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 Py_XDECREF(createCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
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 (readCallback_ != 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(readCallback_);
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 (removeCallback_ != 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(removeCallback_);
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 }