blob: 96bd7b7c47e76dcb169f973c2e53c7af9268c37e [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 Regents of the University of California.
Junxiao Shi7357ef22016-09-07 02:39:37 +00004 *
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
28namespace ndn {
29namespace nfd {
30
31/**
32 * \ingroup management
33 * \brief represents Face Query Filter
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -080034 * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Query-Operation
Junxiao Shi7357ef22016-09-07 02:39:37 +000035 */
36class FaceQueryFilter
37{
38public:
39 class Error : public tlv::Error
40 {
41 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060042 using tlv::Error::Error;
Junxiao Shi7357ef22016-09-07 02:39:37 +000043 };
44
45 FaceQueryFilter();
46
47 explicit
48 FaceQueryFilter(const Block& block);
49
50 /** \brief prepend FaceQueryFilter to the encoder
51 */
52 template<encoding::Tag TAG>
53 size_t
54 wireEncode(EncodingImpl<TAG>& encoder) const;
55
56 /** \brief encode FaceQueryFilter
57 */
58 const Block&
59 wireEncode() const;
60
61 /** \brief decode FaceQueryFilter
62 */
63 void
64 wireDecode(const Block& wire);
65
Junxiao Shia341ae82017-02-13 19:45:12 +000066 /** \return whether the filter is empty
67 */
68 bool
69 empty() const;
Junxiao Shi7357ef22016-09-07 02:39:37 +000070
Junxiao Shia341ae82017-02-13 19:45:12 +000071public: // getters & setters
Junxiao Shi7357ef22016-09-07 02:39:37 +000072 bool
73 hasFaceId() const
74 {
Junxiao Shia341ae82017-02-13 19:45:12 +000075 return !!m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +000076 }
77
78 uint64_t
79 getFaceId() const
80 {
81 BOOST_ASSERT(this->hasFaceId());
Junxiao Shia341ae82017-02-13 19:45:12 +000082 return *m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +000083 }
84
85 FaceQueryFilter&
86 setFaceId(uint64_t faceId);
87
88 FaceQueryFilter&
89 unsetFaceId();
90
91 bool
92 hasUriScheme() const
93 {
Junxiao Shia341ae82017-02-13 19:45:12 +000094 return !m_uriScheme.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +000095 }
96
97 const std::string&
98 getUriScheme() const
99 {
100 BOOST_ASSERT(this->hasUriScheme());
101 return m_uriScheme;
102 }
103
104 FaceQueryFilter&
105 setUriScheme(const std::string& uriScheme);
106
107 FaceQueryFilter&
108 unsetUriScheme();
109
110 bool
111 hasRemoteUri() const
112 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000113 return !m_remoteUri.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000114 }
115
116 const std::string&
117 getRemoteUri() const
118 {
119 BOOST_ASSERT(this->hasRemoteUri());
120 return m_remoteUri;
121 }
122
123 FaceQueryFilter&
124 setRemoteUri(const std::string& remoteUri);
125
126 FaceQueryFilter&
127 unsetRemoteUri();
128
129 bool
130 hasLocalUri() const
131 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000132 return !m_localUri.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000133 }
134
135 const std::string&
136 getLocalUri() const
137 {
138 BOOST_ASSERT(this->hasLocalUri());
139 return m_localUri;
140 }
141
142 FaceQueryFilter&
143 setLocalUri(const std::string& localUri);
144
145 FaceQueryFilter&
146 unsetLocalUri();
147
148 bool
149 hasFaceScope() const
150 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000151 return !!m_faceScope;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000152 }
153
154 FaceScope
155 getFaceScope() const
156 {
157 BOOST_ASSERT(this->hasFaceScope());
Junxiao Shia341ae82017-02-13 19:45:12 +0000158 return *m_faceScope;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000159 }
160
161 FaceQueryFilter&
162 setFaceScope(FaceScope faceScope);
163
164 FaceQueryFilter&
165 unsetFaceScope();
166
167 bool
168 hasFacePersistency() const
169 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000170 return !!m_facePersistency;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000171 }
172
173 FacePersistency
174 getFacePersistency() const
175 {
176 BOOST_ASSERT(this->hasFacePersistency());
Junxiao Shia341ae82017-02-13 19:45:12 +0000177 return *m_facePersistency;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000178 }
179
180 FaceQueryFilter&
181 setFacePersistency(FacePersistency facePersistency);
182
183 FaceQueryFilter&
184 unsetFacePersistency();
185
186 bool
187 hasLinkType() const
188 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000189 return !!m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000190 }
191
192 LinkType
193 getLinkType() const
194 {
195 BOOST_ASSERT(this->hasLinkType());
Junxiao Shia341ae82017-02-13 19:45:12 +0000196 return *m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000197 }
198
199 FaceQueryFilter&
200 setLinkType(LinkType linkType);
201
202 FaceQueryFilter&
203 unsetLinkType();
204
205private:
Junxiao Shia341ae82017-02-13 19:45:12 +0000206 optional<uint64_t> m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000207 std::string m_uriScheme;
208 std::string m_remoteUri;
209 std::string m_localUri;
Junxiao Shia341ae82017-02-13 19:45:12 +0000210 optional<FaceScope> m_faceScope;
211 optional<FacePersistency> m_facePersistency;
212 optional<LinkType> m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000213
214 mutable Block m_wire;
215};
216
Davide Pesavento88a0d812017-08-19 21:31:42 -0400217NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(FaceQueryFilter);
218
Junxiao Shia825d262017-02-07 18:24:59 +0000219bool
220operator==(const FaceQueryFilter& a, const FaceQueryFilter& b);
221
222inline bool
223operator!=(const FaceQueryFilter& a, const FaceQueryFilter& b)
224{
225 return !(a == b);
226}
227
Junxiao Shi7357ef22016-09-07 02:39:37 +0000228std::ostream&
229operator<<(std::ostream& os, const FaceQueryFilter& filter);
230
231} // namespace nfd
232} // namespace ndn
233
234#endif // NDN_MGMT_NFD_FACE_QUERY_FILTER_HPP