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