blob: 5c5c5d1f0d31364b2d2bbfd20fd1fbc7efa61e5f [file] [log] [blame]
Eric Newberry4b5a5cf2015-08-06 22:00:43 -07001/* -*- 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 Shi4b469982015-12-03 18:20:19 +000028#include "../tag.hpp"
Eric Newberry4b5a5cf2015-08-06 22:00:43 -070029#include "../encoding/encoding-buffer.hpp"
30#include "../encoding/block-helpers.hpp"
31
32#include "tlv.hpp"
33
34namespace ndn {
35namespace lp {
36
37/**
38 * \brief indicates the cache policy applied to a Data packet
39 */
40enum class CachePolicyType {
41 NONE = 0,
42 NO_CACHE = 1
43};
44
45std::ostream&
46operator<<(std::ostream& os, CachePolicyType policy);
47
48/**
49 * \brief represents a CachePolicy header field
50 */
51class CachePolicy
52{
53public:
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
90public: // 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
105private:
106 CachePolicyType m_policy;
107 mutable Block m_wire;
108};
109
110} // namespace lp
111} // namespace ndn
112
Junxiao Shi4b469982015-12-03 18:20:19 +0000113#endif // NDN_CXX_LP_CACHE_POLICY_HPP