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 | 6727297 | 2023-03-16 17:20:22 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, 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 | */ |
Davide Pesavento | 6727297 | 2023-03-16 17:20:22 -0400 | [diff] [blame] | 39 | using QuerySucceedCallback = std::function<void(const Data&, const Response&)>; |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * @brief callback function when failing to get the final Response |
| 43 | */ |
Davide Pesavento | 6727297 | 2023-03-16 17:20:22 -0400 | [diff] [blame] | 44 | using QueryFailCallback = std::function<void(uint32_t errCode, const std::string& errMsg)>; |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * @brief a Query Controller interface |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 48 | */ |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 49 | class QueryController : boost::noncopyable |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | QueryController(const Name& dstLabel, const name::Component& rrType, |
| 53 | const time::milliseconds& interestLifetime, |
| 54 | const QuerySucceedCallback& onSucceed, const QueryFailCallback& onFail, |
| 55 | Face& face); |
| 56 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 57 | virtual |
| 58 | ~QueryController() = default; |
| 59 | |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 60 | /** |
| 61 | * @brief start query process. |
| 62 | */ |
| 63 | virtual void |
| 64 | start() = 0; |
| 65 | |
| 66 | /** |
| 67 | * @brief should keep sending query, or has ended yet, |
| 68 | */ |
| 69 | virtual bool |
| 70 | hasEnded() = 0; |
| 71 | |
Shock Jiang | 5d5928c | 2014-12-03 13:41:22 -0800 | [diff] [blame] | 72 | virtual void |
| 73 | setStartComponentIndex(size_t startIndex) = 0; |
| 74 | |
Davide Pesavento | 6727297 | 2023-03-16 17:20:22 -0400 | [diff] [blame] | 75 | public: // getters |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 76 | const Name& |
| 77 | getDstLabel() const |
| 78 | { |
| 79 | return m_dstLabel; |
| 80 | } |
| 81 | |
| 82 | const time::milliseconds& |
| 83 | getInterestLifetime() const |
| 84 | { |
| 85 | return m_interestLifetime; |
| 86 | } |
| 87 | |
| 88 | const name::Component& |
| 89 | getRrType() const |
| 90 | { |
| 91 | return m_rrType; |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | const Name m_dstLabel; |
| 96 | const name::Component m_rrType; |
| 97 | const time::milliseconds m_interestLifetime; |
| 98 | |
| 99 | const QuerySucceedCallback m_onSucceed; |
| 100 | const QueryFailCallback m_onFail; |
| 101 | |
| 102 | Face& m_face; |
Shock Jiang | 698e6ed | 2014-11-09 11:22:24 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | std::ostream& |
| 106 | operator<<(std::ostream& os, const QueryController& ctr); |
| 107 | |
| 108 | } // namespace ndns |
| 109 | } // namespace ndn |
| 110 | |
| 111 | #endif // NDNS_CLIENTS_QUERY_CONTROLLER_HPP |