00001 // $Id: FdEvent.ih 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2008 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #ifndef IH_SENF_Scheduler_FdEvent_ 00027 #define IH_SENF_Scheduler_FdEvent_ 1 00028 00029 // Custom includes 00030 #include <senf/boost_intrusive/iset.hpp> 00031 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 00034 namespace senf { 00035 namespace scheduler { 00036 00037 void restart(); 00038 00039 namespace detail { 00040 00041 struct FdSetCompare { 00042 bool operator()(FdEvent const & a, FdEvent const & b) const 00043 { return a.fd_ < b.fd_; } 00044 }; 00045 00046 struct FindFd { 00047 bool operator()(FdEvent const & a, int b) const 00048 { return a.fd_ < b; } 00049 bool operator()(int a, FdEvent const & b) const 00050 { return a < b.fd_; } 00051 }; 00052 00053 class FdDispatcher 00054 : public senf::singleton<FdDispatcher> 00055 { 00056 public: 00057 using senf::singleton<FdDispatcher>::instance; 00058 using senf::singleton<FdDispatcher>::alive; 00059 00060 bool add(FdEvent & event); 00061 void remove(FdEvent & event); 00062 00063 bool empty() const; 00064 00065 protected: 00066 00067 private: 00068 FdDispatcher(); 00069 ~FdDispatcher(); 00070 00071 typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>, 00072 FdSetCompare, 00073 false > FdSet; 00074 00075 FdSet fds_; 00076 00077 friend void senf::scheduler::restart(); 00078 friend class singleton<FdDispatcher>; 00079 friend class senf::scheduler::FdEvent; 00080 }; 00081 00082 class FileDispatcher 00083 : public senf::singleton<FileDispatcher> 00084 { 00085 public: 00086 using senf::singleton<FileDispatcher>::instance; 00087 using senf::singleton<FileDispatcher>::alive; 00088 00089 void add(FdEvent & event); 00090 void remove(FdEvent & event); 00091 00092 void prepareRun(); 00093 00094 // Called by IdleEventDispatcher 00095 void timeout(int t); 00096 int timeout() const; 00097 00098 bool empty() const; 00099 00100 protected: 00101 00102 private: 00103 FileDispatcher(); 00104 ~FileDispatcher(); 00105 00106 // We really only need a list here but we need to use the same event structure used by 00107 // the FdEvent. 00108 typedef boost::intrusive::imultiset< FdSetBase::value_traits<FdEvent>, 00109 FdSetCompare, 00110 false > FdSet; 00111 00112 FdSet fds_; 00113 int managerTimeout_; 00114 00115 friend void senf::scheduler::restart(); 00116 friend class singleton<FileDispatcher>; 00117 }; 00118 00119 template <class Handle> 00120 int get_descriptor(Handle const & handle); 00121 00122 int retrieve_filehandle(int fd); 00123 00124 }}} 00125 00126 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00127 #endif 00128 00129 00130 // Local Variables: 00131 // mode: c++ 00132 // fill-column: 100 00133 // comment-column: 40 00134 // c-file-style: "senf" 00135 // indent-tabs-mode: nil 00136 // ispell-local-dictionary: "american" 00137 // compile-command: "scons -u test" 00138 // End: