annotate Sources/ICallbackRegistration.cpp @ 151:566df919b286 cmove2

new more detailed C-Move SCP callbacks
author Alain Mazy <am@osimis.io>
date Tue, 27 Feb 2024 16:13:08 +0100
parents cf6decdf9e15
children a8408ef2b2d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Python plugin for Orthanc
114
65ec5597ec70 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium
65ec5597ec70 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
4 * Copyright (C) 2021-2023 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
5 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * 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
10 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 *
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * 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
18 **/
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #include "ICallbackRegistration.h"
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #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
24 #include "PythonLock.h"
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 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
27 PyObject* args,
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 PyObject*& singletonCallback,
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 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
30 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 // 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
32 PyObject* callback = NULL;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 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
35 callback == NULL)
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 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
38 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
39 return NULL;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 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
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 = "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
44 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
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
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 OrthancPlugins::LogInfo("Registering one " + details);
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 registration.Register();
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 singletonCallback = callback;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 Py_XINCREF(singletonCallback);
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 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
56 return Py_None;
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 }
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
119
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
61 PyObject *ICallbackRegistration::Apply2(ICallbackRegistration& registration,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
62 PyObject* args,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
63 PyObject*& singletonCallback1,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
64 PyObject*& singletonCallback2,
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
65 const std::string& details)
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
66 {
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
67 // 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
68 PyObject* callback1 = NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
69 PyObject* callback2 = NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
70
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
71 if (!PyArg_ParseTuple(args, "OO", &callback1, &callback2) ||
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
72 callback1 == NULL || callback2 == NULL)
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
73 {
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
74 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
75 PyErr_SetString(PyExc_ValueError, message.c_str());
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
76 return NULL;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
77 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
78 else if (singletonCallback1 != NULL || singletonCallback2 != 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 = "Can only register once for " + details;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
81 PyErr_SetString(PyExc_RuntimeError, 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
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 OrthancPlugins::LogInfo("Registering callbacks " + details);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
87 registration.Register();
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
88
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
89 singletonCallback1 = callback1;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
90 Py_XINCREF(singletonCallback1);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
91
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
92 singletonCallback2 = callback2;
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
93 Py_XINCREF(singletonCallback2);
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 Py_INCREF(Py_None);
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
96 return Py_None;
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 }
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
99
151
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
100 PyObject *ICallbackRegistration::Apply4(ICallbackRegistration& registration,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
101 PyObject* args,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
102 PyObject*& singletonCallback1,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
103 PyObject*& singletonCallback2,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
104 PyObject*& singletonCallback3,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
105 PyObject*& singletonCallback4,
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
106 const std::string& details)
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
107 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
108 // 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
109 PyObject* callback1 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
110 PyObject* callback2 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
111 PyObject* callback3 = NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
112 PyObject* callback4 = NULL;
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 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
115 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
116 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
117 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
118 PyErr_SetString(PyExc_ValueError, message.c_str());
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
119 return NULL;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
120 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
121 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
122 {
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
123 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
124 PyErr_SetString(PyExc_RuntimeError, 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
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 OrthancPlugins::LogInfo("Registering callbacks " + details);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
130 registration.Register();
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
131
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
132 singletonCallback1 = callback1;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
133 Py_XINCREF(singletonCallback1);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
134
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
135 singletonCallback2 = callback2;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
136 Py_XINCREF(singletonCallback2);
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 singletonCallback3 = callback3;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
139 Py_XINCREF(singletonCallback3);
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 singletonCallback4 = callback4;
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
142 Py_XINCREF(singletonCallback4);
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 Py_INCREF(Py_None);
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
145 return Py_None;
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 }
566df919b286 new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
148
119
cf6decdf9e15 wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
149
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 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
151 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 PythonLock lock;
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 if (singletonCallback != NULL)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 Py_XDECREF(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 }