4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Poller public header */
31 #ifndef HH_SENF_Scheduler_Poller_
32 #define HH_SENF_Scheduler_Poller_ 1
35 #include <sys/epoll.h>
36 #include <boost/utility.hpp>
37 #include <boost/iterator/transform_iterator.hpp>
38 #include <boost/range/iterator_range.hpp>
40 //#include "Poller.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 /** \brief Epoll abstraction
49 This class provides a more convenient interface to the epoll() API. File descriptors are
50 registered with pointers to a parameterized event type. After waiting for an event, the
51 Poller allows to iterate over the event instances for all posted events.
53 \tparam Value Event type
55 template <class Value>
61 typedef std::pair<int, Value*> result_type;
62 result_type operator()(epoll_event const &) const;
65 static int const NumEvents = 8;
68 //-////////////////////////////////////////////////////////////////////////
71 typedef Value value_type;
72 typedef boost::transform_iterator<GetPollResult, epoll_event*> iterator;
73 typedef boost::iterator_range<iterator> range;
76 EV_READ = EPOLLIN, EV_PRIO = EPOLLPRI, EV_WRITE = EPOLLOUT,
77 EV_HUP = EPOLLHUP, EV_ERR = EPOLLERR
80 //-////////////////////////////////////////////////////////////////////////
81 ///\name Structors and default members
88 //-////////////////////////////////////////////////////////////////////////
90 bool set(int fd, int events, Value * data); ///< Set file descriptor event data and mask
91 /**< The Poller does \e not own \a data. The value is owned
92 by some external entity (the dispatcher to be more
94 void remove(int fd); ///< Remove file descriptor
95 range wait(); ///< Wait for one event
96 /**< \returns a range of iterators which iterate over the
97 data values registered with the event */
99 void timeout(int t); ///< Set event timeout to \a t milliseconds
100 int timeout() const; ///< Current event timeout
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 //#include "Poller.cci"
113 #include "Poller.cti"
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"