blob: 19069543acf9043d8f4cdd06591ad123ebc9e2dd [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22
23#ifndef NDN_PIB_DEFAULT_PARAM_HPP
24#define NDN_PIB_DEFAULT_PARAM_HPP
25
26#include "pib-common.hpp"
27#include <ndn-cxx/name.hpp>
28
29namespace ndn {
30namespace pib {
31
32/**
33 * @brief DefaultParam is the abstraction of PIB Default parameter.
34 *
35 * PibDefaultParam := PIB-DEFAULT-PARAM-TYPE TLV-LENGTH
36 * PibType // target type
37 * PibType // origin type
38 * Name? // origin name
39 *
40 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Default-Parameters
41 */
42
43class DefaultParam : noncopyable
44{
45public:
46 class Error : public tlv::Error
47 {
48 public:
49 explicit
50 Error(const std::string& what)
51 : tlv::Error(what)
52 {
53 }
54 };
55
56 DefaultParam();
57
58 DefaultParam(const pib::Type targetType,
59 const pib::Type originType,
60 const Name& originName = Name());
61
62 explicit
63 DefaultParam(const Block& wire);
64
65 tlv::pib::ParamType
66 getParamType() const
67 {
68 return tlv::pib::DefaultParam;
69 }
70
71 pib::Type
72 getTargetType() const
73 {
74 return m_targetType;
75 }
76
77 pib::Type
78 getOriginType() const
79 {
80 return m_originType;
81 }
82
83 /**
84 * @brief Get target name
85 *
86 * @throws Error if origin name does not exist
87 */
88 const Name&
89 getOriginName() const;
90
91 /// @brief Encode to a wire format or estimate wire format
92 template<bool T>
93 size_t
94 wireEncode(EncodingImpl<T>& block) const;
95
96 /**
97 * @brief Encode to a wire format
98 *
99 * @throws Error if encoding fails
100 */
101 const Block&
102 wireEncode() const;
103
104 /**
105 * @brief Decode GetParam from a wire encoded block
106 *
107 * @throws Error if decoding fails
108 */
109 void
110 wireDecode(const Block& wire);
111
112public:
113 static const std::string VERB;
114
115private:
116 pib::Type m_targetType;
117 pib::Type m_originType;
118 Name m_originName;
119
120 mutable Block m_wire;
121};
122
123} // namespace pib
124} // namespace ndn
125
126
127
128#endif // NDN_PIB_DEFAULT_PARAM_HPP