blob: 673d33b3401a885ae4ba215c2eed43274339aba1 [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 {
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070036 m_dataCallbacks.push_back (onData);
37 m_timeoutCallbacks.push_back (onTimeout);
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070038 }
39
40 void
41 ClearCallbacks ()
42 {
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070043 m_dataCallbacks.clear ();
44 m_timeoutCallbacks.clear ();
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070045 }
46
47 Ptr<const Interest>
48 GetInterest () const
49 {
50 return m_interest;
51 }
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070052
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 Afanasyeva4e74282013-07-11 15:23:20 -070074
Alexander Afanasyevbaccf7d2013-08-09 12:38:44 -070075private:
76 std::list<ApiFace::DataCallback> m_dataCallbacks;
77 std::list<ApiFace::TimeoutCallback> m_timeoutCallbacks;
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070078 Ptr<const Interest> m_interest;
79};
80
81
82struct 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