blob: ac4c94a34339b25f17138c53b1527bffb1271291 [file] [log] [blame]
Shock Jiang698e6ed2014-11-09 11:22:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev08d18742018-03-15 16:31:28 -04002/*
Davide Pesavento67272972023-03-16 17:20:22 -04003 * Copyright (c) 2014-2023, Regents of the University of California.
Shock Jiang698e6ed2014-11-09 11:22:24 -08004 *
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 Pesavento948c50c2020-12-26 21:30:45 -050023#include "common.hpp"
Shock Jiang698e6ed2014-11-09 11:22:24 -080024#include "query.hpp"
25#include "response.hpp"
26
27#include <ndn-cxx/data.hpp>
28#include <ndn-cxx/interest.hpp>
Shock Jiang698e6ed2014-11-09 11:22:24 -080029#include <ndn-cxx/face.hpp>
30
Shock Jiang698e6ed2014-11-09 11:22:24 -080031namespace ndn {
32namespace 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 Pesavento67272972023-03-16 17:20:22 -040039using QuerySucceedCallback = std::function<void(const Data&, const Response&)>;
Shock Jiang698e6ed2014-11-09 11:22:24 -080040
41/**
42 * @brief callback function when failing to get the final Response
43 */
Davide Pesavento67272972023-03-16 17:20:22 -040044using QueryFailCallback = std::function<void(uint32_t errCode, const std::string& errMsg)>;
Shock Jiang698e6ed2014-11-09 11:22:24 -080045
46/**
47 * @brief a Query Controller interface
Shock Jiang698e6ed2014-11-09 11:22:24 -080048 */
Davide Pesavento948c50c2020-12-26 21:30:45 -050049class QueryController : boost::noncopyable
Shock Jiang698e6ed2014-11-09 11:22:24 -080050{
51public:
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 Afanasyev08d18742018-03-15 16:31:28 -040057 virtual
58 ~QueryController() = default;
59
Shock Jiang698e6ed2014-11-09 11:22:24 -080060 /**
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 Jiang5d5928c2014-12-03 13:41:22 -080072 virtual void
73 setStartComponentIndex(size_t startIndex) = 0;
74
Davide Pesavento67272972023-03-16 17:20:22 -040075public: // getters
Shock Jiang698e6ed2014-11-09 11:22:24 -080076 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
94protected:
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 Jiang698e6ed2014-11-09 11:22:24 -0800103};
104
105std::ostream&
106operator<<(std::ostream& os, const QueryController& ctr);
107
108} // namespace ndns
109} // namespace ndn
110
111#endif // NDNS_CLIENTS_QUERY_CONTROLLER_HPP