Navigation


Changeset 1014:908ffbb81f60 in freeDiameter for extensions


Ignore:
Timestamp:
Mar 29, 2013, 6:30:59 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/messages.i

    r1013 r1014  
    4141struct anscb_py_layer {
    4242        PyObject * cb;
     43        PyObject * expcb;
    4344        PyObject * data;
    4445};
     
    6768                result = PyObject_CallFunction(l->cb, "(OO)", PyMsg, l->data);
    6869                Py_XDECREF(l->cb);
     70                Py_XDECREF(l->expcb);
    6971                Py_XDECREF(l->data);
    7072                free(l);
     
    8688                /* it actually happens automatically when we do nothing. */
    8789}
     90
     91static void expcb_python(void *cbdata, DiamId_t sentto, size_t senttolen, struct msg ** msg) {
     92        /* The python callback is received in cbdata */
     93        PyObject * result, *PyMsg;
     94        struct anscb_py_layer * l = cbdata;
     95       
     96        if (!l) {
     97                fd_log_debug("Internal error! Python callback disappeared...");
     98                return;
     99        }
     100       
     101        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
     102
     103        if (!msg || !*msg) {
     104                PyMsg = Py_None;
     105        } else {
     106                PyMsg = SWIG_NewPointerObj((void *)*msg,     SWIGTYPE_p_msg,     0 );
     107        }
     108
     109        result = PyObject_CallFunction(l->expcb, "(Os#O)", PyMsg, sentto, senttolen, l->data);
     110        Py_XDECREF(l->cb);
     111        Py_XDECREF(l->expcb);
     112        Py_XDECREF(l->data);
     113        free(l);
     114
     115        /* The callback is supposed to return a message or NULL */
     116        if (!SWIG_IsOK(SWIG_ConvertPtr(result, (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) {
     117                fd_log_debug("Error: Cannot convert the return value to message.");
     118                *msg = NULL;
     119        }
     120
     121        Py_XDECREF(result);
     122
     123        SWIG_PYTHON_THREAD_END_BLOCK;
     124               
     125}
     126
     127
     128
    88129%}
    89130
     
    128169        /* SEND THE MESSAGE */
    129170        %delobject send; /* when this has been called, the msg must not be freed anymore */
    130         void send(PyObject * PyCb = NULL, PyObject * data = NULL, unsigned int timeout = 0) {
     171        void send(PyObject * PyCb = NULL, PyObject * data = NULL, PyObject * PyExpCb = NULL, unsigned int timeout = 0) {
    131172                int ret;
    132173                struct msg * m = $self;
     
    142183                        Py_XINCREF(PyCb);
    143184                        Py_XINCREF(data);
     185                        Py_XINCREF(PyExpCb);
     186                        l->expcb = PyExpCb;
    144187                        l->cb = PyCb;
    145188                        l->data = data;
     
    150193                        (void) clock_gettime(CLOCK_REALTIME, &ts);
    151194                        ts.tv_sec += timeout;
    152                         ret = fd_msg_send_timeout(&m, anscb_python, l, &ts);
     195                        ret = fd_msg_send_timeout(&m, anscb_python, l, expcb_python, &ts);
    153196                } else {
    154197                        ret = fd_msg_send(&m, PyCb ? anscb_python : NULL, l);
Note: See TracChangeset for help on using the changeset viewer.