face-traits.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2024 Regents of the University of California.
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_CXX_MGMT_NFD_FACE_TRAITS_HPP
23 #define NDN_CXX_MGMT_NFD_FACE_TRAITS_HPP
24 
27 
28 namespace ndn::nfd {
29 
35 template<class C>
37 {
38 public:
39  class Error : public tlv::Error
40  {
41  public:
42  using tlv::Error::Error;
43  };
44 
45  uint64_t
46  getFaceId() const
47  {
48  return m_faceId;
49  }
50 
51  C&
52  setFaceId(uint64_t faceId)
53  {
54  m_wire.reset();
55  m_faceId = faceId;
56  return static_cast<C&>(*this);
57  }
58 
59  const std::string&
60  getRemoteUri() const
61  {
62  return m_remoteUri;
63  }
64 
65  C&
66  setRemoteUri(const std::string& remoteUri)
67  {
68  m_wire.reset();
69  m_remoteUri = remoteUri;
70  return static_cast<C&>(*this);
71  }
72 
73  const std::string&
74  getLocalUri() const
75  {
76  return m_localUri;
77  }
78 
79  C&
80  setLocalUri(const std::string& localUri)
81  {
82  m_wire.reset();
83  m_localUri = localUri;
84  return static_cast<C&>(*this);
85  }
86 
87  FaceScope
88  getFaceScope() const
89  {
90  return m_faceScope;
91  }
92 
93  C&
95  {
96  m_wire.reset();
97  m_faceScope = faceScope;
98  return static_cast<C&>(*this);
99  }
100 
103  {
104  return m_facePersistency;
105  }
106 
107  C&
109  {
110  m_wire.reset();
111  m_facePersistency = facePersistency;
112  return static_cast<C&>(*this);
113  }
114 
115  LinkType
116  getLinkType() const
117  {
118  return m_linkType;
119  }
120 
121  C&
123  {
124  m_wire.reset();
125  m_linkType = linkType;
126  return static_cast<C&>(*this);
127  }
128 
129  uint64_t
130  getFlags() const
131  {
132  return m_flags;
133  }
134 
135  C&
136  setFlags(uint64_t flags)
137  {
138  m_wire.reset();
139  m_flags = flags;
140  return static_cast<C&>(*this);
141  }
142 
143  bool
144  getFlagBit(size_t bit) const
145  {
146  if (bit >= 64) {
147  NDN_THROW(std::out_of_range("bit must be within range [0, 64)"));
148  }
149  return m_flags & (1 << bit);
150  }
151 
152  C&
153  setFlagBit(size_t bit, bool value)
154  {
155  if (bit >= 64) {
156  NDN_THROW(std::out_of_range("bit must be within range [0, 64)"));
157  }
158 
159  m_wire.reset();
160 
161  if (value) {
162  m_flags |= (1 << bit);
163  }
164  else {
165  m_flags &= ~(1 << bit);
166  }
167 
168  return static_cast<C&>(*this);
169  }
170 
171 protected:
172  FaceTraits() = default;
173 
174 protected:
176  std::string m_remoteUri;
177  std::string m_localUri;
181  uint64_t m_flags = 0;
182 
183  mutable Block m_wire;
184 };
185 
186 } // namespace ndn::nfd
187 
188 #endif // NDN_CXX_MGMT_NFD_FACE_TRAITS_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:293
Provides getters and setters for face information fields.
Definition: face-traits.hpp:37
C & setFaceScope(FaceScope faceScope)
Definition: face-traits.hpp:94
C & setRemoteUri(const std::string &remoteUri)
Definition: face-traits.hpp:66
C & setFaceId(uint64_t faceId)
Definition: face-traits.hpp:52
uint64_t getFlags() const
FacePersistency m_facePersistency
const std::string & getLocalUri() const
Definition: face-traits.hpp:74
const std::string & getRemoteUri() const
Definition: face-traits.hpp:60
std::string m_localUri
C & setFlagBit(size_t bit, bool value)
FacePersistency getFacePersistency() const
C & setFacePersistency(FacePersistency facePersistency)
bool getFlagBit(size_t bit) const
C & setLocalUri(const std::string &localUri)
Definition: face-traits.hpp:80
std::string m_remoteUri
C & setFlags(uint64_t flags)
uint64_t getFaceId() const
Definition: face-traits.hpp:46
FaceScope getFaceScope() const
Definition: face-traits.hpp:88
C & setLinkType(LinkType linkType)
LinkType getLinkType() const
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:28
#define NDN_THROW(e)
Definition: exception.hpp:56
@ FACE_PERSISTENCY_PERSISTENT
face is persistent
@ FACE_SCOPE_NON_LOCAL
face is non-local
@ LINK_TYPE_POINT_TO_POINT
link is point-to-point
Contains classes and functions related to the NFD Management protocol.
constexpr uint64_t INVALID_FACE_ID