shockjiang | e9c1ab9 | 2014-07-21 12:02:52 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * response.h |
| 3 | * |
| 4 | * Created on: 19 Jul, 2014 |
| 5 | * Author: shock |
| 6 | */ |
| 7 | |
| 8 | #ifndef RESPONSE_H_ |
| 9 | #define RESPONSE_H_ |
| 10 | |
| 11 | #include <boost/asio.hpp> // /opt/local/include |
| 12 | #include <boost/bind.hpp> |
| 13 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 14 | #include <boost/noncopyable.hpp> |
| 15 | |
| 16 | #include <ndn-cxx/face.hpp> // /usr/local/include |
| 17 | #include <ndn-cxx/name.hpp> |
| 18 | #include <ndn-cxx/data.hpp> |
| 19 | |
| 20 | #include <ndn-cxx/encoding/block-helpers.hpp> |
| 21 | #include <ndn-cxx/encoding/block.hpp> |
| 22 | #include <ndn-cxx/encoding/tlv-ndnd.hpp> |
| 23 | |
| 24 | #include<vector> |
| 25 | |
| 26 | #include "ndns-tlv.h" |
| 27 | |
| 28 | using namespace std; |
| 29 | |
| 30 | namespace ndn { |
| 31 | |
| 32 | |
| 33 | |
| 34 | enum class ResponseType |
| 35 | { |
| 36 | NDNS_Resp, |
| 37 | NDNS_Nack, |
| 38 | NDNS_Auth |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | static const string |
| 43 | toString(ResponseType responseType) const |
| 44 | { |
| 45 | string label; |
| 46 | switch (responseType) |
| 47 | { |
| 48 | case ResponseType::NDNS_Resp: |
| 49 | label = "NDNS Resp"; |
| 50 | break; |
| 51 | case ResponseType::NDNS_Nack: |
| 52 | label = "NDNS Nack"; |
| 53 | break; |
| 54 | case ResponseType::NDNS_Auth: |
| 55 | label = "NDNS Auth"; |
| 56 | break; |
| 57 | default: |
| 58 | label = "Default"; |
| 59 | break; |
| 60 | } |
| 61 | return label; |
| 62 | } |
| 63 | |
| 64 | class Response { |
| 65 | public: |
| 66 | Response(); |
| 67 | virtual ~Response(); |
| 68 | |
| 69 | Data |
| 70 | toWire() const; |
| 71 | |
| 72 | void |
| 73 | fromWire(const Interest &interest, const Data &data); |
| 74 | |
| 75 | private: |
| 76 | Name m_queryName; |
| 77 | string m_serial; |
| 78 | ResponseType m_responseType; |
| 79 | |
| 80 | time::milliseconds m_freshness; |
| 81 | |
| 82 | unsigned int m_numberOfRR; |
| 83 | vector<RR> m_rrs; |
| 84 | |
| 85 | }; |
| 86 | |
| 87 | } /* namespace ndn */ |
| 88 | |
| 89 | #endif /* RESPONSE_H_ */ |