Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

set/hna.hxx

Go to the documentation of this file.
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_HNA_HXX
00020 # define QOLYESTER_DAEMON_SET_HNA_HXX 1
00021 
00022 # include "utl/mark.hh"
00023 
00024 # include "hna.hh"
00025 
00026 namespace olsr {
00027 
00028   extern sch::Scheduler scheduler;
00029   extern utl::Mark      routes_recomp;
00030 
00031   namespace set {
00032 
00033     HNAEntry::HNAEntry() :
00034       g_addr_(),
00035       n_addr_(),
00036       prefix_(0),
00037       time_(0, 0)
00038     {}
00039 
00040     HNAEntry::HNAEntry(const address_t& gaddr,
00041                        const address_t& naddr,
00042                        unsigned prefix,
00043                        const timeval_t& v) :
00044       g_addr_(gaddr),
00045       n_addr_(naddr),
00046       prefix_(prefix),
00047       time_(timeval_t::in(v))
00048     {}
00049 
00050     bool
00051     HNAEntry::is_valid() const { return !time_.is_past(); }
00052 
00053     void
00054     HNAEntry::set_time(const timeval_t& t) { time_ = t; }
00055                
00056     bool
00057     HNAEntry::operator<(const This& rhs) const {
00058       if (g_addr_ == rhs.g_addr_)
00059         if (n_addr_ == rhs.n_addr_)
00060           return prefix_ < rhs.prefix_;
00061         else
00062           return n_addr_ < rhs.n_addr_;
00063       return g_addr_ < rhs.g_addr_;
00064     }
00065 
00066     HNAEntry
00067     HNAEntry::make_key(const address_t& gaddr,
00068                        const address_t& naddr,
00069                        unsigned prefix) {
00070       This      tmp = dummy_for_find_;
00071       
00072       const_cast<address_t&>(tmp.g_addr_) = gaddr;
00073       const_cast<address_t&>(tmp.n_addr_) = naddr;
00074       const_cast<unsigned&>(tmp.prefix_)  = prefix;
00075       
00076       return tmp;
00077     }
00078 
00079     HNASet::HNASet()
00080       : hset_(),
00081         hnaset_(*this, hset_)
00082     {}
00083 
00084     void
00085     HNASet::insert(const HNAEntry& x) {
00086       std::pair<hset_t::iterator, bool> p = hset_.insert(x);
00087       if (!p.second) {
00088         sch::TimedEvent*        e = p.first->updater();
00089         scheduler.erase(e);
00090         e->set_next(x.time());
00091         scheduler.insert(e);
00092 
00093         const_cast<elem_t&>(*p.first).set_time(x.time());
00094       } else {
00095         updater_t*      e = new updater_t(x.time(), eraser_t(*this, p.first));
00096         const_cast<elem_t&>(*p.first).set_updater(e);
00097         scheduler.insert(e);
00098         routes_recomp.set_mark();
00099       }
00100     }
00101 
00102     void
00103     HNASet::erase(const hset_t::iterator& pos) {
00104       assert(pos != hset_.end());
00105 //       del_set.erase(pos->del_pos());
00106       sch::TimedEvent*  e = pos->updater();
00107       hset_.erase(pos);
00108       scheduler.destroy(e);
00109       routes_recomp.set_mark();
00110     }
00111 
00112   } // namespace set
00113 
00114 } // namespace olsr
00115 
00116 #endif // ! QOLYESTER_DAEMON_SET_HNA_HXX

Generated on Thu Jul 28 21:21:47 2005 for Qolyester daemon by  doxygen 1.4.1