Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [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 | |
| 22 | #include "tags.hpp" |
| 23 | #include "../encoding/nfd-constants.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace lp { |
| 27 | |
| 28 | #ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER |
| 29 | |
| 30 | using ndn::nfd::INVALID_FACE_ID; |
| 31 | |
| 32 | LocalControlHeaderFacade::LocalControlHeaderFacade(TagHost& pkt) |
| 33 | : m_pkt(pkt) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | bool |
| 38 | LocalControlHeaderFacade::hasIncomingFaceId() const |
| 39 | { |
| 40 | return m_pkt.getTag<IncomingFaceIdTag>() != nullptr; |
| 41 | } |
| 42 | |
| 43 | uint64_t |
| 44 | LocalControlHeaderFacade::getIncomingFaceId() const |
| 45 | { |
| 46 | shared_ptr<IncomingFaceIdTag> tag = m_pkt.getTag<IncomingFaceIdTag>(); |
| 47 | if (tag == nullptr) { |
| 48 | return INVALID_FACE_ID; |
| 49 | } |
| 50 | return *tag; |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | LocalControlHeaderFacade::setIncomingFaceId(uint64_t incomingFaceId) |
| 55 | { |
| 56 | if (incomingFaceId == INVALID_FACE_ID) { |
| 57 | m_pkt.removeTag<IncomingFaceIdTag>(); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | auto tag = make_shared<IncomingFaceIdTag>(incomingFaceId); |
| 62 | m_pkt.setTag(tag); |
| 63 | } |
| 64 | |
| 65 | bool |
| 66 | LocalControlHeaderFacade::hasNextHopFaceId() const |
| 67 | { |
| 68 | return m_pkt.getTag<NextHopFaceIdTag>() != nullptr; |
| 69 | } |
| 70 | |
| 71 | uint64_t |
| 72 | LocalControlHeaderFacade::getNextHopFaceId() const |
| 73 | { |
| 74 | shared_ptr<NextHopFaceIdTag> tag = m_pkt.getTag<NextHopFaceIdTag>(); |
| 75 | if (tag == nullptr) { |
| 76 | return INVALID_FACE_ID; |
| 77 | } |
| 78 | return *tag; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | LocalControlHeaderFacade::setNextHopFaceId(uint64_t nextHopFaceId) |
| 83 | { |
| 84 | if (nextHopFaceId == INVALID_FACE_ID) { |
| 85 | m_pkt.removeTag<NextHopFaceIdTag>(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | auto tag = make_shared<NextHopFaceIdTag>(nextHopFaceId); |
| 90 | m_pkt.setTag(tag); |
| 91 | } |
| 92 | |
| 93 | bool |
| 94 | LocalControlHeaderFacade::hasCachingPolicy() const |
| 95 | { |
| 96 | return m_pkt.getTag<CachePolicyTag>() != nullptr; |
| 97 | } |
| 98 | |
| 99 | LocalControlHeaderFacade::CachingPolicy |
| 100 | LocalControlHeaderFacade::getCachingPolicy() const |
| 101 | { |
| 102 | shared_ptr<CachePolicyTag> tag = m_pkt.getTag<CachePolicyTag>(); |
| 103 | if (tag == nullptr) { |
| 104 | return INVALID_POLICY; |
| 105 | } |
| 106 | switch (tag->get().getPolicy()) { |
| 107 | case CachePolicyType::NO_CACHE: |
| 108 | return NO_CACHE; |
| 109 | default: |
| 110 | return INVALID_POLICY; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | LocalControlHeaderFacade::setCachingPolicy(CachingPolicy cachingPolicy) |
| 116 | { |
| 117 | switch (cachingPolicy) { |
| 118 | case NO_CACHE: { |
| 119 | m_pkt.setTag(make_shared<CachePolicyTag>(CachePolicy().setPolicy(CachePolicyType::NO_CACHE))); |
| 120 | break; |
| 121 | } |
| 122 | default: |
| 123 | m_pkt.removeTag<CachePolicyTag>(); |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER |
| 129 | |
| 130 | } // namespace lp |
| 131 | } // namespace ndn |