Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 7f20d6e | 2017-01-16 14:43:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 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 | #ifndef NDN_MGMT_NFD_FACE_TRAITS_HPP |
| 23 | #define NDN_MGMT_NFD_FACE_TRAITS_HPP |
| 24 | |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 25 | #include "../../encoding/block.hpp" |
| 26 | #include "../../encoding/nfd-constants.hpp" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 31 | /** |
| 32 | * \ingroup management |
| 33 | * \brief provides getters and setters for face information fields |
| 34 | * \tparam C the concrete subclass |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 35 | */ |
| 36 | template<class C> |
| 37 | class FaceTraits |
| 38 | { |
| 39 | public: |
| 40 | class Error : public tlv::Error |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
| 45 | : tlv::Error(what) |
| 46 | { |
| 47 | } |
| 48 | }; |
| 49 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 50 | uint64_t |
| 51 | getFaceId() const |
| 52 | { |
| 53 | return m_faceId; |
| 54 | } |
| 55 | |
| 56 | C& |
| 57 | setFaceId(uint64_t faceId) |
| 58 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 59 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 60 | m_faceId = faceId; |
| 61 | return static_cast<C&>(*this); |
| 62 | } |
| 63 | |
| 64 | const std::string& |
| 65 | getRemoteUri() const |
| 66 | { |
| 67 | return m_remoteUri; |
| 68 | } |
| 69 | |
| 70 | C& |
| 71 | setRemoteUri(const std::string& remoteUri) |
| 72 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 73 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 74 | m_remoteUri = remoteUri; |
| 75 | return static_cast<C&>(*this); |
| 76 | } |
| 77 | |
| 78 | const std::string& |
| 79 | getLocalUri() const |
| 80 | { |
| 81 | return m_localUri; |
| 82 | } |
| 83 | |
| 84 | C& |
| 85 | setLocalUri(const std::string& localUri) |
| 86 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 87 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 88 | m_localUri = localUri; |
| 89 | return static_cast<C&>(*this); |
| 90 | } |
| 91 | |
| 92 | FaceScope |
| 93 | getFaceScope() const |
| 94 | { |
| 95 | return m_faceScope; |
| 96 | } |
| 97 | |
| 98 | C& |
| 99 | setFaceScope(FaceScope faceScope) |
| 100 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 101 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 102 | m_faceScope = faceScope; |
| 103 | return static_cast<C&>(*this); |
| 104 | } |
| 105 | |
| 106 | FacePersistency |
| 107 | getFacePersistency() const |
| 108 | { |
| 109 | return m_facePersistency; |
| 110 | } |
| 111 | |
| 112 | C& |
| 113 | setFacePersistency(FacePersistency facePersistency) |
| 114 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 115 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 116 | m_facePersistency = facePersistency; |
| 117 | return static_cast<C&>(*this); |
| 118 | } |
| 119 | |
| 120 | LinkType |
| 121 | getLinkType() const |
| 122 | { |
| 123 | return m_linkType; |
| 124 | } |
| 125 | |
| 126 | C& |
| 127 | setLinkType(LinkType linkType) |
| 128 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 129 | m_wire.reset(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 130 | m_linkType = linkType; |
| 131 | return static_cast<C&>(*this); |
| 132 | } |
| 133 | |
Eric Newberry | 1aa3e1e | 2016-09-28 20:27:45 -0700 | [diff] [blame] | 134 | uint64_t |
| 135 | getFlags() const |
| 136 | { |
| 137 | return m_flags; |
| 138 | } |
| 139 | |
| 140 | C& |
| 141 | setFlags(uint64_t flags) |
| 142 | { |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 143 | m_wire.reset(); |
Eric Newberry | 1aa3e1e | 2016-09-28 20:27:45 -0700 | [diff] [blame] | 144 | m_flags = flags; |
| 145 | return static_cast<C&>(*this); |
| 146 | } |
| 147 | |
| 148 | bool |
| 149 | getFlagBit(size_t bit) const |
| 150 | { |
| 151 | if (bit >= 64) { |
| 152 | BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)")); |
| 153 | } |
Eric Newberry | 1aa3e1e | 2016-09-28 20:27:45 -0700 | [diff] [blame] | 154 | return m_flags & (1 << bit); |
| 155 | } |
| 156 | |
| 157 | C& |
| 158 | setFlagBit(size_t bit, bool value) |
| 159 | { |
| 160 | if (bit >= 64) { |
| 161 | BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)")); |
| 162 | } |
| 163 | |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 164 | m_wire.reset(); |
Eric Newberry | 1aa3e1e | 2016-09-28 20:27:45 -0700 | [diff] [blame] | 165 | |
| 166 | if (value) { |
| 167 | m_flags |= (1 << bit); |
| 168 | } |
| 169 | else { |
| 170 | m_flags &= ~(1 << bit); |
| 171 | } |
| 172 | |
| 173 | return static_cast<C&>(*this); |
| 174 | } |
| 175 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 176 | protected: |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 177 | FaceTraits() |
| 178 | : m_faceId(INVALID_FACE_ID) |
| 179 | , m_faceScope(FACE_SCOPE_NON_LOCAL) |
| 180 | , m_facePersistency(FACE_PERSISTENCY_PERSISTENT) |
| 181 | , m_linkType(LINK_TYPE_POINT_TO_POINT) |
| 182 | , m_flags(0) |
| 183 | { |
| 184 | } |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 185 | |
| 186 | protected: |
| 187 | uint64_t m_faceId; |
| 188 | std::string m_remoteUri; |
| 189 | std::string m_localUri; |
| 190 | FaceScope m_faceScope; |
| 191 | FacePersistency m_facePersistency; |
| 192 | LinkType m_linkType; |
Eric Newberry | 1aa3e1e | 2016-09-28 20:27:45 -0700 | [diff] [blame] | 193 | uint64_t m_flags; |
Davide Pesavento | 0a1afdf | 2017-02-18 16:34:00 -0500 | [diff] [blame^] | 194 | |
| 195 | mutable Block m_wire; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | } // namespace nfd |
| 199 | } // namespace ndn |
| 200 | |
| 201 | #endif // NDN_MGMT_NFD_FACE_TRAITS_HPP |