Scheduler: Remove obsolete 'Scheduler' class
[senf.git] / Scheduler / FdEvent.ih
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 internal header */
25
26 #ifndef IH_FdDispatcher_
27 #define IH_FdDispatcher_ 1
28
29 // Custom includes
30 #include "../boost/intrusive/iset.hpp"
31
32 ///////////////////////////////ih.p////////////////////////////////////////
33
34 namespace senf {
35 namespace scheduler {
36
37     void restart();
38
39 namespace detail {
40
41     struct FdSetCompare {
42         bool operator()(FdEvent const & a, FdEvent const & b) const
43         { return a.fd_ < b.fd_; }
44     };
45
46     struct FindFd {
47         bool operator()(FdEvent const & a, int b) const
48         { return a.fd_ < b; }
49         bool operator()(int a, FdEvent const & b) const
50         { return a < b.fd_; }
51     };
52     
53     class FdDispatcher
54         : public senf::singleton<FdDispatcher>
55     {
56     public:
57         using senf::singleton<FdDispatcher>::instance;
58         using senf::singleton<FdDispatcher>::alive;
59         
60         bool add(FdEvent & event);
61         void remove(FdEvent & event);
62
63         bool empty() const;
64
65     protected:
66
67     private:
68         FdDispatcher();
69         ~FdDispatcher();
70
71         typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>,
72                                              FdSetCompare,
73                                              false > FdSet;
74
75         FdSet fds_;
76
77         friend void senf::scheduler::restart();
78         friend class singleton<FdDispatcher>;
79         friend class senf::scheduler::FdEvent;
80     };
81
82     class FileDispatcher
83         : public senf::singleton<FileDispatcher>
84     {
85     public:
86         using senf::singleton<FileDispatcher>::instance;
87         using senf::singleton<FileDispatcher>::alive;
88
89         void add(FdEvent & event);
90         void remove(FdEvent & event);
91
92         void prepareRun();
93
94         void timeout(int t);
95         int timeout() const;
96
97         bool empty() const;
98
99     protected:
100
101     private:
102         FileDispatcher();
103         ~FileDispatcher();
104
105         // We really only need a list here but we need to use the same event structure used by
106         // the FdEvent.
107         typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>,
108                                              FdSetCompare,
109                                              false > FdSet;
110
111         FdSet fds_;
112         int managerTimeout_;
113
114         friend void senf::scheduler::restart();
115         friend class singleton<FileDispatcher>;
116     };
117
118 }}}
119
120 ///////////////////////////////ih.e////////////////////////////////////////
121 #endif
122
123 \f
124 // Local Variables:
125 // mode: c++
126 // fill-column: 100
127 // comment-column: 40
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // End: