00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique 00002 00003 // This file is part of Qolyester. 00004 00005 // Qolyester is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 00010 // Qolyester is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 #ifndef QOLYESTER_DAEMON_SET_MID_HH 00020 # define QOLYESTER_DAEMON_SET_MID_HH 1 00021 00022 # include <set> 00023 # include "utl/timeval.hh" 00024 # include "utl/set.hh" 00025 # include "sch/scheduler.hh" 00026 # include "net/ipaddress.hh" 00027 00028 namespace olsr { 00029 00030 namespace sch { 00031 00032 class StatePrinter; 00033 00034 } 00035 00036 namespace set { 00037 00038 class MIDEntry { 00039 typedef MIDEntry This; 00040 inline MIDEntry(); 00041 public: 00042 inline MIDEntry(const address_t& iaddr, 00043 const address_t& maddr, 00044 const timeval_t& vtime); 00045 00046 virtual ~MIDEntry() {} 00047 00048 const address_t& iface_addr() const { return i_addr_; } 00049 const address_t& main_addr() const { return m_addr_; } 00050 const timeval_t& time() const { return time_; } 00051 00052 inline bool is_valid() const; 00053 inline void set_time(const timeval_t& t); 00054 inline void set_main_addr(const address_t& maddr); 00055 inline bool operator<(const This& rhs) const; 00056 00057 inline This& operator=(const This& other); 00058 00059 static inline This make_key(const address_t& iaddr); 00060 private: 00061 const address_t i_addr_; 00062 address_t m_addr_; 00063 timeval_t time_; 00064 00065 static This dummy_for_find_; 00066 00067 friend class sch::StatePrinter; 00068 }; 00069 00070 class MIDSet { 00071 typedef MIDSet This; 00072 typedef sch::Updatable<MIDEntry> elem_t; 00073 typedef std::set<elem_t> mset_t; 00074 typedef sch::upd::SetEraser<This, mset_t::iterator> eraser_t; 00075 typedef sch::UpdateEvent<eraser_t> updater_t; 00076 00077 typedef utl::Subset<mset_t, 00078 utl::NoAction<This, mset_t::iterator>, 00079 utl::DefaultPredicate<This, mset_t::iterator>, 00080 This> val_mset_t; 00081 public: 00082 typedef val_mset_t midset_t; 00083 00084 midset_t& midset() { return midset_; } 00085 00086 inline MIDSet(); 00087 00088 inline void insert(const MIDEntry& x); 00089 inline void erase(const mset_t::iterator& pos); 00090 private: 00091 mset_t mset_; 00092 midset_t midset_; 00093 00094 friend class sch::StatePrinter; 00095 00096 }; 00097 00098 } // namespace set 00099 00100 typedef set::MIDSet midset_t; 00101 00102 } // namespace olsr 00103 00104 # include "mid.hxx" 00105 00106 #endif // ! QOLYESTER_DAEMON_SET_MID_HH