blob: b0e9e5d08a1b88eedbcabd476c30b4872adc8b38 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shia825d262017-02-07 18:24:59 +00003 * Copyright (c) 2013-2017 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:
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 Shia341ae82017-02-13 19:45:12 +000070 /** \return whether the filter is empty
71 */
72 bool
73 empty() const;
Junxiao Shi7357ef22016-09-07 02:39:37 +000074
Junxiao Shia341ae82017-02-13 19:45:12 +000075public: // getters & setters
Junxiao Shi7357ef22016-09-07 02:39:37 +000076 bool
77 hasFaceId() const
78 {
Junxiao Shia341ae82017-02-13 19:45:12 +000079 return !!m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +000080 }
81
82 uint64_t
83 getFaceId() const
84 {
85 BOOST_ASSERT(this->hasFaceId());
Junxiao Shia341ae82017-02-13 19:45:12 +000086 return *m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +000087 }
88
89 FaceQueryFilter&
90 setFaceId(uint64_t faceId);
91
92 FaceQueryFilter&
93 unsetFaceId();
94
95 bool
96 hasUriScheme() const
97 {
Junxiao Shia341ae82017-02-13 19:45:12 +000098 return !m_uriScheme.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +000099 }
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 Shia341ae82017-02-13 19:45:12 +0000117 return !m_remoteUri.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000118 }
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 Shia341ae82017-02-13 19:45:12 +0000136 return !m_localUri.empty();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000137 }
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 Shia341ae82017-02-13 19:45:12 +0000155 return !!m_faceScope;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000156 }
157
158 FaceScope
159 getFaceScope() const
160 {
161 BOOST_ASSERT(this->hasFaceScope());
Junxiao Shia341ae82017-02-13 19:45:12 +0000162 return *m_faceScope;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000163 }
164
165 FaceQueryFilter&
166 setFaceScope(FaceScope faceScope);
167
168 FaceQueryFilter&
169 unsetFaceScope();
170
171 bool
172 hasFacePersistency() const
173 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000174 return !!m_facePersistency;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000175 }
176
177 FacePersistency
178 getFacePersistency() const
179 {
180 BOOST_ASSERT(this->hasFacePersistency());
Junxiao Shia341ae82017-02-13 19:45:12 +0000181 return *m_facePersistency;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000182 }
183
184 FaceQueryFilter&
185 setFacePersistency(FacePersistency facePersistency);
186
187 FaceQueryFilter&
188 unsetFacePersistency();
189
190 bool
191 hasLinkType() const
192 {
Junxiao Shia341ae82017-02-13 19:45:12 +0000193 return !!m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000194 }
195
196 LinkType
197 getLinkType() const
198 {
199 BOOST_ASSERT(this->hasLinkType());
Junxiao Shia341ae82017-02-13 19:45:12 +0000200 return *m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000201 }
202
203 FaceQueryFilter&
204 setLinkType(LinkType linkType);
205
206 FaceQueryFilter&
207 unsetLinkType();
208
209private:
Junxiao Shia341ae82017-02-13 19:45:12 +0000210 optional<uint64_t> m_faceId;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000211 std::string m_uriScheme;
212 std::string m_remoteUri;
213 std::string m_localUri;
Junxiao Shia341ae82017-02-13 19:45:12 +0000214 optional<FaceScope> m_faceScope;
215 optional<FacePersistency> m_facePersistency;
216 optional<LinkType> m_linkType;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000217
218 mutable Block m_wire;
219};
220
Junxiao Shia825d262017-02-07 18:24:59 +0000221bool
222operator==(const FaceQueryFilter& a, const FaceQueryFilter& b);
223
224inline bool
225operator!=(const FaceQueryFilter& a, const FaceQueryFilter& b)
226{
227 return !(a == b);
228}
229
Junxiao Shi7357ef22016-09-07 02:39:37 +0000230std::ostream&
231operator<<(std::ostream& os, const FaceQueryFilter& filter);
232
233} // namespace nfd
234} // namespace ndn
235
236#endif // NDN_MGMT_NFD_FACE_QUERY_FILTER_HPP