Mercurial > hg > orthanc-python
comparison 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 |
comparison
equal
deleted
inserted
replaced
150:3c98306828de | 151:566df919b286 |
---|---|
95 Py_INCREF(Py_None); | 95 Py_INCREF(Py_None); |
96 return Py_None; | 96 return Py_None; |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 PyObject *ICallbackRegistration::Apply4(ICallbackRegistration& registration, | |
101 PyObject* args, | |
102 PyObject*& singletonCallback1, | |
103 PyObject*& singletonCallback2, | |
104 PyObject*& singletonCallback3, | |
105 PyObject*& singletonCallback4, | |
106 const std::string& details) | |
107 { | |
108 // https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c | |
109 PyObject* callback1 = NULL; | |
110 PyObject* callback2 = NULL; | |
111 PyObject* callback3 = NULL; | |
112 PyObject* callback4 = NULL; | |
113 | |
114 if (!PyArg_ParseTuple(args, "OOOO", &callback1, &callback2, &callback3, &callback4) || | |
115 callback1 == NULL || callback2 == NULL || callback3 == NULL || callback4 == NULL) | |
116 { | |
117 const std::string message = "Expected 4 callback functions to register " + details; | |
118 PyErr_SetString(PyExc_ValueError, message.c_str()); | |
119 return NULL; | |
120 } | |
121 else if (singletonCallback1 != NULL || singletonCallback2 != NULL || singletonCallback3 != NULL || singletonCallback4 != NULL) | |
122 { | |
123 const std::string message = "Can only register once for " + details; | |
124 PyErr_SetString(PyExc_RuntimeError, message.c_str()); | |
125 return NULL; | |
126 } | |
127 else | |
128 { | |
129 OrthancPlugins::LogInfo("Registering callbacks " + details); | |
130 registration.Register(); | |
131 | |
132 singletonCallback1 = callback1; | |
133 Py_XINCREF(singletonCallback1); | |
134 | |
135 singletonCallback2 = callback2; | |
136 Py_XINCREF(singletonCallback2); | |
137 | |
138 singletonCallback3 = callback3; | |
139 Py_XINCREF(singletonCallback3); | |
140 | |
141 singletonCallback4 = callback4; | |
142 Py_XINCREF(singletonCallback4); | |
143 | |
144 Py_INCREF(Py_None); | |
145 return Py_None; | |
146 } | |
147 } | |
148 | |
100 | 149 |
101 void ICallbackRegistration::Unregister(PyObject*& singletonCallback) | 150 void ICallbackRegistration::Unregister(PyObject*& singletonCallback) |
102 { | 151 { |
103 PythonLock lock; | 152 PythonLock lock; |
104 | 153 |