blob: 001efa09f2181f87e7d8915be3e9c6c23c38e4f6 [file] [log] [blame]
shockjiange9c1ab92014-07-21 12:02:52 -07001/*
2 * query.h
3 *
4 * Created on: 18 Jul, 2014
5 * Author: shock
6 */
7
8#ifndef QUERY_H_
9#define QUERY_H_
10
11#include <ndn-cxx/name.hpp>
12#include <rr.h>
13
14using namespace std;
15
16namespace ndn {
17
18
19enum class QueryType
20{
21 DNS,
22 DNS_R,
23};
24
25static const string
26toString(QueryType qType) const
27{
28 string label;
29 switch (qType)
30 {
31 case QueryType::DNS:
32 label = "DNS";
33 break;
34 case QueryType::DNS_R:
35 label = "DNS-R";
36 break;
37 default:
38 label = "Default";
39 break;
40 }
41 return label;
42
43}
44
45static const QueryType
46toQueryType(string str)
47{
48 QueryType atype;
49 switch (str)
50 {
51 case "DNS":
52 atype = QueryType::DNS;
53 break;
54 case "DNS-R":
55 atype = QueryType::DNS_R;
56 break;
57 defalut:
58 atype = QueryType::DNS;
59 break;
60 }
61 return atype;
62}
63
64
65
66
67class Query {
68public:
69 Query();
70
71 virtual ~Query();
72
73
74
75 const Name& getAuthorityZone() const {
76 return m_authorityZone;
77 }
78
79 void setAuthorityZone(const Name& authorityZone) {
80 m_authorityZone = authorityZone;
81 }
82
83 time::milliseconds getInterestLifetime() const {
84 return m_interestLifetime;
85 }
86
87 void setInterestLifetime(time::milliseconds interestLifetime) {
88 m_interestLifetime = interestLifetime;
89 }
90
91 enum QueryType getQueryType() const {
92 return m_queryType;
93 }
94
95 void setQueryType(enum QueryType queryType) {
96 m_queryType = queryType;
97 }
98
99 const Name& getRrLabel() const {
100 return m_rrLabel;
101 }
102
103 void setRrLabel(const Name& rrLabel) {
104 m_rrLabel = rrLabel;
105 }
106
107 const RRType& getRrType() const {
108 return m_rrType;
109 }
110
111 void setRrType(const RRType& rrType) {
112 m_rrType = rrType;
113 }
114
115private:
116template<bool T>
117size_t
118wireEncode(EncodingImpl<T> & block) const;
119
120public:
121
122const Block&
123wireEncode() const;
124
125void
126wireDecode(const Block& wire);
127
128
129Interest
130toWire() const;
131
132void
133fromWire(const Name &name, const Interest& interest);
134
135
136
137
138
139public:
140 Name m_authorityZone;
141 enum QueryType m_queryType;
142 time::milliseconds m_interestLifetime;
143 Name m_rrLabel;
144 enum RRType m_rrType;
145
146 mutable Block m_wire;
147 //bool hasWire;
148};
149
150} /* namespace ndn */
151
152#endif /* QUERY_H_ */