Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "face-status.hpp" |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 23 | #include "encoding/tlv-nfd.hpp" |
| 24 | #include "encoding/block-helpers.hpp" |
| 25 | #include "util/concepts.hpp" |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
| 29 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 30 | //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceStatus>)); |
| 31 | BOOST_CONCEPT_ASSERT((WireEncodable<FaceStatus>)); |
| 32 | BOOST_CONCEPT_ASSERT((WireDecodable<FaceStatus>)); |
| 33 | static_assert(std::is_base_of<tlv::Error, FaceStatus::Error>::value, |
| 34 | "FaceStatus::Error must inherit from tlv::Error"); |
| 35 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 36 | FaceStatus::FaceStatus() |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 37 | : m_hasExpirationPeriod(false) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 38 | , m_nInInterests(0) |
| 39 | , m_nInDatas(0) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 40 | , m_nInNacks(0) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 41 | , m_nOutInterests(0) |
| 42 | , m_nOutDatas(0) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 43 | , m_nOutNacks(0) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 44 | , m_nInBytes(0) |
| 45 | , m_nOutBytes(0) |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame^] | 46 | , m_flags(0) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 47 | { |
| 48 | } |
| 49 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 50 | FaceStatus::FaceStatus(const Block& block) |
| 51 | { |
| 52 | this->wireDecode(block); |
| 53 | } |
| 54 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 55 | template<encoding::Tag TAG> |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 56 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 57 | FaceStatus::wireEncode(EncodingImpl<TAG>& encoder) const |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 58 | { |
| 59 | size_t totalLength = 0; |
| 60 | |
| 61 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame^] | 62 | tlv::nfd::Flags, m_flags); |
| 63 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 64 | tlv::nfd::NOutBytes, m_nOutBytes); |
| 65 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 66 | tlv::nfd::NInBytes, m_nInBytes); |
| 67 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 68 | tlv::nfd::NOutNacks, m_nOutNacks); |
| 69 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 70 | tlv::nfd::NOutDatas, m_nOutDatas); |
| 71 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 72 | tlv::nfd::NOutInterests, m_nOutInterests); |
| 73 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 74 | tlv::nfd::NInNacks, m_nInNacks); |
| 75 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 76 | tlv::nfd::NInDatas, m_nInDatas); |
| 77 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 78 | tlv::nfd::NInInterests, m_nInInterests); |
| 79 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 80 | tlv::nfd::LinkType, m_linkType); |
| 81 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 82 | tlv::nfd::FacePersistency, m_facePersistency); |
| 83 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 84 | tlv::nfd::FaceScope, m_faceScope); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 85 | if (m_hasExpirationPeriod) { |
| 86 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 87 | tlv::nfd::ExpirationPeriod, m_expirationPeriod.count()); |
| 88 | } |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 89 | totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 90 | reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size()); |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 91 | totalLength += encoder.prependByteArrayBlock(tlv::nfd::Uri, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 92 | reinterpret_cast<const uint8_t*>(m_remoteUri.c_str()), m_remoteUri.size()); |
| 93 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 94 | tlv::nfd::FaceId, m_faceId); |
| 95 | |
| 96 | totalLength += encoder.prependVarNumber(totalLength); |
| 97 | totalLength += encoder.prependVarNumber(tlv::nfd::FaceStatus); |
| 98 | return totalLength; |
| 99 | } |
| 100 | |
| 101 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 102 | FaceStatus::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& block) const; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 103 | |
| 104 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 105 | FaceStatus::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& block) const; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 106 | |
| 107 | const Block& |
| 108 | FaceStatus::wireEncode() const |
| 109 | { |
| 110 | if (m_wire.hasWire()) |
| 111 | return m_wire; |
| 112 | |
| 113 | EncodingEstimator estimator; |
| 114 | size_t estimatedSize = wireEncode(estimator); |
| 115 | |
| 116 | EncodingBuffer buffer(estimatedSize, 0); |
| 117 | wireEncode(buffer); |
| 118 | |
| 119 | m_wire = buffer.block(); |
| 120 | return m_wire; |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | FaceStatus::wireDecode(const Block& block) |
| 125 | { |
| 126 | if (block.type() != tlv::nfd::FaceStatus) { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 127 | BOOST_THROW_EXCEPTION(Error("expecting FaceStatus block")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 128 | } |
| 129 | m_wire = block; |
| 130 | m_wire.parse(); |
| 131 | Block::element_const_iterator val = m_wire.elements_begin(); |
| 132 | |
| 133 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) { |
| 134 | m_faceId = readNonNegativeInteger(*val); |
| 135 | ++val; |
| 136 | } |
| 137 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 138 | BOOST_THROW_EXCEPTION(Error("missing required FaceId field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) { |
| 142 | m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 143 | ++val; |
| 144 | } |
| 145 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 146 | BOOST_THROW_EXCEPTION(Error("missing required Uri field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) { |
| 150 | m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 151 | ++val; |
| 152 | } |
| 153 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 154 | BOOST_THROW_EXCEPTION(Error("missing required LocalUri field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::ExpirationPeriod) { |
| 158 | m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val)); |
| 159 | m_hasExpirationPeriod = true; |
| 160 | ++val; |
| 161 | } |
| 162 | else { |
| 163 | m_hasExpirationPeriod = false; |
| 164 | // ExpirationPeriod is optional |
| 165 | } |
| 166 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 167 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) { |
| 168 | m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val)); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 169 | ++val; |
| 170 | } |
| 171 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 172 | BOOST_THROW_EXCEPTION(Error("missing required FaceScope field")); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) { |
| 176 | m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val)); |
| 177 | ++val; |
| 178 | } |
| 179 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 180 | BOOST_THROW_EXCEPTION(Error("missing required FacePersistency field")); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) { |
| 184 | m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val)); |
| 185 | ++val; |
| 186 | } |
| 187 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 188 | BOOST_THROW_EXCEPTION(Error("missing required LinkType field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) { |
| 192 | m_nInInterests = readNonNegativeInteger(*val); |
| 193 | ++val; |
| 194 | } |
| 195 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 196 | BOOST_THROW_EXCEPTION(Error("missing required NInInterests field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) { |
| 200 | m_nInDatas = readNonNegativeInteger(*val); |
| 201 | ++val; |
| 202 | } |
| 203 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 204 | BOOST_THROW_EXCEPTION(Error("missing required NInDatas field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 207 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) { |
| 208 | m_nInNacks = readNonNegativeInteger(*val); |
| 209 | ++val; |
| 210 | } |
| 211 | else { |
| 212 | BOOST_THROW_EXCEPTION(Error("missing required NInNacks field")); |
| 213 | } |
| 214 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 215 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) { |
| 216 | m_nOutInterests = readNonNegativeInteger(*val); |
| 217 | ++val; |
| 218 | } |
| 219 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 220 | BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) { |
| 224 | m_nOutDatas = readNonNegativeInteger(*val); |
| 225 | ++val; |
| 226 | } |
| 227 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 228 | BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 231 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) { |
| 232 | m_nOutNacks = readNonNegativeInteger(*val); |
| 233 | ++val; |
| 234 | } |
| 235 | else { |
| 236 | BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field")); |
| 237 | } |
| 238 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 239 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInBytes) { |
| 240 | m_nInBytes = readNonNegativeInteger(*val); |
| 241 | ++val; |
| 242 | } |
| 243 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 244 | BOOST_THROW_EXCEPTION(Error("missing required NInBytes field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutBytes) { |
| 248 | m_nOutBytes = readNonNegativeInteger(*val); |
| 249 | ++val; |
| 250 | } |
| 251 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 252 | BOOST_THROW_EXCEPTION(Error("missing required NOutBytes field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 253 | } |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame^] | 254 | |
| 255 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) { |
| 256 | m_flags = readNonNegativeInteger(*val); |
| 257 | ++val; |
| 258 | } |
| 259 | else { |
| 260 | BOOST_THROW_EXCEPTION(Error("missing required Flags field")); |
| 261 | } |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 264 | FaceStatus& |
| 265 | FaceStatus::setExpirationPeriod(const time::milliseconds& expirationPeriod) |
| 266 | { |
| 267 | m_wire.reset(); |
| 268 | m_expirationPeriod = expirationPeriod; |
| 269 | m_hasExpirationPeriod = true; |
| 270 | return *this; |
| 271 | } |
| 272 | |
| 273 | FaceStatus& |
| 274 | FaceStatus::setNInInterests(uint64_t nInInterests) |
| 275 | { |
| 276 | m_wire.reset(); |
| 277 | m_nInInterests = nInInterests; |
| 278 | return *this; |
| 279 | } |
| 280 | |
| 281 | FaceStatus& |
| 282 | FaceStatus::setNInDatas(uint64_t nInDatas) |
| 283 | { |
| 284 | m_wire.reset(); |
| 285 | m_nInDatas = nInDatas; |
| 286 | return *this; |
| 287 | } |
| 288 | |
| 289 | FaceStatus& |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 290 | FaceStatus::setNInNacks(uint64_t nInNacks) |
| 291 | { |
| 292 | m_wire.reset(); |
| 293 | m_nInNacks = nInNacks; |
| 294 | return *this; |
| 295 | } |
| 296 | |
| 297 | FaceStatus& |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 298 | FaceStatus::setNOutInterests(uint64_t nOutInterests) |
| 299 | { |
| 300 | m_wire.reset(); |
| 301 | m_nOutInterests = nOutInterests; |
| 302 | return *this; |
| 303 | } |
| 304 | |
| 305 | FaceStatus& |
| 306 | FaceStatus::setNOutDatas(uint64_t nOutDatas) |
| 307 | { |
| 308 | m_wire.reset(); |
| 309 | m_nOutDatas = nOutDatas; |
| 310 | return *this; |
| 311 | } |
| 312 | |
| 313 | FaceStatus& |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 314 | FaceStatus::setNOutNacks(uint64_t nOutNacks) |
| 315 | { |
| 316 | m_wire.reset(); |
| 317 | m_nOutNacks = nOutNacks; |
| 318 | return *this; |
| 319 | } |
| 320 | |
| 321 | FaceStatus& |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 322 | FaceStatus::setNInBytes(uint64_t nInBytes) |
| 323 | { |
| 324 | m_wire.reset(); |
| 325 | m_nInBytes = nInBytes; |
| 326 | return *this; |
| 327 | } |
| 328 | |
| 329 | FaceStatus& |
| 330 | FaceStatus::setNOutBytes(uint64_t nOutBytes) |
| 331 | { |
| 332 | m_wire.reset(); |
| 333 | m_nOutBytes = nOutBytes; |
| 334 | return *this; |
| 335 | } |
| 336 | |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame^] | 337 | FaceStatus& |
| 338 | FaceStatus::setFlags(uint64_t flags) |
| 339 | { |
| 340 | m_wire.reset(); |
| 341 | m_flags = flags; |
| 342 | return *this; |
| 343 | } |
| 344 | |
| 345 | bool |
| 346 | FaceStatus::getFlagBit(size_t bit) const |
| 347 | { |
| 348 | if (bit >= 64) { |
| 349 | BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)")); |
| 350 | } |
| 351 | |
| 352 | return m_flags & (1 << bit); |
| 353 | } |
| 354 | |
| 355 | FaceStatus& |
| 356 | FaceStatus::setFlagBit(size_t bit, bool value) |
| 357 | { |
| 358 | if (bit >= 64) { |
| 359 | BOOST_THROW_EXCEPTION(std::out_of_range("bit must be within range [0, 64)")); |
| 360 | } |
| 361 | |
| 362 | m_wire.reset(); |
| 363 | |
| 364 | if (value) { |
| 365 | m_flags |= (1 << bit); |
| 366 | } |
| 367 | else { |
| 368 | m_flags &= ~(1 << bit); |
| 369 | } |
| 370 | |
| 371 | return *this; |
| 372 | } |
| 373 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 374 | void |
| 375 | FaceStatus::wireReset() const |
| 376 | { |
| 377 | m_wire.reset(); |
| 378 | } |
| 379 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 380 | std::ostream& |
| 381 | operator<<(std::ostream& os, const FaceStatus& status) |
| 382 | { |
| 383 | os << "FaceStatus(" |
| 384 | << "FaceID: " << status.getFaceId() << ",\n" |
| 385 | << "RemoteUri: " << status.getRemoteUri() << ",\n" |
| 386 | << "LocalUri: " << status.getLocalUri() << ",\n"; |
| 387 | |
| 388 | if (status.hasExpirationPeriod()) { |
| 389 | os << "ExpirationPeriod: " << status.getExpirationPeriod() << ",\n"; |
| 390 | } |
| 391 | else { |
| 392 | os << "ExpirationPeriod: infinite,\n"; |
| 393 | } |
| 394 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 395 | os << "FaceScope: " << status.getFaceScope() << ",\n" |
| 396 | << "FacePersistency: " << status.getFacePersistency() << ",\n" |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame^] | 397 | << "LinkType: " << status.getLinkType() << ",\n"; |
| 398 | |
| 399 | auto osFlags = os.flags(); |
| 400 | os << "Flags: " << std::showbase << std::hex << status.getFlags() << ",\n"; |
| 401 | os.flags(osFlags); |
| 402 | |
| 403 | os << "Counters: { Interests: {in: " << status.getNInInterests() << ", " |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 404 | << "out: " << status.getNOutInterests() << "},\n" |
| 405 | << " Data: {in: " << status.getNInDatas() << ", " |
| 406 | << "out: " << status.getNOutDatas() << "},\n" |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 407 | << " Nack: {in: " << status.getNInNacks() << ", " |
| 408 | << "out: " << status.getNOutNacks() << "},\n" |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 409 | << " bytes: {in: " << status.getNInBytes() << ", " |
| 410 | << "out: " << status.getNOutBytes() << "} }\n" |
| 411 | << ")"; |
| 412 | return os; |
| 413 | } |
| 414 | |
| 415 | } // namespace nfd |
| 416 | } // namespace ndn |