4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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 \brief FdManager public header */
27 #define HH_FdManager_ 1
31 #include "ClockService.hh"
32 #include "../Utils/singleton.hh"
34 //#include "FdManager.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
43 /** \brief Manage file descriptor event processing
45 The FdManager is the internal class which manages all events (all events need to somehow be
46 made accessible via a file descriptor). File descriptors are added or removed from the
47 FdManager which then allows waiting until an event occurs on one of the descriptors.
49 Registered events must be derived from FdManager::Event. The FdManager does \e not manage
50 the event classes, it just manages pointers to externally owned events (the events are owned
51 by the respective dispatchers).
53 When an event is posted, it's \c signal() member is called. However, this call will \e not
54 execute the user callback registered for the event, it will just mark the relevant tasks as
60 : public singleton<FdManager>
63 ///////////////////////////////////////////////////////////////////////////
69 virtual void signal(int events) = 0; ///< Called when the given event is posted
73 EV_READ = Poller<Event>::EV_READ, EV_PRIO = Poller<Event>::EV_PRIO, EV_WRITE = Poller<Event>::EV_WRITE,
74 EV_HUP = Poller<Event>::EV_HUP, EV_ERR = Poller<Event>::EV_ERR
77 ///////////////////////////////////////////////////////////////////////////
78 ///\name Structors and default members
81 using singleton<FdManager>::instance;
82 using singleton<FdManager>::alive;
85 ///////////////////////////////////////////////////////////////////////////
87 bool set(int fd, int events, Event * entry); ///< Set file descriptor event mask
88 /**< This sets the event mask for \a fd to \a events which
89 is a combination of values from the \c Events enum. If
90 \a fd is already registered, the registration is
91 changed to conform to the parameters passed, otherwise
92 a new registration is added.
93 \param[in] fd file descriptor
94 \param[in] events events to register for
95 \param[in] entry event to signal
96 \returns \c true, if \a fd supports polling, \c false
98 void remove(int fd); ///< Remove \a fd from the manager
100 void timeout(int t); ///< Set event timeout
101 /**< proceseOnce() will wait for max \a t milliseconds for
102 an event to occur. If set to -1, processOnce() will
104 int timeout() const; ///< Get timeout in milliseconds
106 void processOnce(); ///< Wait for events
107 /**< This call waits until at least one event is posted but
108 no longer than the current timeout(). */
110 ClockService::clock_type eventTime() const; ///< Time of last event
117 Poller<Event> poller_;
118 senf::ClockService::clock_type eventTime_;
120 friend class singleton<FdManager>;
121 friend class senf::Scheduler;
126 ///////////////////////////////hh.e////////////////////////////////////////
127 #include "FdManager.cci"
128 //#include "FdManager.ct"
129 //#include "FdManager.cti"
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"