Mercurial > hg > orthanc-python
annotate Sources/StorageArea.cpp @ 166:6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 22:27:45 +0200 |
parents | 71d305c29cfa |
children | c8de83fe7faa |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "PythonString.h" |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 static PyObject* createCallback_ = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 static PyObject* readCallback_ = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 static PyObject* removeCallback_ = NULL; |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 static OrthancPluginErrorCode RunCallback(PythonLock& lock, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 PyObject* callback, |
80 | 35 const PythonObject& args, |
79
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 const std::string& name) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 PythonObject result(lock, PyObject_CallObject(callback, args.GetPyObject())); |
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 std::string traceback; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 if (lock.HasErrorOccurred(traceback)) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 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
|
44 return OrthancPluginErrorCode_Plugin; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 else |
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 return OrthancPluginErrorCode_Success; |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 static OrthancPluginErrorCode StorageCreate(const char *uuid, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 const void *content, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 int64_t size, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 OrthancPluginContentType type) |
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 try |
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 if (createCallback_ == NULL) |
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 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 PythonLock lock; |
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 PythonObject args(lock, PyTuple_New(3)); |
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 PythonString str(lock, uuid); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 PyTuple_SetItem(args.GetPyObject(), 0, str.Release()); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type)); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 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
|
73 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 return RunCallback(lock, createCallback_, args, "StorageCreate"); |
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 catch (OrthancPlugins::PluginException& e) |
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 return e.GetErrorCode(); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 static OrthancPluginErrorCode StorageRead(void **content, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 int64_t *size, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 const char *uuid, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 OrthancPluginContentType type) |
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 try |
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 if (readCallback_ == NULL) |
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 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 PythonLock lock; |
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 PythonObject args(lock, PyTuple_New(2)); |
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 PythonString str(lock, uuid); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 PyTuple_SetItem(args.GetPyObject(), 0, str.Release()); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type)); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 PythonObject result(lock, PyObject_CallObject(readCallback_, args.GetPyObject())); |
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 std::string traceback; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 if (lock.HasErrorOccurred(traceback)) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 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
|
109 return OrthancPluginErrorCode_Plugin; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 } |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 else if (!PyBytes_Check(result.GetPyObject())) |
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 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
|
114 return OrthancPluginErrorCode_Plugin; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 } |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 else |
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 char* pythonBuffer = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 Py_ssize_t pythonSize = 0; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 if (PyBytes_AsStringAndSize(result.GetPyObject(), &pythonBuffer, &pythonSize) == 1) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 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
|
123 return OrthancPluginErrorCode_Plugin; |
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 else |
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 if (pythonSize == 0) |
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 *content = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 *size = 0; |
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 *content = malloc(pythonSize); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 *size = pythonSize; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 if (*content == NULL) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 return OrthancPluginErrorCode_NotEnoughMemory; |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 memcpy(*content, pythonBuffer, pythonSize); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 return OrthancPluginErrorCode_Success; |
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 } |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 catch (OrthancPlugins::PluginException& e) |
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 return e.GetErrorCode(); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 static OrthancPluginErrorCode StorageRemove(const char *uuid, |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 OrthancPluginContentType type) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 try |
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 if (removeCallback_ == NULL) |
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 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_InternalError); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 PythonLock lock; |
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 PythonObject args(lock, PyTuple_New(2)); |
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 PythonString str(lock, uuid); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 PyTuple_SetItem(args.GetPyObject(), 0, str.Release()); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(type)); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 return RunCallback(lock, removeCallback_, args, "StorageRemove"); |
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 catch (OrthancPlugins::PluginException& e) |
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 return e.GetErrorCode(); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 PyObject* RegisterStorageArea(PyObject* module, PyObject* args) |
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 // 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
|
185 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 PyObject* a = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 PyObject* b = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 PyObject* c = NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 if (!PyArg_ParseTuple(args, "OOO", &a, &b, &c) || |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 a == NULL || |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 b == NULL || |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 c == NULL) |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 { |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 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
|
196 return NULL; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 } |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 else if (createCallback_ != NULL || |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 readCallback_ != NULL || |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 removeCallback_ != 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_RuntimeError, "Cannot register twice 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 |
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 OrthancPlugins::LogInfo("Registering a custom storage area in Python"); |
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 OrthancPluginRegisterStorageArea(OrthancPlugins::GetGlobalContext(), |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 StorageCreate, StorageRead, StorageRemove); |
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 createCallback_ = a; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 Py_XINCREF(createCallback_); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 readCallback_ = b; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 Py_XINCREF(readCallback_); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 removeCallback_ = c; |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 Py_XINCREF(removeCallback_); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 Py_INCREF(Py_None); |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 return Py_None; |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 void FinalizeStorageArea() |
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 PythonLock lock; |
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 if (createCallback_ != NULL) |
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 Py_XDECREF(createCallback_); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 if (readCallback_ != NULL) |
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 Py_XDECREF(readCallback_); |
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 |
068551520123
New Python function: "orthanc.RegisterStorageArea()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 if (removeCallback_ != NULL) |
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 Py_XDECREF(removeCallback_); |
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 } |