mb_timer_queue.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2008 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 
00022 #ifndef INCLUDED_MB_TIMER_QUEUE_H
00023 #define INCLUDED_MB_TIMER_QUEUE_H
00024 
00025 #include <mblock/time.h>
00026 #include <vector>
00027 #include <queue>
00028 #include <pmt.h>
00029 #include <mblock/msg_accepter.h>
00030 
00031 class mb_timeout {
00032 public:
00033   mb_time               d_when;         // absolute time to fire timeout
00034   mb_time               d_delta;        // if periodic, delta_t to next timeout
00035   bool                  d_is_periodic;  // true iff this is a periodic timeout
00036   pmt_t                 d_user_data;    // data from %timeout msg
00037   pmt_t                 d_handle;       // handle for cancellation
00038   mb_msg_accepter_sptr  d_accepter;     // where to send the message
00039 
00040   // one-shot constructor
00041   mb_timeout(const mb_time &abs_time,
00042              pmt_t user_data, mb_msg_accepter_sptr accepter);
00043 
00044   // periodic constructor
00045   mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time,
00046              pmt_t user_data, mb_msg_accepter_sptr accepter);
00047 
00048   pmt_t handle() const { return d_handle; }
00049 };
00050 
00051 typedef boost::shared_ptr<mb_timeout> mb_timeout_sptr;
00052 
00053 
00054 //! Sort criterion for priority_queue
00055 class timeout_later
00056 {
00057 public:
00058   bool operator() (const mb_timeout_sptr t1, const mb_timeout_sptr t2)
00059   {
00060     return t1->d_when > t2->d_when;
00061   }
00062 };
00063 
00064 
00065 class mb_timer_queue : public std::priority_queue<mb_timeout_sptr,
00066                                                   std::vector<mb_timeout_sptr>,
00067                                                   timeout_later>
00068 {
00069 public:
00070   void cancel(pmt_t handle);
00071 };
00072 
00073 #endif /* INCLUDED_MB_TIMER_QUEUE_H */

Generated on Wed Jul 29 06:31:39 2009 for GNU Radio 3.2.2 C++ API by  doxygen 1.5.9