g++/final: don't add extra code to check for buffer overflows (-fno-stack-protector)
[senf.git] / senf / Scheduler / FdEvent.ih
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief FdDispatcher internal header */
30
31 #ifndef IH_SENF_Scheduler_FdEvent_
32 #define IH_SENF_Scheduler_FdEvent_ 1
33
34 // Custom includes
35 #include <senf/boost_intrusive/iset.hpp>
36
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40 namespace scheduler {
41
42     void restart();
43
44 namespace detail {
45
46     struct FdSetCompare {
47         bool operator()(FdEvent const & a, FdEvent const & b) const
48         { return a.fd_ < b.fd_; }
49     };
50
51     class FdDispatcher
52         : public senf::singleton<FdDispatcher>
53     {
54     public:
55         using senf::singleton<FdDispatcher>::instance;
56         using senf::singleton<FdDispatcher>::alive;
57
58         bool add(FdEvent & event);
59         void remove(FdEvent & event);
60
61         bool empty() const;
62
63     protected:
64
65     private:
66         FdDispatcher();
67         ~FdDispatcher();
68
69         typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>,
70                                              FdSetCompare,
71                                              false > FdSet;
72
73         FdSet fds_;
74
75         friend void senf::scheduler::restart();
76         friend class singleton<FdDispatcher>;
77         friend class senf::scheduler::FdEvent;
78     };
79
80     class FileDispatcher
81         : public senf::singleton<FileDispatcher>
82     {
83     public:
84         using senf::singleton<FileDispatcher>::instance;
85         using senf::singleton<FileDispatcher>::alive;
86
87         void add(FdEvent & event);
88         void remove(FdEvent & event);
89
90         void prepareRun();
91
92         // Called by IdleEventDispatcher
93         void timeout(int t);
94         int timeout() const;
95
96         bool empty() const;
97
98     protected:
99
100     private:
101         FileDispatcher();
102         ~FileDispatcher();
103
104         // We really only need a list here but we need to use the same event structure used by
105         // the FdEvent.
106         typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>,
107                                              FdSetCompare,
108                                              false > FdSet;
109
110         FdSet fds_;
111         int managerTimeout_;
112
113         friend void senf::scheduler::restart();
114         friend class singleton<FileDispatcher>;
115     };
116
117     template <class Handle>
118     int get_descriptor(Handle const & handle);
119
120     int retrieve_filehandle(int fd);
121
122 }}}
123
124 //-/////////////////////////////////////////////////////////////////////////////////////////////////
125 #endif
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // End: