hooks work
This commit is contained in:
@ -127,31 +127,34 @@ static void pyhook(initHookState state)
|
|||||||
PyObject *list = PyDict_GetItem(hooktable, key);
|
PyObject *list = PyDict_GetItem(hooktable, key);
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
|
|
||||||
list = PyObject_GetIter(list);
|
if(list) {
|
||||||
if(!list) {
|
|
||||||
fprintf(stderr, "hook sequence not iterable!");
|
|
||||||
|
|
||||||
} else {
|
list = PyObject_GetIter(list);
|
||||||
|
if(!list) {
|
||||||
|
fprintf(stderr, "hook sequence not iterable!");
|
||||||
|
|
||||||
while((next=PyIter_Next(list))!=NULL) {
|
} else {
|
||||||
PyObject *obj;
|
|
||||||
if(!PyCallable_Check(next))
|
while((next=PyIter_Next(list))!=NULL) {
|
||||||
continue;
|
PyObject *obj;
|
||||||
obj = PyObject_CallFunction(next, "O", key);
|
if(!PyCallable_Check(next))
|
||||||
Py_DECREF(next);
|
continue;
|
||||||
if(obj)
|
obj = PyObject_CallFunction(next, "");
|
||||||
Py_DECREF(obj);
|
Py_DECREF(next);
|
||||||
else {
|
if(obj)
|
||||||
|
Py_DECREF(obj);
|
||||||
|
else {
|
||||||
|
PyErr_Print();
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!PyErr_Occurred()) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
PyErr_Clear();
|
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 */
|
/* initialize "magic" builtin module */
|
||||||
static void init_dbapi(void)
|
static void init_dbapi(void)
|
||||||
{
|
{
|
||||||
PyObject *mod;
|
PyObject *mod, *hookdict;
|
||||||
pystate *st;
|
pystate *st;
|
||||||
|
PyGILState_STATE state;
|
||||||
|
|
||||||
|
state = PyGILState_Ensure();
|
||||||
|
|
||||||
hooktable = PyDict_New();
|
hooktable = PyDict_New();
|
||||||
if(!hooktable)
|
if(!hooktable)
|
||||||
@ -195,14 +201,21 @@ static void init_dbapi(void)
|
|||||||
|
|
||||||
mod = Py_InitModule("_dbapi", devsup_methods);
|
mod = Py_InitModule("_dbapi", devsup_methods);
|
||||||
|
|
||||||
|
hookdict = PyDict_New();
|
||||||
|
if(!hookdict)
|
||||||
|
return;
|
||||||
|
PyModule_AddObject(mod, "_hooks", hookdict);
|
||||||
|
|
||||||
for(st = statenames; st->name; st++) {
|
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 */
|
Py_INCREF(hooktable); /* an extra ref */
|
||||||
PyModule_AddObject(mod, "_hooktable", hooktable);
|
PyModule_AddObject(mod, "_hooktable", hooktable);
|
||||||
|
|
||||||
pyField_setup(mod);
|
pyField_setup(mod);
|
||||||
pyRecord_setup(mod);
|
pyRecord_setup(mod);
|
||||||
|
|
||||||
|
PyGILState_Release(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iocsh.h>
|
#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
|
#!./bin/linux-x86-debug/devsup
|
||||||
|
|
||||||
|
epicsEnvSet("PYTHONPATH", "${PWD}/python")
|
||||||
|
|
||||||
dbLoadDatabase("dbd/devsup.dbd")
|
dbLoadDatabase("dbd/devsup.dbd")
|
||||||
devsup_registerRecordDeviceDriver(pdbbase)
|
devsup_registerRecordDeviceDriver(pdbbase)
|
||||||
|
|
||||||
evalPy "print 1"
|
evalPy "import sys"
|
||||||
evalPy "print 2"
|
evalPy "print sys.path"
|
||||||
|
evalPy "import devsup.hooks"
|
||||||
|
evalPy "devsup.hooks.debugHooks()"
|
||||||
|
|
||||||
|
iocInit
|
||||||
|
Reference in New Issue
Block a user