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 FileDispatcher public header */
26 #ifndef HH_FileDispatcher_
27 #define HH_FileDispatcher_ 1
31 #include "FdManager.hh"
32 #include "FIFORunner.hh"
33 #include "FdDispatcher.hh"
35 //#include "FileDispatcher.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
41 /** \brief Scheduler dispatcher managing disc files
43 This dispatcher manages file descriptors which are connected to disc files. Since disc files
44 do not support select() / poll() / epoll(), they are considered to be always ready (which is
45 especially untrue for remote files e.g. vie NFS).
47 The FileDispatcher will change the FdManager's event timeout value to 0 (from -1) whenever
48 there is at least one file registered.
53 ///////////////////////////////////////////////////////////////////////////
56 typedef boost::function<void (int)> Callback;
59 EV_READ = FdManager::EV_READ, EV_WRITE = FdManager::EV_WRITE,
60 EV_HUP = FdManager::EV_HUP, EV_ERR = FdManager::EV_ERR,
61 EV_ALL = FdManager::EV_READ | FdManager::EV_WRITE
64 ///////////////////////////////////////////////////////////////////////////
65 ///\name Structors and default members
68 FileDispatcher(FdManager & manager, FIFORunner & runner);
72 ///////////////////////////////////////////////////////////////////////////
74 void add(std::string const & name, int fd, Callback const & cb, int events = EV_ALL);
75 ///< Add file descriptor callback
76 /**< There is always one active callback for each
77 combination of file descriptor and event. Registering a
78 new callback will overwrite the old callback.
79 \param[in] name descriptive name
80 \param[in] fd file descriptor
81 \param[in] cb callback
82 \param[in] events Events to call \a cb for */
84 void remove(int fd, int events = EV_ALL);
85 /**< \param[in] fd file descriptor
86 \param[in] events Events for which to remove the
89 void prepareRun(); ///< Prepare tasks
90 /**< This must be called after the FdManager returns before
91 running the runnable tasks. */
93 void timeout(int t); ///< Change FdManager timeout
94 /**< Since the FileDispatcher must be able to change the
95 timeout value, the value must be set here and not
96 directly in the FdManager. */
97 int timeout() const; ///< Retrieve current timeout value
99 bool empty() const; ///< \c true, if no files are registered.
104 /// Internal: Disk file event
106 : public detail::FdTask<0, FileEvent>,
107 public detail::FdTask<1, FileEvent>
109 typedef detail::FdTask<0, FileEvent> ReadTask;
110 typedef detail::FdTask<1, FileEvent> WriteTask;
112 int activeEvents() const;
116 typedef std::map<int, FileEvent> FileMap;
119 FdManager & manager_;
120 FIFORunner & runner_;
127 ///////////////////////////////hh.e////////////////////////////////////////
128 #include "FileDispatcher.cci"
129 //#include "FileDispatcher.ct"
130 //#include "FileDispatcher.cti"
137 // comment-column: 40
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"