blob: f473d8a2870eb410504bf24b5bc5611cd1681fbe [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"
Chengyu Fan36dca992014-09-25 13:42:03 -060026
27namespace ndn {
28namespace nfd {
29
Chengyu Fan36dca992014-09-25 13:42:03 -060030/** \ingroup management
31 * \brief providers getters and setters of face information fields
32 * \tparam C the concrete class; it must provide .wireReset() method
33 to clear wire encoding when a field changes
34 */
35template<class C>
36class FaceTraits
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 FaceTraits()
50 : m_faceId(0)
51 , m_faceScope(FACE_SCOPE_NON_LOCAL)
52 , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
53 , m_linkType(LINK_TYPE_POINT_TO_POINT)
54 {
55 }
56
57 uint64_t
58 getFaceId() const
59 {
60 return m_faceId;
61 }
62
63 C&
64 setFaceId(uint64_t faceId)
65 {
66 wireReset();
67 m_faceId = faceId;
68 return static_cast<C&>(*this);
69 }
70
71 const std::string&
72 getRemoteUri() const
73 {
74 return m_remoteUri;
75 }
76
77 C&
78 setRemoteUri(const std::string& remoteUri)
79 {
80 wireReset();
81 m_remoteUri = remoteUri;
82 return static_cast<C&>(*this);
83 }
84
85 const std::string&
86 getLocalUri() const
87 {
88 return m_localUri;
89 }
90
91 C&
92 setLocalUri(const std::string& localUri)
93 {
94 wireReset();
95 m_localUri = localUri;
96 return static_cast<C&>(*this);
97 }
98
99 FaceScope
100 getFaceScope() const
101 {
102 return m_faceScope;
103 }
104
105 C&
106 setFaceScope(FaceScope faceScope)
107 {
108 wireReset();
109 m_faceScope = faceScope;
110 return static_cast<C&>(*this);
111 }
112
113 FacePersistency
114 getFacePersistency() const
115 {
116 return m_facePersistency;
117 }
118
119 C&
120 setFacePersistency(FacePersistency facePersistency)
121 {
122 wireReset();
123 m_facePersistency = facePersistency;
124 return static_cast<C&>(*this);
125 }
126
127 LinkType
128 getLinkType() const
129 {
130 return m_linkType;
131 }
132
133 C&
134 setLinkType(LinkType linkType)
135 {
136 wireReset();
137 m_linkType = linkType;
138 return static_cast<C&>(*this);
139 }
140
Chengyu Fan36dca992014-09-25 13:42:03 -0600141protected:
142 virtual void
143 wireReset() const = 0;
144
145protected:
146 uint64_t m_faceId;
147 std::string m_remoteUri;
148 std::string m_localUri;
149 FaceScope m_faceScope;
150 FacePersistency m_facePersistency;
151 LinkType m_linkType;
152};
153
154} // namespace nfd
155} // namespace ndn
156
157#endif // NDN_MANAGEMENT_NFD_FACE_TRAITS_HPP