duplicate.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_DUPLICATE_HXX
00020 # define QOLYESTER_DAEMON_SET_DUPLICATE_HXX 1
00021 
00022 # include "duplicate.hh"
00023 
00024 namespace olsr {
00025 
00026   extern sch::Scheduler scheduler;
00027 
00028   namespace set {
00029 
00030     DuplicateEntry::DuplicateEntry() :
00031       addr_(),
00032       seqnum_(),
00033       retransmitted_(false),
00034       ifaces_(),
00035       time_(0)
00036     {}
00037 
00038     DuplicateEntry::DuplicateEntry(const address_t& a, u_int16_t s,
00039                                    const address_t& i, bool r) :
00040       addr_(a),
00041       seqnum_(s),
00042       retransmitted_(r), 
00043       ifaces_(),
00044       time_(timeval_t::in(cst::dup_hold_time)) {
00045       ifaces_.insert(i);
00046     }
00047 
00048     bool 
00049     DuplicateEntry::in_ifaces(const address_t& a) const {
00050       return ifaces_.find(a) != ifaces_.end();
00051     }
00052 
00053     void
00054     DuplicateEntry::add_iface(const address_t& a) {
00055       ifaces_.insert(a);
00056     }
00057 
00058     bool
00059     DuplicateEntry::operator<(const This& rhs) const {
00060       if (addr_ == rhs.addr_)
00061         return seqnum_ < rhs.seqnum_;
00062       return addr_ < rhs.addr_;
00063     }
00064 
00065     DuplicateEntry
00066     DuplicateEntry::make_key(const address_t& a, u_int16_t s) {
00067       This      tmp = dummy_for_find_;
00068       const_cast<address_t&>(tmp.addr_) = a;
00069       const_cast<u_int16_t&>(tmp.seqnum_) = s;
00070       return tmp;
00071     }
00072 
00073     DuplicateSet::DuplicateSet()
00074       : dset_(),
00075         dupset_(*this, dset_)
00076     {}
00077 
00078     void
00079     DuplicateSet::insert(const DuplicateEntry& x) {
00080       std::pair<dset_t::iterator, bool> p = dset_.insert(x);
00081       if (!p.second) {
00082         sch::TimedEvent*        e = p.first->updater();
00083         scheduler.erase(e);
00084         e->set_next(x.time());
00085         scheduler.insert(e);
00086         
00087         const_cast<elem_t&>(*p.first).set_time(x.time());
00088         const_cast<elem_t&>(*p.first).ifaces().insert(x.ifaces().begin(),
00089                                                      x.ifaces().end());
00090         if (x.retransmitted())
00091           const_cast<elem_t&>(*p.first).set_retransmitted();
00092       } else {
00093         updater_t*      e = new updater_t(x.time(), eraser_t(*this, p.first));
00094         const_cast<elem_t&>(*p.first).set_updater(e);
00095         scheduler.insert(e);
00096       }
00097     }
00098 
00099     void
00100     DuplicateSet::erase(const dset_t::iterator& pos) {
00101       sch::TimedEvent*  e = pos->updater();
00102       dset_.erase(pos);
00103       scheduler.destroy(e);
00104     }
00105 
00106   } // namespace set
00107 
00108 } // namespace olsr
00109 
00110 #endif // ! QOLYESTER_DAEMON_SET_DUPLICATE_HXX

Generated on Mon Sep 10 17:02:11 2007 for Qolyester daemon by  doxygen 1.5.1