4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
24 #define HH_Scheduler_ 1
28 #include <boost/function.hpp>
29 #include <boost/utility.hpp>
30 #include <boost/call_traits.hpp>
32 //#include "scheduler.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
38 /** \brief Singleton class to manage the event loop
40 This class manages a single select() type event loop. A
41 customer of this class may register any number of file
42 descriptiors with this class and pass callback functions to be
43 called on input, output or error. This functions are specified
44 using boost::function objects
50 ///////////////////////////////////////////////////////////////////////////
53 enum EventId { EV_NONE=0,
54 EV_READ=1, EV_PRIO=2, EV_WRITE=4, EV_HUP=8, EV_ERR=16,
57 template <class Handle>
58 struct GenericCallback {
59 typedef boost::function<void (typename boost::call_traits<Handle>::param_type,
63 ///////////////////////////////////////////////////////////////////////////
64 ///\name Structors and default members
67 // private default constructor
68 // no copy constructor
71 // no conversion constructors
73 static Scheduler & instance();
76 ///////////////////////////////////////////////////////////////////////////
78 template <class Handle>
79 void add(Handle const & handle,
80 typename GenericCallback<Handle>::Callback const & cb,
81 EventId eventMask = EV_ALL);
82 template <class Handle>
83 void remove(Handle const & handle, EventId eventMask = EV_ALL);
94 typedef boost::function<void (EventId)> InternalCallback;
96 void do_add(int fd, InternalCallback const & cb, EventId eventMask = EV_ALL);
97 void do_remove(int fd, EventId eventMask = EV_ALL);
101 InternalCallback cb_read;
102 InternalCallback cb_prio;
103 InternalCallback cb_write;
104 InternalCallback cb_hup;
105 InternalCallback cb_err;
107 int epollMask() const;
110 typedef std::map<int,EventSpec> FdTable;
117 int retrieve_filehandle(int fd);
121 ///////////////////////////////hh.e////////////////////////////////////////
122 #include "Scheduler.cci"
123 #include "Scheduler.ct"
124 #include "Scheduler.cti"
130 // c-file-style: "satcom"