hooks work
This commit is contained in:
@ -127,31 +127,34 @@ static void pyhook(initHookState state)
|
||||
PyObject *list = PyDict_GetItem(hooktable, key);
|
||||
Py_DECREF(key);
|
||||
|
||||
list = PyObject_GetIter(list);
|
||||
if(!list) {
|
||||
fprintf(stderr, "hook sequence not iterable!");
|
||||
if(list) {
|
||||
|
||||
} else {
|
||||
list = PyObject_GetIter(list);
|
||||
if(!list) {
|
||||
fprintf(stderr, "hook sequence not iterable!");
|
||||
|
||||
while((next=PyIter_Next(list))!=NULL) {
|
||||
PyObject *obj;
|
||||
if(!PyCallable_Check(next))
|
||||
continue;
|
||||
obj = PyObject_CallFunction(next, "O", key);
|
||||
Py_DECREF(next);
|
||||
if(obj)
|
||||
Py_DECREF(obj);
|
||||
else {
|
||||
} else {
|
||||
|
||||
while((next=PyIter_Next(list))!=NULL) {
|
||||
PyObject *obj;
|
||||
if(!PyCallable_Check(next))
|
||||
continue;
|
||||
obj = PyObject_CallFunction(next, "");
|
||||
Py_DECREF(next);
|
||||
if(obj)
|
||||
Py_DECREF(obj);
|
||||
else {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
if(!PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
if(!PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
Py_DECREF(list);
|
||||
Py_DECREF(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,8 +184,11 @@ void pyRecord_setup(PyObject *module);
|
||||
/* initialize "magic" builtin module */
|
||||
static void init_dbapi(void)
|
||||
{
|
||||
PyObject *mod;
|
||||
PyObject *mod, *hookdict;
|
||||
pystate *st;
|
||||
PyGILState_STATE state;
|
||||
|
||||
state = PyGILState_Ensure();
|
||||
|
||||
hooktable = PyDict_New();
|
||||
if(!hooktable)
|
||||
@ -195,14 +201,21 @@ static void init_dbapi(void)
|
||||
|
||||
mod = Py_InitModule("_dbapi", devsup_methods);
|
||||
|
||||
hookdict = PyDict_New();
|
||||
if(!hookdict)
|
||||
return;
|
||||
PyModule_AddObject(mod, "_hooks", hookdict);
|
||||
|
||||
for(st = statenames; st->name; st++) {
|
||||
PyModule_AddIntConstant(mod, st->name, (long)st->state);
|
||||
PyDict_SetItemString(hookdict, st->name, PyInt_FromLong((long)st->state));
|
||||
}
|
||||
Py_INCREF(hooktable); /* an extra ref */
|
||||
PyModule_AddObject(mod, "_hooktable", hooktable);
|
||||
|
||||
pyField_setup(mod);
|
||||
pyRecord_setup(mod);
|
||||
|
||||
PyGILState_Release(state);
|
||||
}
|
||||
|
||||
#include <iocsh.h>
|
||||
|
0
python/devsup/__init__.py
Normal file
0
python/devsup/__init__.py
Normal file
36
python/devsup/hooks.py
Normal file
36
python/devsup/hooks.py
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
from _dbapi import _hooks, _hooktable
|
||||
|
||||
__all__ = [
|
||||
"hooknames",
|
||||
"addHook",
|
||||
"debugHooks",
|
||||
]
|
||||
|
||||
hooknames = _hooks.keys()
|
||||
|
||||
def addHook(state, func):
|
||||
"""addHook("stats", funcion)
|
||||
Add callback function to IOC start sequence.
|
||||
|
||||
def show():
|
||||
print 'State Occurred'
|
||||
addHook("AfterIocRunning", show)
|
||||
"""
|
||||
sid = _hooks[state]
|
||||
try:
|
||||
slist = _hooktable[sid]
|
||||
except KeyError:
|
||||
slist = []
|
||||
_hooktable[sid] = slist
|
||||
|
||||
slist.append(func)
|
||||
|
||||
|
||||
def debugHooks():
|
||||
"""Install debugging print to hooks
|
||||
"""
|
||||
for h in hooknames:
|
||||
def _showstate(state=h):
|
||||
print 'Reached state',state
|
||||
addHook(h, _showstate)
|
11
test.cmd
11
test.cmd
@ -1,6 +1,13 @@
|
||||
#!./bin/linux-x86-debug/devsup
|
||||
|
||||
epicsEnvSet("PYTHONPATH", "${PWD}/python")
|
||||
|
||||
dbLoadDatabase("dbd/devsup.dbd")
|
||||
devsup_registerRecordDeviceDriver(pdbbase)
|
||||
|
||||
evalPy "print 1"
|
||||
evalPy "print 2"
|
||||
evalPy "import sys"
|
||||
evalPy "print sys.path"
|
||||
evalPy "import devsup.hooks"
|
||||
evalPy "devsup.hooks.debugHooks()"
|
||||
|
||||
iocInit
|
||||
|
Reference in New Issue
Block a user