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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef _NDN_PIT_ENTRY_IMPL_H_ |
| 22 | #define _NDN_PIT_ENTRY_IMPL_H_ |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 23 | |
| 24 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 25 | namespace ndn { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 27 | class Pit; |
| 28 | |
| 29 | namespace pit { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 30 | |
| 31 | template<class Pit> |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | class EntryImpl : public Entry |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 33 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | typedef Entry super; |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 35 | #define CONTAINER static_cast<Pit&> (m_container) |
| 36 | |
| 37 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 38 | EntryImpl (Pit &pit, |
| 39 | Ptr<const InterestHeader> header, |
| 40 | Ptr<fib::Entry> fibEntry) |
| 41 | : Entry (pit, header, fibEntry) |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 42 | , item_ (0) |
| 43 | { |
| 44 | CONTAINER.i_time.insert (*this); |
| 45 | CONTAINER.RescheduleCleaning (); |
| 46 | } |
| 47 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 48 | virtual ~EntryImpl () |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 49 | { |
Alexander Afanasyev | ad82e25 | 2012-07-29 23:51:21 -0700 | [diff] [blame] | 50 | CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this)); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 51 | |
| 52 | CONTAINER.RescheduleCleaning (); |
| 53 | } |
| 54 | |
| 55 | virtual void |
| 56 | UpdateLifetime (const Time &offsetTime) |
| 57 | { |
Alexander Afanasyev | ad82e25 | 2012-07-29 23:51:21 -0700 | [diff] [blame] | 58 | CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this)); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 59 | super::UpdateLifetime (offsetTime); |
| 60 | CONTAINER.i_time.insert (*this); |
| 61 | |
| 62 | CONTAINER.RescheduleCleaning (); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | // to make sure policies work |
| 67 | void |
| 68 | SetTrie (typename Pit::super::iterator item) { item_ = item; } |
| 69 | |
| 70 | typename Pit::super::iterator to_iterator () { return item_; } |
| 71 | typename Pit::super::const_iterator to_iterator () const { return item_; } |
| 72 | |
| 73 | public: |
| 74 | boost::intrusive::set_member_hook<> time_hook_; |
| 75 | |
| 76 | private: |
| 77 | typename Pit::super::iterator item_; |
| 78 | }; |
| 79 | |
| 80 | template<class T> |
| 81 | struct TimestampIndex |
| 82 | { |
| 83 | bool |
| 84 | operator () (const T &a, const T &b) const |
| 85 | { |
| 86 | return a.GetExpireTime () < b.GetExpireTime (); |
| 87 | } |
| 88 | }; |
| 89 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 90 | } // namespace pit |
| 91 | } // namespace ndn |
| 92 | } // namespace ns3 |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 93 | |
| 94 | #endif |