blob: dda903810146346fc62ef9143391ed1691cfc166 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi68b53852018-07-25 13:56:38 -06002/*
3 * 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_TRAITS_HPP
23#define NDN_MGMT_NFD_FACE_TRAITS_HPP
24
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050025#include "../../encoding/block.hpp"
26#include "../../encoding/nfd-constants.hpp"
Junxiao Shi7357ef22016-09-07 02:39:37 +000027
28namespace ndn {
29namespace nfd {
30
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050031/**
32 * \ingroup management
33 * \brief provides getters and setters for face information fields
34 * \tparam C the concrete subclass
Junxiao Shi7357ef22016-09-07 02:39:37 +000035 */
36template<class C>
37class FaceTraits
38{
39public:
40 class Error : public tlv::Error
41 {
42 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060043 using tlv::Error::Error;
Junxiao Shi7357ef22016-09-07 02:39:37 +000044 };
45
Junxiao Shi7357ef22016-09-07 02:39:37 +000046 uint64_t
47 getFaceId() const
48 {
49 return m_faceId;
50 }
51
52 C&
53 setFaceId(uint64_t faceId)
54 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050055 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000056 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 Pesavento0a1afdf2017-02-18 16:34:00 -050069 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000070 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 Pesavento0a1afdf2017-02-18 16:34:00 -050083 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000084 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 Pesavento0a1afdf2017-02-18 16:34:00 -050097 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000098 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 Pesavento0a1afdf2017-02-18 16:34:00 -0500111 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000112 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 Pesavento0a1afdf2017-02-18 16:34:00 -0500125 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000126 m_linkType = linkType;
127 return static_cast<C&>(*this);
128 }
129
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700130 uint64_t
131 getFlags() const
132 {
133 return m_flags;
134 }
135
136 C&
137 setFlags(uint64_t flags)
138 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500139 m_wire.reset();
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700140 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 Newberry1aa3e1e2016-09-28 20:27:45 -0700150 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 Pesavento0a1afdf2017-02-18 16:34:00 -0500160 m_wire.reset();
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700161
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 Shi7357ef22016-09-07 02:39:37 +0000172protected:
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500173 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 Shi7357ef22016-09-07 02:39:37 +0000181
182protected:
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 Newberry1aa3e1e2016-09-28 20:27:45 -0700189 uint64_t m_flags;
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500190
191 mutable Block m_wire;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000192};
193
194} // namespace nfd
195} // namespace ndn
196
197#endif // NDN_MGMT_NFD_FACE_TRAITS_HPP