Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef _CCNX_PIT_ENTRY_IMPL_H_ |
| 22 | #define _CCNX_PIT_ENTRY_IMPL_H_ |
| 23 | |
| 24 | namespace ns3 { |
| 25 | |
| 26 | class CcnxPit; |
| 27 | class CcnxInterestHeader; |
| 28 | class CcnxFibEntry; |
| 29 | |
| 30 | template<class Pit> |
| 31 | class CcnxPitEntryImpl : public CcnxPitEntry |
| 32 | { |
| 33 | typedef CcnxPitEntry super; |
| 34 | #define CONTAINER static_cast<Pit&> (m_container) |
| 35 | |
| 36 | public: |
| 37 | CcnxPitEntryImpl (CcnxPit &pit, |
| 38 | Ptr<const CcnxInterestHeader> header, |
| 39 | Ptr<CcnxFibEntry> fibEntry) |
| 40 | : CcnxPitEntry (pit, header, fibEntry) |
| 41 | , item_ (0) |
| 42 | { |
| 43 | CONTAINER.i_time.insert (*this); |
| 44 | CONTAINER.RescheduleCleaning (); |
| 45 | } |
| 46 | |
| 47 | virtual ~CcnxPitEntryImpl () |
| 48 | { |
| 49 | CONTAINER.i_time.erase (*this); |
| 50 | |
| 51 | CONTAINER.RescheduleCleaning (); |
| 52 | } |
| 53 | |
| 54 | virtual void |
| 55 | UpdateLifetime (const Time &offsetTime) |
| 56 | { |
| 57 | CONTAINER.i_time.erase (*this); |
| 58 | super::UpdateLifetime (offsetTime); |
| 59 | CONTAINER.i_time.insert (*this); |
| 60 | |
| 61 | CONTAINER.RescheduleCleaning (); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | // to make sure policies work |
| 66 | void |
| 67 | SetTrie (typename Pit::super::iterator item) { item_ = item; } |
| 68 | |
| 69 | typename Pit::super::iterator to_iterator () { return item_; } |
| 70 | typename Pit::super::const_iterator to_iterator () const { return item_; } |
| 71 | |
| 72 | public: |
| 73 | boost::intrusive::set_member_hook<> time_hook_; |
| 74 | |
| 75 | private: |
| 76 | typename Pit::super::iterator item_; |
| 77 | }; |
| 78 | |
| 79 | template<class T> |
| 80 | struct TimestampIndex |
| 81 | { |
| 82 | bool |
| 83 | operator () (const T &a, const T &b) const |
| 84 | { |
| 85 | return a.GetExpireTime () < b.GetExpireTime (); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | } // ns3 |
| 90 | |
| 91 | #endif |