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