blob: 0160af185ec5bedff317adc1de5e230d2d5f9690 [file] [log] [blame]
Chengyu Fan36dca992014-09-25 13:42:03 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 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_MANAGEMENT_NFD_FACE_TRAITS_HPP
23#define NDN_MANAGEMENT_NFD_FACE_TRAITS_HPP
24
25#include "../encoding/tlv-nfd.hpp"
26#include "../encoding/encoding-buffer.hpp"
27#include "../encoding/block-helpers.hpp"
28
29namespace ndn {
30namespace nfd {
31
32/**
33 * \ingroup management
Chengyu Fan36dca992014-09-25 13:42:03 -060034 * \brief provides additional information about a faceScope
35 */
36enum FaceScope {
37 /** \brief face is non-local
38 */
39 FACE_SCOPE_NON_LOCAL = 0,
40 /** \brief face is local
41 */
42 FACE_SCOPE_LOCAL = 1
43};
44
45std::ostream&
46operator<<(std::ostream& os, FaceScope faceScope);
47
48/**
49 * \ingroup management
50 * \brief provides additional information about a facePersistency
51 */
52enum FacePersistency {
53 /** \brief face is persistent
54 */
55 FACE_PERSISTENCY_PERSISTENT = 0,
56 /** \brief face is on-demand
57 */
58 FACE_PERSISTENCY_ON_DEMAND = 1,
59 /** \brief face is permanent
60 */
61 FACE_PERSISTENCY_PERMANENT = 2
62};
63
64std::ostream&
65operator<<(std::ostream& os, FacePersistency facePersistency);
66
67/**
68 * \ingroup management
69 * \brief provides additional information about a linkType
70 */
71enum LinkType {
72 /** \brief link is point-to-point
73 */
74 LINK_TYPE_POINT_TO_POINT = 0,
75 /** \brief link is multi-access
76 */
77 LINK_TYPE_MULTI_ACCESS = 1
78};
79
80std::ostream&
81operator<<(std::ostream& os, LinkType linkType);
82
83/** \ingroup management
84 * \brief providers getters and setters of face information fields
85 * \tparam C the concrete class; it must provide .wireReset() method
86 to clear wire encoding when a field changes
87 */
88template<class C>
89class FaceTraits
90{
91public:
92 class Error : public tlv::Error
93 {
94 public:
95 explicit
96 Error(const std::string& what)
97 : tlv::Error(what)
98 {
99 }
100 };
101
102 FaceTraits()
103 : m_faceId(0)
104 , m_faceScope(FACE_SCOPE_NON_LOCAL)
105 , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
106 , m_linkType(LINK_TYPE_POINT_TO_POINT)
107 {
108 }
109
110 uint64_t
111 getFaceId() const
112 {
113 return m_faceId;
114 }
115
116 C&
117 setFaceId(uint64_t faceId)
118 {
119 wireReset();
120 m_faceId = faceId;
121 return static_cast<C&>(*this);
122 }
123
124 const std::string&
125 getRemoteUri() const
126 {
127 return m_remoteUri;
128 }
129
130 C&
131 setRemoteUri(const std::string& remoteUri)
132 {
133 wireReset();
134 m_remoteUri = remoteUri;
135 return static_cast<C&>(*this);
136 }
137
138 const std::string&
139 getLocalUri() const
140 {
141 return m_localUri;
142 }
143
144 C&
145 setLocalUri(const std::string& localUri)
146 {
147 wireReset();
148 m_localUri = localUri;
149 return static_cast<C&>(*this);
150 }
151
152 FaceScope
153 getFaceScope() const
154 {
155 return m_faceScope;
156 }
157
158 C&
159 setFaceScope(FaceScope faceScope)
160 {
161 wireReset();
162 m_faceScope = faceScope;
163 return static_cast<C&>(*this);
164 }
165
166 FacePersistency
167 getFacePersistency() const
168 {
169 return m_facePersistency;
170 }
171
172 C&
173 setFacePersistency(FacePersistency facePersistency)
174 {
175 wireReset();
176 m_facePersistency = facePersistency;
177 return static_cast<C&>(*this);
178 }
179
180 LinkType
181 getLinkType() const
182 {
183 return m_linkType;
184 }
185
186 C&
187 setLinkType(LinkType linkType)
188 {
189 wireReset();
190 m_linkType = linkType;
191 return static_cast<C&>(*this);
192 }
193
Chengyu Fan36dca992014-09-25 13:42:03 -0600194protected:
195 virtual void
196 wireReset() const = 0;
197
198protected:
199 uint64_t m_faceId;
200 std::string m_remoteUri;
201 std::string m_localUri;
202 FaceScope m_faceScope;
203 FacePersistency m_facePersistency;
204 LinkType m_linkType;
205};
206
207} // namespace nfd
208} // namespace ndn
209
210#endif // NDN_MANAGEMENT_NFD_FACE_TRAITS_HPP