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