Changeset 639:95a784729cac in freeDiameter for extensions/dbg_interactive/dispatch.i
- Timestamp:
- Dec 20, 2010, 1:07:06 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/dbg_interactive/dispatch.i
r638 r639 40 40 41 41 %{ 42 /* store the python callback function here */43 static PyObject * py_dispatch_cb = NULL;44 static int py_dispatch_cb_n = 0;45 42 /* call it (will be called from a different thread than the interpreter, when message arrives) */ 46 static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp, struct session *session, enum disp_action *action) {43 static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp, struct session *session, void * pycb, enum disp_action *action) { 47 44 PyObject *PyMsg, *PyAvp, *PySess; 48 PyObject * result = NULL;45 PyObject *cb, *result = NULL; 49 46 int ret = 0; 50 47 51 if (!py_dispatch_cb) 48 if (!pycb) { 49 fd_log_debug("Internal error: missing the callback!\n"); 52 50 return ENOTSUP; 51 } 52 cb = pycb; 53 53 54 54 SWIG_PYTHON_THREAD_BEGIN_BLOCK; … … 59 59 60 60 /* Call the function */ 61 result = PyEval_CallFunction( py_dispatch_cb, "(OOO)", PyMsg, PyAvp, PySess);61 result = PyEval_CallFunction(cb, "(OOO)", PyMsg, PyAvp, PySess); 62 62 63 63 /* The result is supposedly composed of: [ ret, *msg, *action ] */ … … 108 108 struct disp_hdl * hdl = NULL; 109 109 int ret; 110 if (py_dispatch_cb && (py_dispatch_cb != PyCb)) {111 DI_ERROR(EINVAL, PyExc_SyntaxError, "Only one dispatch callback is supported at the moment in this extension\n.");112 return NULL;113 }114 py_dispatch_cb = PyCb;115 py_dispatch_cb_n += 1;116 Py_XINCREF(py_dispatch_cb);117 110 118 ret = fd_disp_register ( call_the_python_dispatch_callback, how, when, &hdl ); 111 Py_XINCREF(PyCb); 112 113 ret = fd_disp_register ( call_the_python_dispatch_callback, how, when, PyCb, &hdl ); 119 114 if (ret != 0) { 120 115 DI_ERROR(ret, NULL, NULL); … … 125 120 ~disp_hdl() { 126 121 struct disp_hdl * hdl = self; 127 int ret = fd_disp_unregister(&hdl); 122 PyObject * cb = NULL; 123 int ret = fd_disp_unregister(&hdl, (void *)&cb); 128 124 if (ret != 0) { 129 125 DI_ERROR(ret, NULL, NULL); 130 126 } 131 /* Now free the callback */ 132 Py_XDECREF(py_dispatch_cb); 133 py_dispatch_cb_n -= 1; 134 if (!py_dispatch_cb_n) 135 py_dispatch_cb = NULL; 127 Py_XDECREF(cb); 136 128 return; 137 129 }
Note: See TracChangeset
for help on using the changeset viewer.