Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, Regents of the University of California. |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NDNS_CLIENTS_QUERY_CONTROLLER_HPP |
| 21 | #define NDNS_CLIENTS_QUERY_CONTROLLER_HPP |
| 22 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame^] | 23 | #include "common.hpp" |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 24 | #include "query.hpp" |
| 25 | #include "response.hpp" |
| 26 | |
| 27 | #include <ndn-cxx/data.hpp> |
| 28 | #include <ndn-cxx/interest.hpp> |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 29 | #include <ndn-cxx/face.hpp> |
| 30 | |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 31 | namespace ndn { |
| 32 | namespace ndns { |
| 33 | |
| 34 | /** |
| 35 | * @brief callback function when succeeding getting the final Response |
| 36 | * @param[in] Data the Data packet which contains the Response, client should verify the packet |
| 37 | * @param[in] Response the Final Response converted from Data |
| 38 | */ |
| 39 | typedef function<void(const Data&, const Response&)> QuerySucceedCallback; |
| 40 | |
| 41 | /** |
| 42 | * @brief callback function when failing to get the final Response |
| 43 | */ |
| 44 | typedef function<void(uint32_t errCode, const std::string& errMsg)> QueryFailCallback; |
| 45 | |
| 46 | /** |
| 47 | * @brief a Query Controller interface |
| 48 | * |
| 49 | */ |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame^] | 50 | class QueryController : boost::noncopyable |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | QueryController(const Name& dstLabel, const name::Component& rrType, |
| 54 | const time::milliseconds& interestLifetime, |
| 55 | const QuerySucceedCallback& onSucceed, const QueryFailCallback& onFail, |
| 56 | Face& face); |
| 57 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 58 | virtual |
| 59 | ~QueryController() = default; |
| 60 | |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 61 | /** |
| 62 | * @brief start query process. |
| 63 | */ |
| 64 | virtual void |
| 65 | start() = 0; |
| 66 | |
| 67 | /** |
| 68 | * @brief should keep sending query, or has ended yet, |
| 69 | */ |
| 70 | virtual bool |
| 71 | hasEnded() = 0; |
| 72 | |
Shock Jiang | 5d5928c | 2014-12-03 13:41:22 -0800 | [diff] [blame] | 73 | virtual void |
| 74 | setStartComponentIndex(size_t startIndex) = 0; |
| 75 | |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 76 | public: |
| 77 | //////////////// |
| 78 | // getter |
| 79 | |
| 80 | const Name& |
| 81 | getDstLabel() const |
| 82 | { |
| 83 | return m_dstLabel; |
| 84 | } |
| 85 | |
| 86 | const time::milliseconds& |
| 87 | getInterestLifetime() const |
| 88 | { |
| 89 | return m_interestLifetime; |
| 90 | } |
| 91 | |
| 92 | const name::Component& |
| 93 | getRrType() const |
| 94 | { |
| 95 | return m_rrType; |
| 96 | } |
| 97 | |
| 98 | protected: |
| 99 | const Name m_dstLabel; |
| 100 | const name::Component m_rrType; |
| 101 | const time::milliseconds m_interestLifetime; |
| 102 | |
| 103 | const QuerySucceedCallback m_onSucceed; |
| 104 | const QueryFailCallback m_onFail; |
| 105 | |
| 106 | Face& m_face; |
| 107 | |
| 108 | }; |
| 109 | |
| 110 | std::ostream& |
| 111 | operator<<(std::ostream& os, const QueryController& ctr); |
| 112 | |
| 113 | } // namespace ndns |
| 114 | } // namespace ndn |
| 115 | |
| 116 | #endif // NDNS_CLIENTS_QUERY_CONTROLLER_HPP |