Navigation



Ignore:
Timestamp:
Jan 5, 2011, 5:13:34 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Implemented fd_msg_send_timeout to close #10. Not tested yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/messages.i

    r640 r649  
    5555        }
    5656       
    57         SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    58        
    59         if (!msg || !*msg) {
    60                 PyMsg = Py_None;
    61         } else {
    62                 PyMsg = SWIG_NewPointerObj((void *)*msg,     SWIGTYPE_p_msg,     0 );
    63         }
    64        
    65         result = PyEval_CallFunction(l->cb, "(OO)", PyMsg, l->data);
    66         Py_XDECREF(l->cb);
    67         Py_XDECREF(l->data);
    68         free(l);
    69        
    70         /* The callback is supposed to return a message or NULL */
    71         if (!SWIG_IsOK(SWIG_ConvertPtr(result, (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) {
    72                 fd_log_debug("Error: Cannot convert the return value to message.\n");
    73                 *msg = NULL;
    74         }
    75        
    76         Py_XDECREF(result);
    77        
    78         SWIG_PYTHON_THREAD_END_BLOCK;
    79        
     57        if (l->cb) {
     58       
     59                SWIG_PYTHON_THREAD_BEGIN_BLOCK;
     60
     61                if (!msg || !*msg) {
     62                        PyMsg = Py_None;
     63                } else {
     64                        PyMsg = SWIG_NewPointerObj((void *)*msg,     SWIGTYPE_p_msg,     0 );
     65                }
     66
     67                result = PyEval_CallFunction(l->cb, "(OO)", PyMsg, l->data);
     68                Py_XDECREF(l->cb);
     69                Py_XDECREF(l->data);
     70                free(l);
     71
     72                /* The callback is supposed to return a message or NULL */
     73                if (!SWIG_IsOK(SWIG_ConvertPtr(result, (void *)msg, SWIGTYPE_p_msg, SWIG_POINTER_DISOWN))) {
     74                        fd_log_debug("Error: Cannot convert the return value to message.\n");
     75                        *msg = NULL;
     76                }
     77
     78                Py_XDECREF(result);
     79
     80                SWIG_PYTHON_THREAD_END_BLOCK;
     81               
     82        }
     83        /* else */
     84                /* Only the timeout was specified, without a callback */
     85                /* in this case, just delete the message */
     86                /* it actually happens automatically when we do nothing. */
    8087}
    8188%}
     
    121128        /* SEND THE MESSAGE */
    122129        %delobject send; /* when this has been called, the msg must not be freed anymore */
    123         void send(PyObject * PyCb = NULL, PyObject * data = NULL) {
     130        void send(PyObject * PyCb = NULL, PyObject * data = NULL, unsigned int timeout = 0) {
    124131                int ret;
    125132                struct msg * m = $self;
    126133                struct anscb_py_layer * l = NULL;
    127134               
    128                 if (PyCb) {
     135                if (PyCb || timeout) {
    129136                        l = malloc(sizeof(struct anscb_py_layer));
    130137                        if (!l) {
     
    139146                }
    140147               
    141                 ret = fd_msg_send(&m, PyCb ? anscb_python : NULL, l);
     148                if (timeout) {
     149                        struct timespec ts;
     150                        (void) clock_gettime(CLOCK_REALTIME, &ts);
     151                        ts.tv_sec += timeout;
     152                        ret = fd_msg_send_timeout(&m, anscb_python, l, &ts);
     153                } else {
     154                        ret = fd_msg_send(&m, PyCb ? anscb_python : NULL, l);
     155                }
    142156                if (ret != 0) {
    143157                        DI_ERROR(ret, NULL, NULL);
     
    303317        }
    304318       
     319        /* Is request? (shortcut) */
     320        PyObject * is_request() {
     321                PyObject * r;
     322                int ret;
     323                struct msg_hdr * h;
     324               
     325                ret = fd_msg_hdr($self, &h);
     326                if (ret != 0) {
     327                        DI_ERROR(ret, NULL, NULL);
     328                }
     329                if (h->msg_flags & CMD_FLAG_REQUEST)
     330                        r = Py_True;
     331                else
     332                        r = Py_False;
     333                Py_XINCREF(r);
     334                return r;
     335        }
     336       
    305337        /* Get the source */
    306338        char *source() {
Note: See TracChangeset for help on using the changeset viewer.