Scheduler: Change ClockService implementation to utilize the POSIX CLOCK_MONOTONIC...
[senf.git] / Scheduler / FdDispatcher.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief FdDispatcher public header */
25
26 #ifndef HH_FdDispatcher_
27 #define HH_FdDispatcher_ 1
28
29 // Custom includes
30 #include <map>
31 #include "FdManager.hh"
32 #include "FIFORunner.hh"
33
34 //#include "FdDispatcher.mpp"
35 #include "FdDispatcher.ih"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace scheduler {
40
41     /** \brief
42       */
43     class FdDispatcher
44     {
45     public:
46         ///////////////////////////////////////////////////////////////////////////
47         // Types
48
49         typedef boost::function<void (int)> Callback;
50
51         enum Events { 
52             EV_READ = FdManager::EV_READ, EV_PRIO = FdManager::EV_PRIO, EV_WRITE = FdManager::EV_WRITE,
53             EV_HUP = FdManager::EV_HUP, EV_ERR = FdManager::EV_ERR,
54             EV_ALL = FdManager::EV_READ | FdManager::EV_WRITE | FdManager::EV_PRIO
55         };
56
57         ///////////////////////////////////////////////////////////////////////////
58         ///\name Structors and default members
59         ///@{
60         
61         FdDispatcher(FdManager & manager, FIFORunner & runner);
62         ~FdDispatcher();
63
64         ///@}
65         ///////////////////////////////////////////////////////////////////////////
66
67         void add(int fd, Callback const & cb, int events = EV_ALL);
68         void remove(int fd, int events = EV_ALL);
69
70     protected:
71
72     private:
73         struct FdEvent 
74             : public detail::FdTask<0, FdEvent>,
75               public detail::FdTask<1, FdEvent>,
76               public detail::FdTask<2, FdEvent>,
77               public FdManager::Event
78         {
79             typedef detail::FdTask<0, FdEvent> ReadTask;
80             typedef detail::FdTask<1, FdEvent> PrioTask;
81             typedef detail::FdTask<2, FdEvent> WriteTask;
82
83             virtual void signal(int events);
84
85             int activeEvents() const;
86
87             int events;
88         };
89
90         typedef std::map<int, FdEvent> FdMap;
91
92         FdMap fds_;
93         FdManager & manager_;
94         FIFORunner & runner_;
95     };
96
97 }}
98
99 ///////////////////////////////hh.e////////////////////////////////////////
100 #include "FdDispatcher.cci"
101 #include "FdDispatcher.ct"
102 #include "FdDispatcher.cti"
103 #endif
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // comment-column: 40
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // End: