blob: a78b5df247f13a27a22b8993097ad889dc3def41 [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 Pesavento948c50c2020-12-26 21:30:45 -05003 * Copyright (c) 2014-2020, 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 */
39typedef function<void(const Data&, const Response&)> QuerySucceedCallback;
40
41/**
42 * @brief callback function when failing to get the final Response
43 */
44typedef function<void(uint32_t errCode, const std::string& errMsg)> QueryFailCallback;
45
46/**
47 * @brief a Query Controller interface
48 *
49 */
Davide Pesavento948c50c2020-12-26 21:30:45 -050050class QueryController : boost::noncopyable
Shock Jiang698e6ed2014-11-09 11:22:24 -080051{
52public:
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 Afanasyev08d18742018-03-15 16:31:28 -040058 virtual
59 ~QueryController() = default;
60
Shock Jiang698e6ed2014-11-09 11:22:24 -080061 /**
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 Jiang5d5928c2014-12-03 13:41:22 -080073 virtual void
74 setStartComponentIndex(size_t startIndex) = 0;
75
Shock Jiang698e6ed2014-11-09 11:22:24 -080076public:
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
98protected:
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
110std::ostream&
111operator<<(std::ostream& os, const QueryController& ctr);
112
113} // namespace ndns
114} // namespace ndn
115
116#endif // NDNS_CLIENTS_QUERY_CONTROLLER_HPP