blob: 8a8464523e5af29c24a60d21e38bb5347bcc030a [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/*
3 * Copyright (c) 2014-2018, 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
23#include "query.hpp"
24#include "response.hpp"
25
26#include <ndn-cxx/data.hpp>
27#include <ndn-cxx/interest.hpp>
28#include <ndn-cxx/name.hpp>
29#include <ndn-cxx/face.hpp>
30
31
32namespace ndn {
33namespace ndns {
34
35/**
36 * @brief callback function when succeeding getting the final Response
37 * @param[in] Data the Data packet which contains the Response, client should verify the packet
38 * @param[in] Response the Final Response converted from Data
39 */
40typedef function<void(const Data&, const Response&)> QuerySucceedCallback;
41
42/**
43 * @brief callback function when failing to get the final Response
44 */
45typedef function<void(uint32_t errCode, const std::string& errMsg)> QueryFailCallback;
46
47/**
48 * @brief a Query Controller interface
49 *
50 */
51class QueryController : noncopyable
52{
53public:
54 QueryController(const Name& dstLabel, const name::Component& rrType,
55 const time::milliseconds& interestLifetime,
56 const QuerySucceedCallback& onSucceed, const QueryFailCallback& onFail,
57 Face& face);
58
Alexander Afanasyev08d18742018-03-15 16:31:28 -040059 virtual
60 ~QueryController() = default;
61
Shock Jiang698e6ed2014-11-09 11:22:24 -080062 /**
63 * @brief start query process.
64 */
65 virtual void
66 start() = 0;
67
68 /**
69 * @brief should keep sending query, or has ended yet,
70 */
71 virtual bool
72 hasEnded() = 0;
73
Shock Jiang5d5928c2014-12-03 13:41:22 -080074 virtual void
75 setStartComponentIndex(size_t startIndex) = 0;
76
Shock Jiang698e6ed2014-11-09 11:22:24 -080077public:
78 ////////////////
79 // getter
80
81 const Name&
82 getDstLabel() const
83 {
84 return m_dstLabel;
85 }
86
87 const time::milliseconds&
88 getInterestLifetime() const
89 {
90 return m_interestLifetime;
91 }
92
93 const name::Component&
94 getRrType() const
95 {
96 return m_rrType;
97 }
98
99protected:
100 const Name m_dstLabel;
101 const name::Component m_rrType;
102 const time::milliseconds m_interestLifetime;
103
104 const QuerySucceedCallback m_onSucceed;
105 const QueryFailCallback m_onFail;
106
107 Face& m_face;
108
109};
110
111std::ostream&
112operator<<(std::ostream& os, const QueryController& ctr);
113
114} // namespace ndns
115} // namespace ndn
116
117#endif // NDNS_CLIENTS_QUERY_CONTROLLER_HPP