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