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 FdDispatcher public header */
26 #ifndef HH_FdDispatcher_
27 #define HH_FdDispatcher_ 1
31 #include "FdManager.hh"
32 #include "FIFORunner.hh"
34 //#include "FdDispatcher.mpp"
35 #include "FdDispatcher.ih"
36 ///////////////////////////////hh.p////////////////////////////////////////
41 /** \brief Scheduler dispatcher managing poll-able file descriptors
43 File descriptors are added directly to the event loop.
48 ///////////////////////////////////////////////////////////////////////////
51 typedef boost::function<void (int)> Callback;
54 EV_READ = FdManager::EV_READ, EV_PRIO = FdManager::EV_PRIO, EV_WRITE = FdManager::EV_WRITE,
55 EV_HUP = FdManager::EV_HUP, EV_ERR = FdManager::EV_ERR,
56 EV_ALL = FdManager::EV_READ | FdManager::EV_WRITE | FdManager::EV_PRIO
59 ///////////////////////////////////////////////////////////////////////////
60 ///\name Structors and default members
63 FdDispatcher(FdManager & manager, FIFORunner & runner);
67 ///////////////////////////////////////////////////////////////////////////
69 bool add(std::string const & name, int fd, Callback const & cb, int events = EV_ALL);
70 ///< Add file descriptor callback
71 /**< There is always one active callback for each
72 combination of file descriptor and event. Registering a
73 new callback will overwrite the old callback.
74 \param[in] name descriptive name
75 \param[in] fd file descriptor
76 \param[in] cb callback
77 \param[in] events Events to call \a cb for */
79 void remove(int fd, int events = EV_ALL); ///< Remove callback
80 /**< \param[in] fd file descriptor
81 \param[in] events Events for which to remove the
84 bool empty() const; ///< \c true, if no file descriptors are registered.
89 /// Internal: File descriptor event
91 : public detail::FdTask<0, FdEvent>,
92 public detail::FdTask<1, FdEvent>,
93 public detail::FdTask<2, FdEvent>,
94 public FdManager::Event
96 typedef detail::FdTask<0, FdEvent> ReadTask;
97 typedef detail::FdTask<1, FdEvent> PrioTask;
98 typedef detail::FdTask<2, FdEvent> WriteTask;
100 virtual void signal(int events);
101 int activeEvents() const;
105 typedef std::map<int, FdEvent> FdMap;
108 FdManager & manager_;
109 FIFORunner & runner_;
114 ///////////////////////////////hh.e////////////////////////////////////////
115 #include "FdDispatcher.cci"
116 #include "FdDispatcher.ct"
117 #include "FdDispatcher.cti"
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"