blob: 58a9245880475fc44b7aa5fac43d1a7f35f52d43 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento7f20d6e2017-01-16 14:43:58 -05003 * 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_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:
43 explicit
44 Error(const std::string& what)
45 : tlv::Error(what)
46 {
47 }
48 };
49
Junxiao Shi7357ef22016-09-07 02:39:37 +000050 uint64_t
51 getFaceId() const
52 {
53 return m_faceId;
54 }
55
56 C&
57 setFaceId(uint64_t faceId)
58 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050059 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000060 m_faceId = faceId;
61 return static_cast<C&>(*this);
62 }
63
64 const std::string&
65 getRemoteUri() const
66 {
67 return m_remoteUri;
68 }
69
70 C&
71 setRemoteUri(const std::string& remoteUri)
72 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050073 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000074 m_remoteUri = remoteUri;
75 return static_cast<C&>(*this);
76 }
77
78 const std::string&
79 getLocalUri() const
80 {
81 return m_localUri;
82 }
83
84 C&
85 setLocalUri(const std::string& localUri)
86 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -050087 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +000088 m_localUri = localUri;
89 return static_cast<C&>(*this);
90 }
91
92 FaceScope
93 getFaceScope() const
94 {
95 return m_faceScope;
96 }
97
98 C&
99 setFaceScope(FaceScope faceScope)
100 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500101 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000102 m_faceScope = faceScope;
103 return static_cast<C&>(*this);
104 }
105
106 FacePersistency
107 getFacePersistency() const
108 {
109 return m_facePersistency;
110 }
111
112 C&
113 setFacePersistency(FacePersistency facePersistency)
114 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500115 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000116 m_facePersistency = facePersistency;
117 return static_cast<C&>(*this);
118 }
119
120 LinkType
121 getLinkType() const
122 {
123 return m_linkType;
124 }
125
126 C&
127 setLinkType(LinkType linkType)
128 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500129 m_wire.reset();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000130 m_linkType = linkType;
131 return static_cast<C&>(*this);
132 }
133
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700134 uint64_t
135 getFlags() const
136 {
137 return m_flags;
138 }
139
140 C&
141 setFlags(uint64_t flags)
142 {
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500143 m_wire.reset();
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700144 m_flags = flags;
145 return static_cast<C&>(*this);
146 }
147
148 bool
149 getFlagBit(size_t bit) const
150 {
151 if (bit >= 64) {
152 BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)"));
153 }
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700154 return m_flags & (1 << bit);
155 }
156
157 C&
158 setFlagBit(size_t bit, bool value)
159 {
160 if (bit >= 64) {
161 BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)"));
162 }
163
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500164 m_wire.reset();
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700165
166 if (value) {
167 m_flags |= (1 << bit);
168 }
169 else {
170 m_flags &= ~(1 << bit);
171 }
172
173 return static_cast<C&>(*this);
174 }
175
Junxiao Shi7357ef22016-09-07 02:39:37 +0000176protected:
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500177 FaceTraits()
178 : m_faceId(INVALID_FACE_ID)
179 , m_faceScope(FACE_SCOPE_NON_LOCAL)
180 , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
181 , m_linkType(LINK_TYPE_POINT_TO_POINT)
182 , m_flags(0)
183 {
184 }
Junxiao Shi7357ef22016-09-07 02:39:37 +0000185
186protected:
187 uint64_t m_faceId;
188 std::string m_remoteUri;
189 std::string m_localUri;
190 FaceScope m_faceScope;
191 FacePersistency m_facePersistency;
192 LinkType m_linkType;
Eric Newberry1aa3e1e2016-09-28 20:27:45 -0700193 uint64_t m_flags;
Davide Pesavento0a1afdf2017-02-18 16:34:00 -0500194
195 mutable Block m_wire;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000196};
197
198} // namespace nfd
199} // namespace ndn
200
201#endif // NDN_MGMT_NFD_FACE_TRAITS_HPP