blob: 78ab10d6686f78bf5720c8fdce1bcfadb4357875 [file] [log] [blame]
Alexander Afanasyeva4e74282013-07-11 15:23:20 -07001/* -*- 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
17namespace ns3 {
18namespace ndn {
19namespace detail {
20
21struct PendingInterestEntry : public SimpleRefCount< PendingInterestEntry >
22{
23public:
24 PendingInterestEntry (Ptr<const Interest> interest)
25 : m_interest (interest)
26 { }
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070027
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070028 void
29 AddCallbacks (ApiFace::DataCallback onData, ApiFace::TimeoutCallback onTimeout)
30 {
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070031 m_dataCallbacks.push_back (onData);
32 m_timeoutCallbacks.push_back (onTimeout);
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070033 }
34
35 void
36 ClearCallbacks ()
37 {
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070038 m_dataCallbacks.clear ();
39 m_timeoutCallbacks.clear ();
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070040 }
41
42 Ptr<const Interest>
43 GetInterest () const
44 {
45 return m_interest;
46 }
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070047
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 Afanasyeva4e74282013-07-11 15:23:20 -070069
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070070private:
71 std::list<ApiFace::DataCallback> m_dataCallbacks;
72 std::list<ApiFace::TimeoutCallback> m_timeoutCallbacks;
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070073 Ptr<const Interest> m_interest;
74};
75
76
77struct 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