1-
1+ /* Provide EPICS functions in Python format */
22#define PY_SSIZE_T_CLEAN
33#include <Python.h>
44#include <string.h>
55
66#define db_accessHFORdb_accessC // Needed to get correct DBF_ values
77#include <dbAccess.h>
88#include <dbFldTypes.h>
9+ #include <callback.h>
910#include <dbStaticLib.h>
1011#include <asTrapWrite.h>
1112#include <epicsVersion.h>
1213#include <dbChannel.h>
1314#include <asTrapWrite.h>
1415#include <asDbLib.h>
1516
17+
1618/* Reference stealing version of PyDict_SetItemString */
1719static void set_dict_item_steal (
1820 PyObject * dict , const char * name , PyObject * py_value )
@@ -209,6 +211,42 @@ static PyObject *install_pv_logging(PyObject *self, PyObject *args)
209211 Py_RETURN_NONE ;
210212}
211213
214+ #define CAPSULE_NAME "ProcessDeviceSupportOut.callback"
215+
216+ static void capsule_destructor (PyObject * obj )
217+ {
218+ void * callback = PyCapsule_GetPointer (obj , CAPSULE_NAME );
219+ free (callback );
220+ }
221+
222+
223+ static PyObject * create_callback_capsule (PyObject * self , PyObject * args )
224+ {
225+ void * callback = malloc (sizeof (CALLBACK ));
226+
227+ printf ("Created CALLBACK struct %p\n" , callback );
228+
229+ return PyCapsule_New (callback , CAPSULE_NAME , & capsule_destructor );
230+ }
231+
232+ static PyObject * signal_processing_complete (PyObject * self , PyObject * args )
233+ {
234+ int priority ;
235+ dbCommon * record ;
236+ PyObject * callback_capsule ;
237+
238+ if (!PyArg_ParseTuple (args , "inO" , & priority , & record , & callback_capsule ))
239+ {
240+ return NULL ;
241+ }
242+
243+ CALLBACK * callback = PyCapsule_GetPointer (callback_capsule , CAPSULE_NAME );
244+
245+ callbackRequestProcessCallback (callback , priority , record );
246+
247+ Py_RETURN_NONE ;
248+ }
249+
212250static struct PyMethodDef softioc_methods [] = {
213251 {"get_DBF_values" , get_DBF_values , METH_VARARGS ,
214252 "Get a map of DBF names to values" },
@@ -218,6 +256,10 @@ static struct PyMethodDef softioc_methods[] = {
218256 "Put a database field to a value" },
219257 {"install_pv_logging" , install_pv_logging , METH_VARARGS ,
220258 "Install caput logging to stdout" },
259+ {"signal_processing_complete" , signal_processing_complete , METH_VARARGS ,
260+ "Inform EPICS that asynchronous record processing has completed" },
261+ {"create_callback_capsule" , create_callback_capsule , METH_VARARGS ,
262+ "Create a CALLBACK structure inside a PyCapsule" },
221263 {NULL , NULL , 0 , NULL } /* Sentinel */
222264};
223265
0 commit comments