blob: f772101e5ed919373725fcac2efe653beab5df50 [file] [log] [blame]
Eric Newberry4b5a5cf2015-08-06 22:00:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventob6355e82017-08-10 21:27:08 -04002/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 Regents of the University of California.
Eric Newberry4b5a5cf2015-08-06 22:00:43 -07004 *
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 Newberry4b5a5cf2015-08-06 22:00:43 -070027#include "../encoding/encoding-buffer.hpp"
Eric Newberry4b5a5cf2015-08-06 22:00:43 -070028#include "tlv.hpp"
29
30namespace ndn {
31namespace lp {
32
33/**
34 * \brief indicates the cache policy applied to a Data packet
35 */
36enum class CachePolicyType {
37 NONE = 0,
38 NO_CACHE = 1
39};
40
41std::ostream&
42operator<<(std::ostream& os, CachePolicyType policy);
43
44/**
45 * \brief represents a CachePolicy header field
46 */
47class CachePolicy
48{
49public:
50 class Error : public ndn::tlv::Error
51 {
52 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060053 using ndn::tlv::Error::Error;
Eric Newberry4b5a5cf2015-08-06 22:00:43 -070054 };
55
56 CachePolicy();
57
58 explicit
59 CachePolicy(const Block& block);
60
61 /**
62 * \brief prepend CachePolicy to encoder
63 * \pre getPolicy() != CachePolicyType::NONE
64 * \throw Error policy type is unset
65 */
66 template<encoding::Tag TAG>
67 size_t
68 wireEncode(EncodingImpl<TAG>& encoder) const;
69
70 /**
71 * \brief encode CachePolicy into wire format
72 */
73 const Block&
74 wireEncode() const;
75
76 /**
77 * \brief get CachePolicyType from wire format
78 */
79 void
80 wireDecode(const Block& wire);
81
82public: // policy type
83 /**
84 * \return policy type code
85 * \retval CachePolicyType::NONE if policy type is unset or has an unknown code
86 */
87 CachePolicyType
88 getPolicy() const;
89
90 /**
91 * \brief set policy type code
92 * \param policy a policy type code; CachePolicyType::NONE clears the policy
93 */
94 CachePolicy&
95 setPolicy(CachePolicyType policy);
96
97private:
98 CachePolicyType m_policy;
99 mutable Block m_wire;
100};
101
Davide Pesavento88a0d812017-08-19 21:31:42 -0400102NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CachePolicy);
103
Eric Newberry4b5a5cf2015-08-06 22:00:43 -0700104} // namespace lp
105} // namespace ndn
106
Junxiao Shi4b469982015-12-03 18:20:19 +0000107#endif // NDN_CXX_LP_CACHE_POLICY_HPP