Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * |
| 6 | * GNU v3.0 license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #ifndef NDN_NDNCXX_DETAIL_PENDING_INTEREST_CONTAINER_H |
| 12 | #define NDN_NDNCXX_DETAIL_PENDING_INTEREST_CONTAINER_H |
| 13 | |
| 14 | #include <ns3/ndnSIM/utils/trie/trie-with-policy.h> |
| 15 | #include "timeouts-policy.h" |
| 16 | |
| 17 | namespace ns3 { |
| 18 | namespace ndn { |
| 19 | namespace detail { |
| 20 | |
| 21 | struct PendingInterestEntry : public SimpleRefCount< PendingInterestEntry > |
| 22 | { |
| 23 | public: |
| 24 | PendingInterestEntry (Ptr<const Interest> interest) |
| 25 | : m_interest (interest) |
Alexander Afanasyev | f0bda2f | 2013-08-12 16:38:13 -0700 | [diff] [blame] | 26 | { |
| 27 | } |
| 28 | |
| 29 | virtual ~PendingInterestEntry () |
| 30 | { |
| 31 | } |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 33 | void |
| 34 | AddCallbacks (ApiFace::DataCallback onData, ApiFace::TimeoutCallback onTimeout) |
| 35 | { |
YuZhang | bc1d1e2 | 2014-02-05 12:44:33 -0800 | [diff] [blame] | 36 | if (! onData.IsNull ()) |
| 37 | { |
| 38 | m_dataCallbacks.push_back (onData); |
| 39 | } |
| 40 | if (! onTimeout.IsNull ()) |
| 41 | { |
| 42 | m_timeoutCallbacks.push_back (onTimeout); |
| 43 | } |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void |
| 47 | ClearCallbacks () |
| 48 | { |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 49 | m_dataCallbacks.clear (); |
| 50 | m_timeoutCallbacks.clear (); |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | Ptr<const Interest> |
| 54 | GetInterest () const |
| 55 | { |
| 56 | return m_interest; |
| 57 | } |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 58 | |
| 59 | void |
| 60 | ProcessOnData (Ptr<const Interest> interest, Ptr<const Data> data) |
| 61 | { |
| 62 | for (std::list<ApiFace::DataCallback>::iterator i = m_dataCallbacks.begin (); |
| 63 | i != m_dataCallbacks.end (); |
| 64 | i++) |
| 65 | { |
| 66 | (*i) (interest, data); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | ProcessOnTimeout (Ptr<const Interest> interest) |
| 72 | { |
| 73 | for (std::list<ApiFace::TimeoutCallback>::iterator i = m_timeoutCallbacks.begin (); |
| 74 | i != m_timeoutCallbacks.end (); |
| 75 | i++) |
| 76 | { |
| 77 | (*i) (interest); |
| 78 | } |
| 79 | } |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 81 | private: |
| 82 | std::list<ApiFace::DataCallback> m_dataCallbacks; |
| 83 | std::list<ApiFace::TimeoutCallback> m_timeoutCallbacks; |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 84 | Ptr<const Interest> m_interest; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | struct PendingInterestContainer : |
| 89 | public ndnSIM::trie_with_policy<Name, |
| 90 | ndnSIM::smart_pointer_payload_traits< PendingInterestEntry >, |
| 91 | timeouts_policy_traits> |
| 92 | { |
| 93 | }; |
| 94 | |
| 95 | } // detail |
| 96 | } // ndn |
| 97 | } // ns3 |
| 98 | |
| 99 | #endif // NDN_NDNCXX_DETAIL_PENDING_INTEREST_CONTAINER_H |