Mercurial > hg > orthanc-python
annotate Sources/ReceivedInstanceCallback.cpp @ 213:f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 14:56:51 +0200 |
parents | c8de83fe7faa |
children | 3678a028f1f6 |
rev | line source |
---|---|
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 /** |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
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 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
6 * |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 * |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 * |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 **/ |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 #include "ReceivedInstanceCallback.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 |
213
f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
24 #include "PythonHeaderWrapper.h" |
f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
25 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "ICallbackRegistration.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 #include "PythonString.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
30 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
31 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 10, 0) |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
32 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 #include <Compatibility.h> // For std::unique_ptr<> |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 static PyObject* receivedInstanceCallback_ = NULL; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
38 static OrthancPluginReceivedInstanceAction ReceivedInstanceCallback( |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
39 OrthancPluginMemoryBuffer64* modifiedDicomBuffer /* out */, |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
40 const void* receivedDicomBuffer, |
103
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
41 uint64_t receivedDicomBufferSize, |
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
42 OrthancPluginInstanceOrigin origin) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 try |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 PythonLock lock; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 |
103
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
48 PythonObject args(lock, PyTuple_New(2)); |
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
49 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 PyTuple_SetItem(args.GetPyObject(), 0, PyBytes_FromStringAndSize(reinterpret_cast<const char*>(receivedDicomBuffer), receivedDicomBufferSize)); |
103
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
51 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(origin)); |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 PythonObject result(lock, PyObject_CallObject(receivedInstanceCallback_, args.GetPyObject())); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 std::string traceback; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 if (lock.HasErrorOccurred(traceback)) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
58 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python received instance callback, traceback:\n" + traceback); |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
59 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 else if (!PyTuple_Check(result.GetPyObject()) || PyTuple_Size(result.GetPyObject()) != 2) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
63 ORTHANC_PLUGINS_LOG_ERROR("The Python received instance callback has not returned a tuple as expected"); |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
64 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 else |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 PyObject* returnCode = PyTuple_GET_ITEM(result.GetPyObject(), 0); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 PyObject* modifiedDicom = PyTuple_GET_ITEM(result.GetPyObject(), 1); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 if (!PyLong_Check(returnCode)) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
73 ORTHANC_PLUGINS_LOG_ERROR("The Python received instance callback has not returned an int as the first element of the return tuple"); |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
74 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
77 OrthancPluginReceivedInstanceAction resultCode = static_cast<OrthancPluginReceivedInstanceAction>(PyLong_AsLong(returnCode)); |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
79 if (resultCode == OrthancPluginReceivedInstanceAction_KeepAsIs || |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
80 resultCode == OrthancPluginReceivedInstanceAction_Discard) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 return resultCode; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 else |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
86 char* pythonBuffer = NULL; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
87 Py_ssize_t pythonSize = 0; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
88 if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1) |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
89 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
90 ORTHANC_PLUGINS_LOG_ERROR("Cannot access the byte buffer returned by the Python received instance callback"); |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
91 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
92 } |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
93 else |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
94 { |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
95 OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, pythonSize); |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
96 |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
97 if (pythonSize != 0) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
99 if (modifiedDicomBuffer->data == NULL) |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
100 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
101 ORTHANC_PLUGINS_LOG_ERROR("Cannot allocate memory in the Python received instance callback"); |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
102 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
103 } |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
104 else |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
105 { |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
106 memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize); |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
107 } |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 } |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
109 |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
110 return OrthancPluginReceivedInstanceAction_Modify; |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
111 } |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
114 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
115 catch (OrthancPlugins::PluginException& e) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
117 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python received instance callback: " + |
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
118 std::string(e.What(OrthancPlugins::GetGlobalContext()))); |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
120 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
121 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
125 PyObject* RegisterReceivedInstanceCallback(PyObject* module, PyObject* args) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 // The GIL is locked at this point (no need to create "PythonLock") |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
128 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 class Registration : public ICallbackRegistration |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 public: |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 virtual void Register() ORTHANC_OVERRIDE |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 OrthancPluginRegisterReceivedInstanceCallback( |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 OrthancPlugins::GetGlobalContext(), ReceivedInstanceCallback); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 }; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
138 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
139 Registration registration; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
140 return ICallbackRegistration::Apply( |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
141 registration, args, receivedInstanceCallback_, "Python received instance callback"); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
142 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
143 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
144 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
145 void FinalizeReceivedInstanceCallback() |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
146 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
147 ICallbackRegistration::Unregister(receivedInstanceCallback_); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
148 } |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
149 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
150 #else |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
151 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
152 #warning OrthancPluginRegisterReceivedInstanceCallback() is not supported |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
153 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
154 PyObject* RegisterReceivedInstanceCallback(PyObject* module, PyObject* args) |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
155 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
156 PyErr_SetString(PyExc_RuntimeError, "The version of your Orthanc SDK doesn't provide OrthancPluginRegisterReceivedInstanceCallback()"); |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
157 return NULL; |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
158 } |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
159 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
160 void FinalizeReceivedInstanceCallback() |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
161 { |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
162 } |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
163 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
164 #endif |