Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 7 | #ifndef NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP |
| 8 | #define NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 10 | #include "../encoding/block.hpp" |
| 11 | #include "../encoding/tlv-face-management.hpp" |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 14 | namespace ndnd { |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 15 | |
| 16 | class StatusResponse { |
| 17 | public: |
| 18 | StatusResponse() |
| 19 | : code_(0) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | StatusResponse(uint32_t code, const std::string &info) |
| 24 | : code_(code) |
| 25 | , info_(info) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | inline uint32_t |
| 30 | getCode() const; |
| 31 | |
| 32 | inline void |
| 33 | setCode(uint32_t code); |
| 34 | |
| 35 | inline const std::string & |
| 36 | getInfo() const; |
| 37 | |
| 38 | inline void |
| 39 | setInfo(const std::string &info); |
| 40 | |
| 41 | inline const Block& |
| 42 | wireEncode() const; |
| 43 | |
| 44 | inline void |
| 45 | wireDecode(const Block &block); |
| 46 | |
| 47 | private: |
| 48 | uint32_t code_; |
| 49 | std::string info_; |
| 50 | |
| 51 | mutable Block wire_; |
| 52 | }; |
| 53 | |
| 54 | inline uint32_t |
| 55 | StatusResponse::getCode() const |
| 56 | { |
| 57 | return code_; |
| 58 | } |
| 59 | |
| 60 | inline void |
| 61 | StatusResponse::setCode(uint32_t code) |
| 62 | { |
| 63 | code_ = code; |
| 64 | wire_.reset(); |
| 65 | } |
| 66 | |
| 67 | inline const std::string & |
| 68 | StatusResponse::getInfo() const |
| 69 | { |
| 70 | return info_; |
| 71 | } |
| 72 | |
| 73 | inline void |
| 74 | StatusResponse::setInfo(const std::string &info) |
| 75 | { |
| 76 | info_ = info; |
| 77 | wire_.reset(); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | inline const Block& |
| 82 | StatusResponse::wireEncode() const |
| 83 | { |
| 84 | if (wire_.hasWire()) |
| 85 | return wire_; |
| 86 | |
| 87 | wire_ = Block(Tlv::FaceManagement::StatusResponse); |
| 88 | wire_.push_back |
| 89 | (nonNegativeIntegerBlock(Tlv::FaceManagement::StatusCode, code_)); |
| 90 | |
| 91 | if (!info_.empty()) |
| 92 | { |
| 93 | wire_.push_back |
| 94 | (dataBlock(Tlv::FaceManagement::StatusText, info_.c_str(), info_.size())); |
| 95 | } |
| 96 | |
| 97 | wire_.encode(); |
| 98 | return wire_; |
| 99 | } |
| 100 | |
| 101 | inline void |
| 102 | StatusResponse::wireDecode(const Block &wire) |
| 103 | { |
| 104 | wire_ = wire; |
| 105 | wire_.parse(); |
| 106 | |
| 107 | code_ = readNonNegativeInteger(wire_.get(Tlv::FaceManagement::StatusCode)); |
| 108 | |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 109 | Block::element_const_iterator val = wire_.find(Tlv::FaceManagement::StatusText); |
| 110 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 111 | { |
| 112 | info_.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | inline std::ostream& |
| 117 | operator << (std::ostream &os, const StatusResponse &status) |
| 118 | { |
| 119 | os << status.getCode() << " " << status.getInfo(); |
| 120 | return os; |
| 121 | } |
| 122 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 123 | } // namespace ndnd |
| 124 | } // namespace ndn |
Alexander Afanasyev | 1837187 | 2014-01-05 23:00:26 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 126 | #endif // NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP |