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 | { |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 36 | m_dataCallbacks.push_back (onData); |
| 37 | m_timeoutCallbacks.push_back (onTimeout); |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void |
| 41 | ClearCallbacks () |
| 42 | { |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 43 | m_dataCallbacks.clear (); |
| 44 | m_timeoutCallbacks.clear (); |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | Ptr<const Interest> |
| 48 | GetInterest () const |
| 49 | { |
| 50 | return m_interest; |
| 51 | } |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 52 | |
| 53 | void |
| 54 | ProcessOnData (Ptr<const Interest> interest, Ptr<const Data> data) |
| 55 | { |
| 56 | for (std::list<ApiFace::DataCallback>::iterator i = m_dataCallbacks.begin (); |
| 57 | i != m_dataCallbacks.end (); |
| 58 | i++) |
| 59 | { |
| 60 | (*i) (interest, data); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | ProcessOnTimeout (Ptr<const Interest> interest) |
| 66 | { |
| 67 | for (std::list<ApiFace::TimeoutCallback>::iterator i = m_timeoutCallbacks.begin (); |
| 68 | i != m_timeoutCallbacks.end (); |
| 69 | i++) |
| 70 | { |
| 71 | (*i) (interest); |
| 72 | } |
| 73 | } |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | baccf7d | 2013-08-09 12:38:44 -0700 | [diff] [blame] | 75 | private: |
| 76 | std::list<ApiFace::DataCallback> m_dataCallbacks; |
| 77 | std::list<ApiFace::TimeoutCallback> m_timeoutCallbacks; |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 78 | Ptr<const Interest> m_interest; |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | struct PendingInterestContainer : |
| 83 | public ndnSIM::trie_with_policy<Name, |
| 84 | ndnSIM::smart_pointer_payload_traits< PendingInterestEntry >, |
| 85 | timeouts_policy_traits> |
| 86 | { |
| 87 | }; |
| 88 | |
| 89 | } // detail |
| 90 | } // ndn |
| 91 | } // ns3 |
| 92 | |
| 93 | #endif // NDN_NDNCXX_DETAIL_PENDING_INTEREST_CONTAINER_H |