Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 13 | * |
| 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 26 | * @author Zhuo Li <zhuoli@email.arizona.edu> |
| 27 | */ |
| 28 | |
| 29 | #ifndef NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |
| 30 | #define NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |
| 31 | |
| 32 | #include "core/common.hpp" |
| 33 | |
| 34 | namespace ndn { |
| 35 | namespace peek { |
| 36 | |
| 37 | /** |
| 38 | * @brief options for NdnPeek |
| 39 | */ |
| 40 | struct PeekOptions |
| 41 | { |
| 42 | std::string prefix; |
| 43 | int minSuffixComponents; |
| 44 | int maxSuffixComponents; |
| 45 | time::milliseconds interestLifetime; |
| 46 | time::milliseconds timeout; |
| 47 | shared_ptr<Link> link; |
| 48 | bool isVerbose; |
| 49 | bool mustBeFresh; |
| 50 | bool wantRightmostChild; |
| 51 | bool wantPayloadOnly; |
| 52 | }; |
| 53 | |
| 54 | enum class ResultCode { |
| 55 | NONE = -1, |
| 56 | DATA = 0, |
| 57 | NACK = 4, |
| 58 | TIMEOUT = 3 |
| 59 | }; |
| 60 | |
| 61 | class NdnPeek : boost::noncopyable |
| 62 | { |
| 63 | public: |
| 64 | NdnPeek(Face& face, const PeekOptions& options); |
| 65 | |
| 66 | /** |
| 67 | * @return the timeout |
| 68 | */ |
| 69 | time::milliseconds |
| 70 | getTimeout() const; |
| 71 | |
| 72 | /** |
| 73 | * @return the result of Peek execution |
| 74 | */ |
| 75 | ResultCode |
| 76 | getResultCode() const; |
| 77 | |
| 78 | /** |
| 79 | * @brief express the Interest |
| 80 | * @note The caller must invoke face.processEvents() afterwards |
| 81 | */ |
| 82 | void |
| 83 | start(); |
| 84 | |
| 85 | private: |
| 86 | Interest |
| 87 | createInterest() const; |
| 88 | |
| 89 | /** |
| 90 | * @brief called when a Data packet is received |
| 91 | */ |
| 92 | void |
| 93 | onData(const Data& data); |
| 94 | |
| 95 | /** |
| 96 | * @brief called when a Nack packet is received |
| 97 | */ |
| 98 | void |
| 99 | onNack(const lp::Nack& nack); |
| 100 | |
| 101 | private: |
| 102 | Face& m_face; |
| 103 | const PeekOptions& m_options; |
| 104 | time::steady_clock::TimePoint m_expressInterestTime; |
| 105 | time::milliseconds m_timeout; |
| 106 | ResultCode m_resultCode; |
| 107 | }; |
| 108 | |
| 109 | } // namespace peek |
| 110 | } // namespace ndn |
| 111 | |
| 112 | #endif // NDN_TOOLS_NDNPEEK_NDNPEEK_HPP |