Mercurial > hg > orthanc-python
annotate Sources/ICallbackRegistration.cpp @ 170:b49eeb36cd0d
removed generation of code model, now part of orthanc-java
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Jun 2024 14:26:59 +0200 |
parents | 6fada29b6759 |
children | c8de83fe7faa |
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 |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
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:
157
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
5 * 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
|
6 * |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * 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
|
8 * 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
|
9 * 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
|
10 * 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
|
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 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
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * 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
|
18 * 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
|
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 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "ICallbackRegistration.h" |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #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
|
25 #include "PythonLock.h" |
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 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
|
28 PyObject* args, |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 PyObject*& singletonCallback, |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 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
|
31 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 // 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
|
33 PyObject* callback = NULL; |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 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
|
36 callback == NULL) |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 return NULL; |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 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
|
43 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 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
|
45 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
|
46 return NULL; |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 } |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 else |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 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
|
51 registration.Register(); |
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 singletonCallback = callback; |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 Py_XINCREF(singletonCallback); |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 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
|
57 return Py_None; |
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 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
119
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
62 PyObject *ICallbackRegistration::Apply2(ICallbackRegistration& registration, |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
63 PyObject* args, |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
64 PyObject*& singletonCallback1, |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
65 PyObject*& singletonCallback2, |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
66 const std::string& details) |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
67 { |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
68 // 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
|
69 PyObject* callback1 = NULL; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
70 PyObject* callback2 = NULL; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
71 |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
72 if (!PyArg_ParseTuple(args, "OO", &callback1, &callback2) || |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
73 callback1 == NULL || callback2 == NULL) |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
74 { |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
75 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
|
76 PyErr_SetString(PyExc_ValueError, message.c_str()); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
77 return NULL; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
78 } |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
79 else if (singletonCallback1 != NULL || singletonCallback2 != NULL) |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
80 { |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
81 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
|
82 PyErr_SetString(PyExc_RuntimeError, message.c_str()); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
83 return NULL; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
84 } |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
85 else |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
86 { |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
87 OrthancPlugins::LogInfo("Registering callbacks " + details); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
88 registration.Register(); |
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 singletonCallback1 = callback1; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
91 Py_XINCREF(singletonCallback1); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
92 |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
93 singletonCallback2 = callback2; |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
94 Py_XINCREF(singletonCallback2); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
95 |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
96 Py_INCREF(Py_None); |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
97 return Py_None; |
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 } |
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
100 |
151
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
101 PyObject *ICallbackRegistration::Apply4(ICallbackRegistration& registration, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
102 PyObject* args, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
103 PyObject*& singletonCallback1, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
104 PyObject*& singletonCallback2, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
105 PyObject*& singletonCallback3, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
106 PyObject*& singletonCallback4, |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
107 const std::string& details) |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
108 { |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
109 // 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
|
110 PyObject* callback1 = NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
111 PyObject* callback2 = NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
112 PyObject* callback3 = NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
113 PyObject* callback4 = NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
114 |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
115 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
|
116 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
|
117 { |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
118 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
|
119 PyErr_SetString(PyExc_ValueError, message.c_str()); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
120 return NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
121 } |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
122 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
|
123 { |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
124 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
|
125 PyErr_SetString(PyExc_RuntimeError, message.c_str()); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
126 return NULL; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
127 } |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
128 else |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
129 { |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
130 OrthancPlugins::LogInfo("Registering callbacks " + details); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
131 registration.Register(); |
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 singletonCallback1 = callback1; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
134 Py_XINCREF(singletonCallback1); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
135 |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
136 singletonCallback2 = callback2; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
137 Py_XINCREF(singletonCallback2); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
138 |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
139 singletonCallback3 = callback3; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
140 Py_XINCREF(singletonCallback3); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
141 |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
142 singletonCallback4 = callback4; |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
143 Py_XINCREF(singletonCallback4); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
144 |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
145 Py_INCREF(Py_None); |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
146 return Py_None; |
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 } |
566df919b286
new more detailed C-Move SCP callbacks
Alain Mazy <am@osimis.io>
parents:
119
diff
changeset
|
149 |
119
cf6decdf9e15
wrapped new SDK callback: orthanc.RegisterStorageCommitmentScpCallback()
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
150 |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 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
|
152 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 PythonLock lock; |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 if (singletonCallback != NULL) |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 Py_XDECREF(singletonCallback); |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 } |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 } |