Mercurial > hg > orthanc-python
annotate Sources/ReceivedInstanceCallback.cpp @ 227:9574f06d8588 default tip
todo
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 08:54:11 +0200 |
parents | 3678a028f1f6 |
children |
rev | line source |
---|---|
219
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
1 /** |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
2 * SPDX-FileCopyrightText: 2020-2023 Osimis S.A., 2024-2024 Orthanc Team SRL, 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
3 * SPDX-License-Identifier: AGPL-3.0-or-later |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
4 */ |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
5 |
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 * Python plugin for Orthanc |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
8 * 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
|
9 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
114
diff
changeset
|
10 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
99
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 free software: you can redistribute it and/or |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * 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
|
14 * as published by the Free Software Foundation, either version 3 of |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * the License, or (at your option) any later version. |
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 * 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
|
18 * WITHOUT ANY WARRANTY; without even the implied warranty of |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 * Affero General Public License for more details. |
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 * 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
|
23 * 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
|
24 **/ |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "ReceivedInstanceCallback.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 |
213
f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
29 #include "PythonHeaderWrapper.h" |
f8dc8dd2da76
documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
30 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 #include "ICallbackRegistration.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 #include "PythonString.h" |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
35 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
36 #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
|
37 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 #include <Compatibility.h> // For std::unique_ptr<> |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 static PyObject* receivedInstanceCallback_ = NULL; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
43 static OrthancPluginReceivedInstanceAction ReceivedInstanceCallback( |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
44 OrthancPluginMemoryBuffer64* modifiedDicomBuffer /* out */, |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
45 const void* receivedDicomBuffer, |
103
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
46 uint64_t receivedDicomBufferSize, |
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
47 OrthancPluginInstanceOrigin origin) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 try |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 PythonLock lock; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 |
103
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
53 PythonObject args(lock, PyTuple_New(2)); |
d2259c4cd677
added origin in ReceivedInstanceCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
54 |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 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
|
56 PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(origin)); |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 PythonObject result(lock, PyObject_CallObject(receivedInstanceCallback_, args.GetPyObject())); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 std::string traceback; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 if (lock.HasErrorOccurred(traceback)) |
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("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
|
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 if (!PyTuple_Check(result.GetPyObject()) || PyTuple_Size(result.GetPyObject()) != 2) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
68 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
|
69 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
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 else |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 PyObject* returnCode = PyTuple_GET_ITEM(result.GetPyObject(), 0); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 PyObject* modifiedDicom = PyTuple_GET_ITEM(result.GetPyObject(), 1); |
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 if (!PyLong_Check(returnCode)) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
78 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
|
79 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
82 OrthancPluginReceivedInstanceAction resultCode = static_cast<OrthancPluginReceivedInstanceAction>(PyLong_AsLong(returnCode)); |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
84 if (resultCode == OrthancPluginReceivedInstanceAction_KeepAsIs || |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
85 resultCode == OrthancPluginReceivedInstanceAction_Discard) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 return resultCode; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 else |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
91 char* pythonBuffer = NULL; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
92 Py_ssize_t pythonSize = 0; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
93 if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1) |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
94 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
95 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
|
96 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
97 } |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
98 else |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
99 { |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
100 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
|
101 |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
102 if (pythonSize != 0) |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
104 if (modifiedDicomBuffer->data == NULL) |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
105 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
106 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
|
107 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
108 } |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
109 else |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
110 { |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
111 memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize); |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
112 } |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 } |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
114 |
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
115 return OrthancPluginReceivedInstanceAction_Modify; |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
116 } |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 } |
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 catch (OrthancPlugins::PluginException& e) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
122 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
|
123 std::string(e.What(OrthancPlugins::GetGlobalContext()))); |
99
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 |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
126 return OrthancPluginReceivedInstanceAction_KeepAsIs; |
99
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 } |
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 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 PyObject* RegisterReceivedInstanceCallback(PyObject* module, PyObject* args) |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 // 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
|
133 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 class Registration : public ICallbackRegistration |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 public: |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 virtual void Register() ORTHANC_OVERRIDE |
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 OrthancPluginRegisterReceivedInstanceCallback( |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
140 OrthancPlugins::GetGlobalContext(), ReceivedInstanceCallback); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
141 } |
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 Registration registration; |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
145 return ICallbackRegistration::Apply( |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
146 registration, args, receivedInstanceCallback_, "Python received instance callback"); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
147 } |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
148 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
149 |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
150 void FinalizeReceivedInstanceCallback() |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
151 { |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
152 ICallbackRegistration::Unregister(receivedInstanceCallback_); |
465bf098554b
new callback: orthanc.RegisterReceivedInstanceCallback()
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
153 } |
100
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
154 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
155 #else |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
156 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
157 #warning OrthancPluginRegisterReceivedInstanceCallback() is not supported |
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 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
|
160 { |
102
ed994991a20b
improved error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
161 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
|
162 return NULL; |
100
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 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
165 void FinalizeReceivedInstanceCallback() |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
166 { |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
167 } |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
168 |
e2b2e1d4e1bb
fixed compatibility with Orthanc SDK 1.8.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
99
diff
changeset
|
169 #endif |