annotate Sources/ICallbackRegistration.cpp @ 221:8e127a46128e OrthancPython-4.3

OrthancPython-4.3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jul 2024 09:37:44 +0200
parents 3678a028f1f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
219
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
1 /**
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
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: 171
diff changeset
3 * SPDX-License-Identifier: AGPL-3.0-or-later
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
4 */
3678a028f1f6 making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
5
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 /**
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
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: 157
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: 157
diff changeset
9 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
155
71d305c29cfa updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
10 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is free software: you can redistribute it and/or
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * modify it under the terms of the GNU Affero General Public License
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * as published by the Free Software Foundation, either version 3 of
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the License, or (at your option) any later version.
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful, but
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * Affero General Public License for more details.
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU Affero General Public License
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 **/
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "ICallbackRegistration.h"
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "PythonLock.h"
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 PyObject *ICallbackRegistration::Apply(ICallbackRegistration& registration,
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 PyObject* args,
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 PyObject*& singletonCallback,
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 const std::string& details)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 // https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 PyObject* callback = NULL;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (!PyArg_ParseTuple(args, "O", &callback) ||
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 callback == NULL)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 const std::string message = "Expected a callback function to register one " + details;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 PyErr_SetString(PyExc_ValueError, message.c_str());
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 return NULL;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 else if (singletonCallback != NULL)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const std::string message = "Can only register one " + details;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 PyErr_SetString(PyExc_RuntimeError, message.c_str());
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 return NULL;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 else
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
55 ORTHANC_PLUGINS_LOG_INFO("Registering one " + details);
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 registration.Register();
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 singletonCallback = callback;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 Py_XINCREF(singletonCallback);
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 Py_INCREF(Py_None);
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return Py_None;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
119
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
67 PyObject *ICallbackRegistration::Apply2(ICallbackRegistration& registration,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
68 PyObject* args,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
69 PyObject*& singletonCallback1,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
70 PyObject*& singletonCallback2,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
71 const std::string& details)
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
72 {
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
73 // https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
74 PyObject* callback1 = NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
75 PyObject* callback2 = NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
76
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
77 if (!PyArg_ParseTuple(args, "OO", &callback1, &callback2) ||
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
78 callback1 == NULL || callback2 == NULL)
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
79 {
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
80 const std::string message = "Expected two callback functions to register " + details;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
81 PyErr_SetString(PyExc_ValueError, message.c_str());
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
82 return NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
83 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
84 else if (singletonCallback1 != NULL || singletonCallback2 != NULL)
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
85 {
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
86 const std::string message = "Can only register once for " + details;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
87 PyErr_SetString(PyExc_RuntimeError, message.c_str());
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
88 return NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
89 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
90 else
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
91 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
92 ORTHANC_PLUGINS_LOG_INFO("Registering callbacks " + details);
119
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
93 registration.Register();
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
94
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
95 singletonCallback1 = callback1;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
96 Py_XINCREF(singletonCallback1);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
97
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
98 singletonCallback2 = callback2;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
99 Py_XINCREF(singletonCallback2);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
100
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
101 Py_INCREF(Py_None);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
102 return Py_None;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
103 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
104 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
105
151
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
106 PyObject *ICallbackRegistration::Apply4(ICallbackRegistration& registration,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
107 PyObject* args,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
108 PyObject*& singletonCallback1,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
109 PyObject*& singletonCallback2,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
110 PyObject*& singletonCallback3,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
111 PyObject*& singletonCallback4,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
112 const std::string& details)
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
113 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
114 // https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
115 PyObject* callback1 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
116 PyObject* callback2 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
117 PyObject* callback3 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
118 PyObject* callback4 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
119
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
120 if (!PyArg_ParseTuple(args, "OOOO", &callback1, &callback2, &callback3, &callback4) ||
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
121 callback1 == NULL || callback2 == NULL || callback3 == NULL || callback4 == NULL)
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
122 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
123 const std::string message = "Expected 4 callback functions to register " + details;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
124 PyErr_SetString(PyExc_ValueError, message.c_str());
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
125 return NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
126 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
127 else if (singletonCallback1 != NULL || singletonCallback2 != NULL || singletonCallback3 != NULL || singletonCallback4 != NULL)
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
128 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
129 const std::string message = "Can only register once for " + details;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
130 PyErr_SetString(PyExc_RuntimeError, message.c_str());
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
131 return NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
132 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
133 else
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
134 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
135 ORTHANC_PLUGINS_LOG_INFO("Registering callbacks " + details);
151
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
136 registration.Register();
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
137
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
138 singletonCallback1 = callback1;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
139 Py_XINCREF(singletonCallback1);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
140
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
141 singletonCallback2 = callback2;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
142 Py_XINCREF(singletonCallback2);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
143
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
144 singletonCallback3 = callback3;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
145 Py_XINCREF(singletonCallback3);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
146
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
147 singletonCallback4 = callback4;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
148 Py_XINCREF(singletonCallback4);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
149
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
150 Py_INCREF(Py_None);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
151 return Py_None;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
152 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
153 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
154
119
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
155
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 void ICallbackRegistration::Unregister(PyObject*& singletonCallback)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 PythonLock lock;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (singletonCallback != NULL)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 Py_XDECREF(singletonCallback);
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }