Imported Upstream version 3.2.2
[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 3, 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  * \ingroup base
35  *
36  * \sa gr_dispatcher
37  */
38 class gr_select_handler
39 {
40   int   d_fd;
41
42 protected:
43   gr_select_handler(int file_descriptor);
44
45 public:
46   virtual ~gr_select_handler();
47
48   int fd() const { return d_fd; }
49   int file_descriptor() const { return d_fd; }
50
51   /*!
52    * \brief Called when file_descriptor is readable.
53    *
54    * Called when the dispatcher detects that file_descriptor can
55    * be read without blocking.
56    */
57   virtual void handle_read() = 0;
58
59   /*!
60    * \brief Called when file_descriptor is writable.
61    *
62    * Called when dispatcher detects that file descriptor can be 
63    * written without blocking.
64    */
65   virtual void handle_write() = 0;
66
67   /*!
68    * Called each time around the dispatcher loop to determine whether
69    * this handler's file descriptor should be added to the list on which
70    * read events can occur.  The default method returns true, indicating
71    * that by default, all handlers are interested in read events.
72    */
73   virtual bool readable() { return true; }
74
75   /*!
76    * Called each time around the dispatcher loop to determine whether
77    * this handler's file descriptor should be added to the list on which
78    * write events can occur.  The default method returns true, indicating
79    * that by default, all handlers are interested in write events.
80    */
81   virtual bool writable() { return true; }
82 };
83
84 #endif /* INCLUDED_GR_SELECT_HANDLER_H */