Mercurial > hg > orthanc-python
comparison Sources/Plugin.cpp @ 63:32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jun 2021 18:19:27 +0200 |
parents | 23f3099bed47 |
children | 091fb1903bfc |
comparison
equal
deleted
inserted
replaced
62:d82eef8c98fc | 63:32de70a1e4c7 |
---|---|
22 | 22 |
23 // https://www.codevate.com/blog/7-concurrency-with-embedded-python-in-a-multi-threaded-c-application | 23 // https://www.codevate.com/blog/7-concurrency-with-embedded-python-in-a-multi-threaded-c-application |
24 // https://fr.slideshare.net/YiLungTsai/embed-python | 24 // https://fr.slideshare.net/YiLungTsai/embed-python |
25 | 25 |
26 | 26 |
27 #include "DicomScpCallbacks.h" | |
27 #include "IncomingHttpRequestFilter.h" | 28 #include "IncomingHttpRequestFilter.h" |
28 #include "OnChangeCallback.h" | 29 #include "OnChangeCallback.h" |
29 #include "OnStoredInstanceCallback.h" | 30 #include "OnStoredInstanceCallback.h" |
30 | 31 |
31 #include "RestCallbacks.h" | 32 #include "RestCallbacks.h" |
49 # define HAS_DL_ITERATE 1 | 50 # define HAS_DL_ITERATE 1 |
50 #endif | 51 #endif |
51 | 52 |
52 | 53 |
53 | 54 |
55 PyObject* CreateDicom(PyObject* module, PyObject* args) | |
56 { | |
57 // The GIL is locked at this point (no need to create "PythonLock") | |
58 const char* json = NULL; | |
59 PyObject* pixelData = NULL; | |
60 long int flags = 0; | |
61 | |
62 if (!PyArg_ParseTuple(args, "sOl", &json, &pixelData, &flags)) | |
63 { | |
64 PyErr_SetString(PyExc_TypeError, "Please provide a JSON string, an orthanc.Image object, and a set of orthanc.CreateDicomFlags"); | |
65 return NULL; | |
66 } | |
67 else | |
68 { | |
69 OrthancPluginImage* image = NULL; | |
70 | |
71 if (pixelData == Py_None) | |
72 { | |
73 // No pixel data | |
74 } | |
75 else if (Py_TYPE(pixelData) == GetOrthancPluginImageType()) | |
76 { | |
77 image = reinterpret_cast<sdk_OrthancPluginImage_Object*>(pixelData)->object_; | |
78 } | |
79 else | |
80 { | |
81 PyErr_SetString(PyExc_TypeError, "Second parameter is not a valid orthanc.Image"); | |
82 return NULL; | |
83 } | |
84 | |
85 OrthancPlugins::MemoryBuffer buffer; | |
86 OrthancPluginErrorCode code = OrthancPluginCreateDicom(OrthancPlugins::GetGlobalContext(), *buffer, json, image, | |
87 static_cast<OrthancPluginCreateDicomFlags>(flags)); | |
88 | |
89 if (code == OrthancPluginErrorCode_Success) | |
90 { | |
91 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); | |
92 } | |
93 else | |
94 { | |
95 PyErr_SetString(PyExc_ValueError, "Cannot create the DICOM instance"); | |
96 return NULL; | |
97 } | |
98 } | |
99 } | |
100 | |
101 | |
102 | |
54 static bool pythonEnabled_ = false; | 103 static bool pythonEnabled_ = false; |
55 static std::string userScriptName_; | 104 static std::string userScriptName_; |
56 static std::vector<PyMethodDef> globalFunctions_; | 105 static std::vector<PyMethodDef> globalFunctions_; |
57 | 106 |
58 | 107 |
89 PyMethodDef f = { "RegisterOnStoredInstanceCallback", RegisterOnStoredInstanceCallback, | 138 PyMethodDef f = { "RegisterOnStoredInstanceCallback", RegisterOnStoredInstanceCallback, |
90 METH_VARARGS, "" }; | 139 METH_VARARGS, "" }; |
91 functions.push_back(f); | 140 functions.push_back(f); |
92 } | 141 } |
93 | 142 |
94 { | 143 |
95 // New in release 3.0 | 144 /** |
145 * New in release 3.0 | |
146 **/ | |
147 | |
148 { | |
96 PyMethodDef f = { "RegisterIncomingHttpRequestFilter", RegisterIncomingHttpRequestFilter, METH_VARARGS, "" }; | 149 PyMethodDef f = { "RegisterIncomingHttpRequestFilter", RegisterIncomingHttpRequestFilter, METH_VARARGS, "" }; |
97 functions.push_back(f); | 150 functions.push_back(f); |
98 } | 151 } |
152 | |
153 | |
154 /** | |
155 * New in release 3.1 | |
156 **/ | |
157 | |
158 { | |
159 PyMethodDef f = { "CreateDicom", CreateDicom, METH_VARARGS, "" }; | |
160 functions.push_back(f); | |
161 } | |
162 | |
163 { | |
164 PyMethodDef f = { "RegisterFindCallback", RegisterFindCallback, METH_VARARGS, "" }; | |
165 functions.push_back(f); | |
166 } | |
167 | |
168 { | |
169 PyMethodDef f = { "RegisterMoveCallback", RegisterMoveCallback, METH_VARARGS, "" }; | |
170 functions.push_back(f); | |
171 } | |
172 | |
99 | 173 |
100 /** | 174 /** |
101 * Append all the global functions that were automatically generated | 175 * Append all the global functions that were automatically generated |
102 **/ | 176 **/ |
103 | 177 |
296 { | 370 { |
297 FinalizeOnChangeCallback(); | 371 FinalizeOnChangeCallback(); |
298 FinalizeRestCallbacks(); | 372 FinalizeRestCallbacks(); |
299 FinalizeOnStoredInstanceCallback(); | 373 FinalizeOnStoredInstanceCallback(); |
300 FinalizeIncomingHttpRequestFilter(); | 374 FinalizeIncomingHttpRequestFilter(); |
375 FinalizeDicomScpCallbacks(); | |
301 | 376 |
302 PythonLock::GlobalFinalize(); | 377 PythonLock::GlobalFinalize(); |
303 } | 378 } |
304 } | 379 } |
305 | 380 |