blob: 74e15fece1abcdde88d004cfa9dfb98796e7c554 [file] [log] [blame]
Alexander Afanasyev18371872014-01-05 23:00:26 -08001/* -*- 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 Afanasyevc8823bc2014-02-09 19:33:33 -08007#ifndef NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP
8#define NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP
Alexander Afanasyev18371872014-01-05 23:00:26 -08009
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080010#include "../encoding/block.hpp"
11#include "../encoding/tlv-face-management.hpp"
Alexander Afanasyev18371872014-01-05 23:00:26 -080012
13namespace ndn {
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080014namespace ndnd {
Alexander Afanasyev18371872014-01-05 23:00:26 -080015
16class StatusResponse {
17public:
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
47private:
48 uint32_t code_;
49 std::string info_;
50
51 mutable Block wire_;
52};
53
54inline uint32_t
55StatusResponse::getCode() const
56{
57 return code_;
58}
59
60inline void
61StatusResponse::setCode(uint32_t code)
62{
63 code_ = code;
64 wire_.reset();
65}
66
67inline const std::string &
68StatusResponse::getInfo() const
69{
70 return info_;
71}
72
73inline void
74StatusResponse::setInfo(const std::string &info)
75{
76 info_ = info;
77 wire_.reset();
78}
79
80
81inline const Block&
82StatusResponse::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
101inline void
102StatusResponse::wireDecode(const Block &wire)
103{
104 wire_ = wire;
105 wire_.parse();
106
107 code_ = readNonNegativeInteger(wire_.get(Tlv::FaceManagement::StatusCode));
108
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -0800109 Block::element_const_iterator val = wire_.find(Tlv::FaceManagement::StatusText);
110 if (val != wire_.elements_end())
Alexander Afanasyev18371872014-01-05 23:00:26 -0800111 {
112 info_.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
113 }
114}
115
116inline std::ostream&
117operator << (std::ostream &os, const StatusResponse &status)
118{
119 os << status.getCode() << " " << status.getInfo();
120 return os;
121}
122
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800123} // namespace ndnd
124} // namespace ndn
Alexander Afanasyev18371872014-01-05 23:00:26 -0800125
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800126#endif // NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP