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