blob: 778d5632e42c89ee487a06cd98cb973a70494156 [file] [log] [blame]
Shock Jiang698e6ed2014-11-09 11:22:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
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
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
59 /**
60 * @brief start query process.
61 */
62 virtual void
63 start() = 0;
64
65 /**
66 * @brief should keep sending query, or has ended yet,
67 */
68 virtual bool
69 hasEnded() = 0;
70
71public:
72 ////////////////
73 // getter
74
75 const Name&
76 getDstLabel() const
77 {
78 return m_dstLabel;
79 }
80
81 const time::milliseconds&
82 getInterestLifetime() const
83 {
84 return m_interestLifetime;
85 }
86
87 const name::Component&
88 getRrType() const
89 {
90 return m_rrType;
91 }
92
93protected:
94 const Name m_dstLabel;
95 const name::Component m_rrType;
96 const time::milliseconds m_interestLifetime;
97
98 const QuerySucceedCallback m_onSucceed;
99 const QueryFailCallback m_onFail;
100
101 Face& m_face;
102
103};
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