blob: b790864e710fb1bc6869375c138df309290ce3a9 [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)
Alexander Afanasyevf0bda2f2013-08-12 16:38:13 -070026 {
27 }
28
29 virtual ~PendingInterestEntry ()
30 {
31 }
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070032
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070033 void
34 AddCallbacks (ApiFace::DataCallback onData, ApiFace::TimeoutCallback onTimeout)
35 {
YuZhangbc1d1e22014-02-05 12:44:33 -080036 if (! onData.IsNull ())
37 {
38 m_dataCallbacks.push_back (onData);
39 }
40 if (! onTimeout.IsNull ())
41 {
42 m_timeoutCallbacks.push_back (onTimeout);
43 }
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070044 }
45
46 void
47 ClearCallbacks ()
48 {
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070049 m_dataCallbacks.clear ();
50 m_timeoutCallbacks.clear ();
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070051 }
52
53 Ptr<const Interest>
54 GetInterest () const
55 {
56 return m_interest;
57 }
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070058
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 Afanasyeva4e74282013-07-11 15:23:20 -070080
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070081private:
82 std::list<ApiFace::DataCallback> m_dataCallbacks;
83 std::list<ApiFace::TimeoutCallback> m_timeoutCallbacks;
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070084 Ptr<const Interest> m_interest;
85};
86
87
88struct 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