blob: 66002977e090965db1121994c81a91dbebbd5c67 [file] [log] [blame]
spirosmastorakis9b68b532016-05-02 21:40:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3* Copyright (c) 2016 Regents of the University of California.
4*
5* This file is part of the nTorrent codebase.
6*
7* nTorrent is free software: you can redistribute it and/or modify it under the
8* terms of the GNU Lesser General Public License as published by the Free Software
9* Foundation, either version 3 of the License, or (at your option) any later version.
10*
11* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
12* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14*
15* You should have received copies of the GNU General Public License and GNU Lesser
16* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
17* <http://www.gnu.org/licenses/>.
18*
19* See AUTHORS for complete list of nTorrent authors and contributors.
20*/
21
22#include <ndn-cxx/data.hpp>
23#include <ndn-cxx/face.hpp>
24#include <ndn-cxx/interest.hpp>
25
26#include <queue>
27#include <tuple>
28
29typedef std::tuple<std::shared_ptr<ndn::Interest>, ndn::DataCallback, ndn::TimeoutCallback> queueTuple;
30
31namespace ndn {
32namespace ntorrent {
33
34class InterestQueue
35{
36public:
37 InterestQueue() = default;
38
39 ~InterestQueue() = default;
40
41 /**
42 * @brief Push a tuple to the Interest Queue
43 * @param interest A shared pointer to an Interest
44 * @param dataReceivedCallback Callback to be called when data is received for the given
45 * Interest
46 * @param dataFailedCallback Callback to be called when we fail to retrieve data for the
47 * given Interest
48 *
49 */
50 void
51 push(shared_ptr<Interest> interest, DataCallback dataReceivedCallback,
52 TimeoutCallback dataFailedCallback);
53
54 /**
55 * @brief Pop a tuple from the Interest Queue
56 * @return A tuple of a shared pointer to an Interest, a callaback for successful data
57 * retrieval and a callback for failed data retrieval
58 */
59 queueTuple
60 pop();
61
62 /**
63 * @brief Return the size of the queue (number of tuples)
64 * @return The number of tuples stored in the queue
65 */
66 size_t
67 size() const;
68
69 /**
70 * @brief Check if the queue is empty
71 * @return True if the queue is empty, otherwise false
72 */
73 bool
74 empty() const;
75
76 /**
77 * @brief Return the top element of the Interest queue
78 * @return The top tuple element of the Interest queue
79 */
80 queueTuple
81 front() const;
82
83private:
84 std::queue<queueTuple> m_queue;
85};
86
87inline size_t
88InterestQueue::size() const
89{
90 return m_queue.size();
91}
92
93inline bool
94InterestQueue::empty() const
95{
96 return m_queue.empty();
97}
98
99inline queueTuple
100InterestQueue::front() const
101{
102 return m_queue.front();
103}
104
105} // namespace ntorrent
106} // namespace ndn