Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [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_QUERY_FILTER_HPP |
| 23 | #define NDN_MGMT_NFD_FACE_QUERY_FILTER_HPP |
| 24 | |
| 25 | #include "../../encoding/block.hpp" |
| 26 | #include "../../encoding/nfd-constants.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | |
| 31 | /** |
| 32 | * \ingroup management |
| 33 | * \brief represents Face Query Filter |
Alexander Afanasyev | e6835fe | 2017-01-19 20:05:01 -0800 | [diff] [blame] | 34 | * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Query-Operation |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 35 | */ |
| 36 | class FaceQueryFilter |
| 37 | { |
| 38 | public: |
| 39 | class Error : public tlv::Error |
| 40 | { |
| 41 | public: |
| 42 | explicit |
| 43 | Error(const std::string& what) |
| 44 | : tlv::Error(what) |
| 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | FaceQueryFilter(); |
| 50 | |
| 51 | explicit |
| 52 | FaceQueryFilter(const Block& block); |
| 53 | |
| 54 | /** \brief prepend FaceQueryFilter to the encoder |
| 55 | */ |
| 56 | template<encoding::Tag TAG> |
| 57 | size_t |
| 58 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 59 | |
| 60 | /** \brief encode FaceQueryFilter |
| 61 | */ |
| 62 | const Block& |
| 63 | wireEncode() const; |
| 64 | |
| 65 | /** \brief decode FaceQueryFilter |
| 66 | */ |
| 67 | void |
| 68 | wireDecode(const Block& wire); |
| 69 | |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 70 | /** \return whether the filter is empty |
| 71 | */ |
| 72 | bool |
| 73 | empty() const; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 74 | |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 75 | public: // getters & setters |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 76 | bool |
| 77 | hasFaceId() const |
| 78 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 79 | return !!m_faceId; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | uint64_t |
| 83 | getFaceId() const |
| 84 | { |
| 85 | BOOST_ASSERT(this->hasFaceId()); |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 86 | return *m_faceId; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | FaceQueryFilter& |
| 90 | setFaceId(uint64_t faceId); |
| 91 | |
| 92 | FaceQueryFilter& |
| 93 | unsetFaceId(); |
| 94 | |
| 95 | bool |
| 96 | hasUriScheme() const |
| 97 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 98 | return !m_uriScheme.empty(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | const std::string& |
| 102 | getUriScheme() const |
| 103 | { |
| 104 | BOOST_ASSERT(this->hasUriScheme()); |
| 105 | return m_uriScheme; |
| 106 | } |
| 107 | |
| 108 | FaceQueryFilter& |
| 109 | setUriScheme(const std::string& uriScheme); |
| 110 | |
| 111 | FaceQueryFilter& |
| 112 | unsetUriScheme(); |
| 113 | |
| 114 | bool |
| 115 | hasRemoteUri() const |
| 116 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 117 | return !m_remoteUri.empty(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | const std::string& |
| 121 | getRemoteUri() const |
| 122 | { |
| 123 | BOOST_ASSERT(this->hasRemoteUri()); |
| 124 | return m_remoteUri; |
| 125 | } |
| 126 | |
| 127 | FaceQueryFilter& |
| 128 | setRemoteUri(const std::string& remoteUri); |
| 129 | |
| 130 | FaceQueryFilter& |
| 131 | unsetRemoteUri(); |
| 132 | |
| 133 | bool |
| 134 | hasLocalUri() const |
| 135 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 136 | return !m_localUri.empty(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | const std::string& |
| 140 | getLocalUri() const |
| 141 | { |
| 142 | BOOST_ASSERT(this->hasLocalUri()); |
| 143 | return m_localUri; |
| 144 | } |
| 145 | |
| 146 | FaceQueryFilter& |
| 147 | setLocalUri(const std::string& localUri); |
| 148 | |
| 149 | FaceQueryFilter& |
| 150 | unsetLocalUri(); |
| 151 | |
| 152 | bool |
| 153 | hasFaceScope() const |
| 154 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 155 | return !!m_faceScope; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | FaceScope |
| 159 | getFaceScope() const |
| 160 | { |
| 161 | BOOST_ASSERT(this->hasFaceScope()); |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 162 | return *m_faceScope; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | FaceQueryFilter& |
| 166 | setFaceScope(FaceScope faceScope); |
| 167 | |
| 168 | FaceQueryFilter& |
| 169 | unsetFaceScope(); |
| 170 | |
| 171 | bool |
| 172 | hasFacePersistency() const |
| 173 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 174 | return !!m_facePersistency; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | FacePersistency |
| 178 | getFacePersistency() const |
| 179 | { |
| 180 | BOOST_ASSERT(this->hasFacePersistency()); |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 181 | return *m_facePersistency; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | FaceQueryFilter& |
| 185 | setFacePersistency(FacePersistency facePersistency); |
| 186 | |
| 187 | FaceQueryFilter& |
| 188 | unsetFacePersistency(); |
| 189 | |
| 190 | bool |
| 191 | hasLinkType() const |
| 192 | { |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 193 | return !!m_linkType; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | LinkType |
| 197 | getLinkType() const |
| 198 | { |
| 199 | BOOST_ASSERT(this->hasLinkType()); |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 200 | return *m_linkType; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | FaceQueryFilter& |
| 204 | setLinkType(LinkType linkType); |
| 205 | |
| 206 | FaceQueryFilter& |
| 207 | unsetLinkType(); |
| 208 | |
| 209 | private: |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 210 | optional<uint64_t> m_faceId; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 211 | std::string m_uriScheme; |
| 212 | std::string m_remoteUri; |
| 213 | std::string m_localUri; |
Junxiao Shi | a341ae8 | 2017-02-13 19:45:12 +0000 | [diff] [blame] | 214 | optional<FaceScope> m_faceScope; |
| 215 | optional<FacePersistency> m_facePersistency; |
| 216 | optional<LinkType> m_linkType; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 217 | |
| 218 | mutable Block m_wire; |
| 219 | }; |
| 220 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 221 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(FaceQueryFilter); |
| 222 | |
Junxiao Shi | a825d26 | 2017-02-07 18:24:59 +0000 | [diff] [blame] | 223 | bool |
| 224 | operator==(const FaceQueryFilter& a, const FaceQueryFilter& b); |
| 225 | |
| 226 | inline bool |
| 227 | operator!=(const FaceQueryFilter& a, const FaceQueryFilter& b) |
| 228 | { |
| 229 | return !(a == b); |
| 230 | } |
| 231 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 232 | std::ostream& |
| 233 | operator<<(std::ostream& os, const FaceQueryFilter& filter); |
| 234 | |
| 235 | } // namespace nfd |
| 236 | } // namespace ndn |
| 237 | |
| 238 | #endif // NDN_MGMT_NFD_FACE_QUERY_FILTER_HPP |