Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | b6355e8 | 2017-08-10 21:27:08 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame] | 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 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 22 | */ |
| 23 | |
| 24 | #ifndef NDN_CXX_LP_CACHE_POLICY_HPP |
| 25 | #define NDN_CXX_LP_CACHE_POLICY_HPP |
| 26 | |
Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame] | 27 | #include "../encoding/encoding-buffer.hpp" |
Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame] | 28 | #include "tlv.hpp" |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace lp { |
| 32 | |
| 33 | /** |
| 34 | * \brief indicates the cache policy applied to a Data packet |
| 35 | */ |
| 36 | enum class CachePolicyType { |
| 37 | NONE = 0, |
| 38 | NO_CACHE = 1 |
| 39 | }; |
| 40 | |
| 41 | std::ostream& |
| 42 | operator<<(std::ostream& os, CachePolicyType policy); |
| 43 | |
| 44 | /** |
| 45 | * \brief represents a CachePolicy header field |
| 46 | */ |
| 47 | class CachePolicy |
| 48 | { |
| 49 | public: |
| 50 | class Error : public ndn::tlv::Error |
| 51 | { |
| 52 | public: |
| 53 | explicit |
| 54 | Error(const std::string& what) |
| 55 | : ndn::tlv::Error(what) |
| 56 | { |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | CachePolicy(); |
| 61 | |
| 62 | explicit |
| 63 | CachePolicy(const Block& block); |
| 64 | |
| 65 | /** |
| 66 | * \brief prepend CachePolicy to encoder |
| 67 | * \pre getPolicy() != CachePolicyType::NONE |
| 68 | * \throw Error policy type is unset |
| 69 | */ |
| 70 | template<encoding::Tag TAG> |
| 71 | size_t |
| 72 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 73 | |
| 74 | /** |
| 75 | * \brief encode CachePolicy into wire format |
| 76 | */ |
| 77 | const Block& |
| 78 | wireEncode() const; |
| 79 | |
| 80 | /** |
| 81 | * \brief get CachePolicyType from wire format |
| 82 | */ |
| 83 | void |
| 84 | wireDecode(const Block& wire); |
| 85 | |
| 86 | public: // policy type |
| 87 | /** |
| 88 | * \return policy type code |
| 89 | * \retval CachePolicyType::NONE if policy type is unset or has an unknown code |
| 90 | */ |
| 91 | CachePolicyType |
| 92 | getPolicy() const; |
| 93 | |
| 94 | /** |
| 95 | * \brief set policy type code |
| 96 | * \param policy a policy type code; CachePolicyType::NONE clears the policy |
| 97 | */ |
| 98 | CachePolicy& |
| 99 | setPolicy(CachePolicyType policy); |
| 100 | |
| 101 | private: |
| 102 | CachePolicyType m_policy; |
| 103 | mutable Block m_wire; |
| 104 | }; |
| 105 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 106 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CachePolicy); |
| 107 | |
Eric Newberry | 4b5a5cf | 2015-08-06 22:00:43 -0700 | [diff] [blame] | 108 | } // namespace lp |
| 109 | } // namespace ndn |
| 110 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 111 | #endif // NDN_CXX_LP_CACHE_POLICY_HPP |