blob: 1b33dea823d7abfc88481b57d4e8e456effae1e1 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070020 */
21
22#ifndef NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
23#define NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
24
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070025// This include must be kept as the first one, to ensure nfd-face-flags.hpp compiles on its own.
26#include "nfd-face-flags.hpp"
27
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070028#include "../encoding/tlv-nfd.hpp"
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070029#include "../encoding/encoding-buffer.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070030#include "../encoding/block-helpers.hpp"
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -070031#include "../util/time.hpp"
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070032
33namespace ndn {
34namespace nfd {
35
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040036/**
37 * \ingroup management
38 * \brief represents Face status
39 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070040 */
41class FaceStatus : public FaceFlagsTraits<FaceStatus>
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070042{
43public:
44 class Error : public Tlv::Error
45 {
46 public:
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070047 explicit
48 Error(const std::string& what)
49 : Tlv::Error(what)
50 {
51 }
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070052 };
53
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070054 FaceStatus();
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070055
56 explicit
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070057 FaceStatus(const Block& block)
58 {
59 this->wireDecode(block);
60 }
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070061
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070062 /** \brief prepend FaceStatus to the encoder
63 */
64 template<bool T>
65 size_t
66 wireEncode(EncodingImpl<T>& encoder) const;
67
68 /** \brief encode FaceStatus
69 */
70 const Block&
71 wireEncode() const;
72
73 /** \brief decode FaceStatus
74 */
75 void
76 wireDecode(const Block& wire);
77
78public: // getters & setters
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -070079 uint64_t
80 getFaceId() const
81 {
82 return m_faceId;
83 }
84
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -070085 FaceStatus&
86 setFaceId(uint64_t faceId)
87 {
88 m_wire.reset();
89 m_faceId = faceId;
90 return *this;
91 }
92
93 const std::string&
94 getRemoteUri() const
95 {
96 return m_remoteUri;
97 }
98
99 FaceStatus&
100 setRemoteUri(const std::string& remoteUri)
101 {
102 m_wire.reset();
103 m_remoteUri = remoteUri;
104 return *this;
105 }
106
107 const std::string&
108 getLocalUri() const
109 {
110 return m_localUri;
111 }
112
113 FaceStatus&
114 setLocalUri(const std::string& localUri)
115 {
116 m_wire.reset();
117 m_localUri = localUri;
118 return *this;
119 }
120
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -0700121 bool
122 hasExpirationPeriod() const
123 {
124 return m_hasExpirationPeriod;
125 }
126
127 const time::milliseconds&
128 getExpirationPeriod() const
129 {
130 BOOST_ASSERT(m_hasExpirationPeriod);
131 return m_expirationPeriod;
132 }
133
134 FaceStatus&
135 setExpirationPeriod(const time::milliseconds& expirationPeriod)
136 {
137 m_expirationPeriod = expirationPeriod;
138 m_hasExpirationPeriod = true;
139 return *this;
140 }
141
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700142 uint64_t
143 getFlags() const
144 {
145 return m_flags;
146 }
147
148 FaceStatus&
149 setFlags(uint64_t flags)
150 {
151 m_wire.reset();
152 m_flags = flags;
153 return *this;
154 }
155
156 uint64_t
157 getNInInterests() const
158 {
159 return m_nInInterests;
160 }
161
162 FaceStatus&
163 setNInInterests(uint64_t nInInterests)
164 {
165 m_wire.reset();
166 m_nInInterests = nInInterests;
167 return *this;
168 }
169
170 uint64_t
171 getNInDatas() const
172 {
173 return m_nInDatas;
174 }
175
176 FaceStatus&
177 setNInDatas(uint64_t nInDatas)
178 {
179 m_wire.reset();
180 m_nInDatas = nInDatas;
181 return *this;
182 }
183
184 uint64_t
185 getNOutInterests() const
186 {
187 return m_nOutInterests;
188 }
189
190 FaceStatus&
191 setNOutInterests(uint64_t nOutInterests)
192 {
193 m_wire.reset();
194 m_nOutInterests = nOutInterests;
195 return *this;
196 }
197
198 uint64_t
199 getNOutDatas() const
200 {
201 return m_nOutDatas;
202 }
203
204 FaceStatus&
205 setNOutDatas(uint64_t nOutDatas)
206 {
207 m_wire.reset();
208 m_nOutDatas = nOutDatas;
209 return *this;
210 }
211
Junxiao Shi13e637f2014-07-16 19:20:40 -0700212 uint64_t
213 getNInBytes() const
214 {
215 return m_nInBytes;
216 }
217
218 FaceStatus&
219 setNInBytes(uint64_t nInBytes)
220 {
221 m_wire.reset();
222 m_nInBytes = nInBytes;
223 return *this;
224 }
225
226 uint64_t
227 getNOutBytes() const
228 {
229 return m_nOutBytes;
230 }
231
232 FaceStatus&
233 setNOutBytes(uint64_t nOutBytes)
234 {
235 m_wire.reset();
236 m_nOutBytes = nOutBytes;
237 return *this;
238 }
239
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -0700240private:
241 uint64_t m_faceId;
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700242 std::string m_remoteUri;
243 std::string m_localUri;
Alexander Afanasyeve63eaf62014-06-30 12:40:55 -0700244 time::milliseconds m_expirationPeriod;
245 bool m_hasExpirationPeriod;
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700246 uint64_t m_flags;
247 uint64_t m_nInInterests;
248 uint64_t m_nInDatas;
249 uint64_t m_nOutInterests;
250 uint64_t m_nOutDatas;
Junxiao Shi13e637f2014-07-16 19:20:40 -0700251 uint64_t m_nInBytes;
252 uint64_t m_nOutBytes;
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -0700253
254 mutable Block m_wire;
255};
256
Junxiao Shi13e637f2014-07-16 19:20:40 -0700257std::ostream&
258operator<<(std::ostream& os, const FaceStatus& status);
Alexander Afanasyev04fa37a2014-03-19 18:06:22 -0700259
260} // namespace nfd
261} // namespace ndn
262
Junxiao Shi7b1ba1a2014-03-29 01:01:56 -0700263#endif // NDN_MANAGEMENT_NFD_FACE_STATUS_HPP