0dc5504aa4c95fdf6ab955756b24bfc91efa30a4
[senf.git] / Scheduler / Poller.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Poller public header */
25
26 #ifndef HH_Poller_
27 #define HH_Poller_ 1
28
29 // Custom includes
30 #include <sys/epoll.h>
31 #include <boost/utility.hpp>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include <boost/range/iterator_range.hpp>
34
35 //#include "Poller.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace scheduler {
40
41     /** \brief
42       */
43     template <class Value>
44     class Poller
45         : boost::noncopyable
46     {
47         struct GetPollResult
48         {
49             typedef std::pair<int, Value*> result_type;
50             result_type operator()(epoll_event const &) const;
51         };
52
53         static int const NumEvents = 8;
54
55     public:
56         ///////////////////////////////////////////////////////////////////////////
57         // Types
58         
59         typedef Value value_type;
60         typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator;
61         typedef boost::iterator_range<iterator> range;
62
63         enum Events { 
64             EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT,
65             EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR 
66 };
67
68         ///////////////////////////////////////////////////////////////////////////
69         ///\name Structors and default members
70         ///@{
71
72         Poller();
73         ~Poller();
74
75         ///@}
76         ///////////////////////////////////////////////////////////////////////////
77
78         bool set(int fd, int events, Value * data);
79         void remove(int fd);
80         range wait();
81         
82         void timeout(int t);
83         int timeout() const;
84
85     private:
86         int epollFd_;
87         int timeout_;
88     };
89
90
91 }}
92
93 ///////////////////////////////hh.e////////////////////////////////////////
94 //#include "Poller.cci"
95 #include "Poller.ct"
96 #include "Poller.cti"
97 #endif
98
99 \f
100 // Local Variables:
101 // mode: c++
102 // fill-column: 100
103 // comment-column: 40
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"
108 // End: