Navigation


Changeset 639:95a784729cac in freeDiameter for extensions/dbg_interactive


Ignore:
Timestamp:
Dec 20, 2010, 1:07:06 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.

Location:
extensions/dbg_interactive
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/dbg_interactive.c

    r625 r639  
    6767       
    6868end:   
    69         /* Upon exit, issue the order of terminating to fD */
    70         CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
     69        /* Upon exit, issue the order of terminating to fD, if the interpreter was started without a file */
     70        if (!arg) {
     71                CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
     72        }
    7173
    7274        return NULL;
  • extensions/dbg_interactive/dispatch.i

    r638 r639  
    4040
    4141%{
    42 /* store the python callback function here */
    43 static PyObject * py_dispatch_cb = NULL;
    44 static int        py_dispatch_cb_n = 0;
    4542/* 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) {
     43static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp, struct session *session, void * pycb, enum disp_action *action) {
    4744        PyObject *PyMsg, *PyAvp, *PySess;
    48         PyObject *result = NULL;
     45        PyObject *cb, *result = NULL;
    4946        int ret = 0;
    5047       
    51         if (!py_dispatch_cb)
     48        if (!pycb) {
     49                fd_log_debug("Internal error: missing the callback!\n");
    5250                return ENOTSUP;
     51        }
     52        cb = pycb;
    5353       
    5454        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
     
    5959       
    6060        /* Call the function */
    61         result = PyEval_CallFunction(py_dispatch_cb, "(OOO)", PyMsg, PyAvp, PySess);
     61        result = PyEval_CallFunction(cb, "(OOO)", PyMsg, PyAvp, PySess);
    6262       
    6363        /* The result is supposedly composed of: [ ret, *msg, *action ] */
     
    108108                struct disp_hdl * hdl = NULL;
    109109                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);
    117110               
    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 );
    119114                if (ret != 0) {
    120115                        DI_ERROR(ret, NULL, NULL);
     
    125120        ~disp_hdl() {
    126121                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);
    128124                if (ret != 0) {
    129125                        DI_ERROR(ret, NULL, NULL);
    130126                }
    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);
    136128                return;
    137129        }
  • extensions/dbg_interactive/sessions.i

    r638 r639  
    3939
    4040%{
    41 /* store the python callback function here */
    42 static PyObject * py_cleanup_cb = NULL;
    4341/* call it (might be called from a different thread than the interpreter, when session times out) */
    44 static void call_the_python_cleanup_callback(session_state * state, char * sid) {
     42static void call_the_python_cleanup_callback(session_state * state, char * sid, void * cb) {
    4543        PyObject *result;
    46         if (!py_cleanup_cb)
     44        if (!cb) {
     45                fd_log_debug("Internal error: missing callback object!\n");
    4746                return;
     47        }
    4848       
    4949        /* Call the function */
    5050        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    51         result = PyEval_CallFunction(py_cleanup_cb, "(Os)", state, sid);
     51        result = PyEval_CallFunction((PyObject *)cb, "(Os)", state, sid);
    5252        Py_XDECREF(result);
    5353        SWIG_PYTHON_THREAD_END_BLOCK;
     
    6464                struct session_handler * hdl = NULL;
    6565                int ret;
    66                 if (py_cleanup_cb) {
    67                         DI_ERROR(EINVAL, PyExc_SyntaxError, "Only one session handler at a time is supported at the moment in this extension\n.");
    68                         return NULL;
    69                 }
    70                 py_cleanup_cb = PyCb;
    71                 Py_XINCREF(py_cleanup_cb);
    7266               
    73                 ret = fd_sess_handler_create_internal ( &hdl, call_the_python_cleanup_callback );
     67                Py_XINCREF(PyCb);
     68               
     69                ret = fd_sess_handler_create_internal ( &hdl, call_the_python_cleanup_callback, PyCb );
    7470                if (ret != 0) {
    7571                        DI_ERROR(ret, NULL, NULL);
     
    8076        ~session_handler() {
    8177                struct session_handler * hdl = self;
    82                 int ret = fd_sess_handler_destroy(&hdl);
     78                PyObject * cb = NULL;
     79               
     80                int ret = fd_sess_handler_destroy(&hdl, (void *)&cb);
    8381                if (ret != 0) {
    8482                        DI_ERROR(ret, NULL, NULL);
    8583                }
    8684                /* Now free the callback */
    87                 Py_XDECREF(py_cleanup_cb);
    88                 py_cleanup_cb = NULL;
     85                Py_XDECREF(cb);
    8986                return;
    9087        }
Note: See TracChangeset for help on using the changeset viewer.