annotate Sources/StorageArea.cpp @ 108:2389ec6ec803

preparing for release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Feb 2022 18:40:20 +0100
parents eb6ac5a801d1
children 65ec5597ec70
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
101
eb6ac5a801d1 update to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
3 * Copyright (C) 2020-2022 Osimis S.A., Belgium
eb6ac5a801d1 update to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
4 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * the License, or (at your option) any later version.
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * 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
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * Affero General Public License for more details.
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 *
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * 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
18 **/
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 #include "StorageArea.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PythonString.h"
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 static PyObject* createCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 static PyObject* readCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 static PyObject* removeCallback_ = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static OrthancPluginErrorCode RunCallback(PythonLock& lock,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 PyObject* callback,
80
ad31ac9a6fef cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 79
diff changeset
34 const PythonObject& args,
79
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 const std::string& name)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 PythonObject result(lock, PyObject_CallObject(callback, args.GetPyObject()));
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 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (lock.HasErrorOccurred(traceback))
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 OrthancPlugins::LogError("Error in the Python " + name + " callback, traceback:\n" + traceback);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 return OrthancPluginErrorCode_Plugin;
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 else
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 return OrthancPluginErrorCode_Success;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
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
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 static OrthancPluginErrorCode StorageCreate(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const void *content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 int64_t size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 OrthancPluginContentType type)
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 try
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 if (createCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(3));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 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
72
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return RunCallback(lock, createCallback_, args, "StorageCreate");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 catch (OrthancPlugins::PluginException& e)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
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
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 static OrthancPluginErrorCode StorageRead(void **content,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 int64_t *size,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 OrthancPluginContentType type)
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 try
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 if (readCallback_ == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(2));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
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 PythonObject result(lock, PyObject_CallObject(readCallback_, args.GetPyObject()));
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 std::string traceback;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (lock.HasErrorOccurred(traceback))
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 OrthancPlugins::LogError("Error in the Python StorageRead callback, traceback:\n" + traceback);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return OrthancPluginErrorCode_Plugin;
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 else if (!PyBytes_Check(result.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 OrthancPlugins::LogError("The Python StorageRead callback has not returned a byte array as expected");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 char* pythonBuffer = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 Py_ssize_t pythonSize = 0;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 if (PyBytes_AsStringAndSize(result.GetPyObject(), &pythonBuffer, &pythonSize) == 1)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 OrthancPlugins::LogError("Cannot access the byte buffer returned by the Python StorageRead callback");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 return OrthancPluginErrorCode_Plugin;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (pythonSize == 0)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 *content = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 *size = 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 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 *content = malloc(pythonSize);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 *size = pythonSize;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 if (*content == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 return OrthancPluginErrorCode_NotEnoughMemory;
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 memcpy(*content, pythonBuffer, pythonSize);
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 return OrthancPluginErrorCode_Success;
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 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 catch (OrthancPlugins::PluginException& e)
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 return e.GetErrorCode();
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 }
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 static OrthancPluginErrorCode StorageRemove(const char *uuid,
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 OrthancPluginContentType type)
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 try
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 if (removeCallback_ == NULL)
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 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
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 PythonLock lock;
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 PythonObject args(lock, PyTuple_New(2));
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 PythonString str(lock, uuid);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type));
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 return RunCallback(lock, removeCallback_, args, "StorageRemove");
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 catch (OrthancPlugins::PluginException& e)
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 return e.GetErrorCode();
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
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
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 PyObject* RegisterStorageArea(PyObject* module, PyObject* args)
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 // 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
184
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 PyObject* a = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 PyObject* b = NULL;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 PyObject* c = NULL;
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 if (!PyArg_ParseTuple(args, "OOO", &a, &b, &c) ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 a == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 b == NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 c == NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 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
195 return 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 else if (createCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 readCallback_ != NULL ||
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 removeCallback_ != NULL)
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 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
202 return 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 else
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 OrthancPlugins::LogInfo("Registering a custom storage area in Python");
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 OrthancPluginRegisterStorageArea(OrthancPlugins::GetGlobalContext(),
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 StorageCreate, StorageRead, StorageRemove);
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 createCallback_ = a;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 Py_XINCREF(createCallback_);
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 readCallback_ = b;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Py_XINCREF(readCallback_);
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 removeCallback_ = c;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 Py_XINCREF(removeCallback_);
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 Py_INCREF(Py_None);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 return Py_None;
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 }
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 void FinalizeStorageArea()
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 PythonLock lock;
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (createCallback_ != NULL)
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 Py_XDECREF(createCallback_);
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
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 if (readCallback_ != NULL)
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 Py_XDECREF(readCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
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 if (removeCallback_ != NULL)
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 Py_XDECREF(removeCallback_);
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
068551520123 New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }