shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 14 | using namespace std; |
| 15 | |
| 16 | namespace ndn { |
| 17 | |
| 18 | |
| 19 | enum class QueryType |
| 20 | { |
| 21 | DNS, |
| 22 | DNS_R, |
| 23 | }; |
| 24 | |
| 25 | static const string |
| 26 | toString(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 | |
| 45 | static const QueryType |
| 46 | toQueryType(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 | |
| 67 | class Query { |
| 68 | public: |
| 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 | |
| 115 | private: |
| 116 | template<bool T> |
| 117 | size_t |
| 118 | wireEncode(EncodingImpl<T> & block) const; |
| 119 | |
| 120 | public: |
| 121 | |
| 122 | const Block& |
| 123 | wireEncode() const; |
| 124 | |
| 125 | void |
| 126 | wireDecode(const Block& wire); |
| 127 | |
| 128 | |
| 129 | Interest |
| 130 | toWire() const; |
| 131 | |
| 132 | void |
| 133 | fromWire(const Name &name, const Interest& interest); |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | public: |
| 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_ */ |