Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_select_handler.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_GR_SELECT_HANDLER_H
24 #define INCLUDED_GR_SELECT_HANDLER_H
25
26 #include <boost/shared_ptr.hpp>
27
28 class gr_select_handler;
29 typedef boost::shared_ptr<gr_select_handler> gr_select_handler_sptr;
30
31
32 /*!
33  * \brief Abstract handler for select based notification.
34  *
35  * \sa gr_dispatcher
36  */
37 class gr_select_handler
38 {
39   int   d_fd;
40
41 protected:
42   gr_select_handler(int file_descriptor);
43
44 public:
45   virtual ~gr_select_handler();
46
47   int fd() const { return d_fd; }
48   int file_descriptor() const { return d_fd; }
49
50   /*!
51    * \brief Called when file_descriptor is readable.
52    *
53    * Called when the dispatcher detects that file_descriptor can
54    * be read without blocking.
55    */
56   virtual void handle_read() = 0;
57
58   /*!
59    * \brief Called when file_descriptor is writable.
60    *
61    * Called when dispatcher detects that file descriptor can be 
62    * written without blocking.
63    */
64   virtual void handle_write() = 0;
65
66   /*!
67    * Called each time around the dispatcher loop to determine whether
68    * this handler's file descriptor should be added to the list on which
69    * read events can occur.  The default method returns true, indicating
70    * that by default, all handlers are interested in read events.
71    */
72   virtual bool readable() { return true; }
73
74   /*!
75    * Called each time around the dispatcher loop to determine whether
76    * this handler's file descriptor should be added to the list on which
77    * write events can occur.  The default method returns true, indicating
78    * that by default, all handlers are interested in write events.
79    */
80   virtual bool writable() { return true; }
81 };
82
83 #endif /* INCLUDED_GR_SELECT_HANDLER_H */