Navigation



Ignore:
Timestamp:
Dec 17, 2010, 6:41:19 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Improved usability of dbg_interactive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/queues.i

    r637 r638  
    3636/* Do not include this directly, use dbg_interactive.i instead */
    3737
     38/****** FIFO QUEUES *********/
     39
     40struct fifo {
     41};
     42
     43%extend fifo {
     44        fifo() {
     45                struct fifo * q = NULL;
     46                int ret = fd_fifo_new(&q);
     47                if (ret != 0) {
     48                        DI_ERROR(ret, NULL, NULL);
     49                        return NULL;
     50                }
     51                return q;
     52        }
     53        ~fifo() {
     54                struct fifo *q = self;
     55                fd_fifo_del(&q);
     56        }
     57       
     58        /* Move all elements to another queue */
     59        void move(struct fifo * to) {
     60                int ret = fd_fifo_move($self, to, NULL);
     61                if (ret != 0) {
     62                        DI_ERROR(ret, NULL, NULL);
     63                }
     64        }
     65       
     66        /* Get the length of the queue (nb elements) */
     67        int length() {
     68                int l;
     69                int ret = fd_fifo_length ( $self, &l );
     70                if (ret != 0) {
     71                        DI_ERROR(ret, NULL, NULL);
     72                }
     73                return l;
     74        }
     75
     76        /* Is the threashold function useful here? TODO... */
     77       
     78        /* Post an item */
     79        void post(PyObject * item) {
     80                int ret;
     81                PyObject * i = item;
     82               
     83                Py_XINCREF(i);
     84                ret = fd_fifo_post($self, &i);
     85                if (ret != 0) {
     86                        DI_ERROR(ret, NULL, NULL);
     87                }
     88        }
     89       
     90        /* Get (blocking) */
     91        PyObject * get() {
     92                int ret;
     93                PyObject * i = NULL;
     94               
     95                ret = fd_fifo_get($self, &i);
     96                if (ret != 0) {
     97                        DI_ERROR(ret, NULL, NULL);
     98                }
     99               
     100                return i;
     101        }
     102       
     103        /* TryGet (non-blocking, returns None on empty queue) */
     104        PyObject * tryget() {
     105                int ret;
     106                PyObject * i = NULL;
     107               
     108                ret = fd_fifo_tryget($self, &i);
     109                if (ret == EWOULDBLOCK) {
     110                        Py_XINCREF(Py_None);
     111                        return Py_None;
     112                }
     113                if (ret != 0) {
     114                        DI_ERROR(ret, NULL, NULL);
     115                }
     116               
     117                return i;
     118        }
     119       
     120        /* TimedGet (blocking for a while) */
     121        PyObject * timedget(long seconds) {
     122                int ret;
     123                PyObject * i = NULL;
     124                struct timespec ts;
     125               
     126                clock_gettime(CLOCK_REALTIME, &ts);
     127                ts.tv_sec += seconds;
     128               
     129                ret = fd_fifo_timedget($self, &i, &ts);
     130                if (ret == ETIMEDOUT) {
     131                        Py_XINCREF(Py_None);
     132                        return Py_None;
     133                }
     134                if (ret != 0) {
     135                        DI_ERROR(ret, NULL, NULL);
     136                }
     137               
     138                return i;
     139        }
     140       
     141}               
     142       
     143       
     144       
     145       
Note: See TracChangeset for help on using the changeset viewer.