Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MANAGEMENT_NFD_FACE_STATUS_HPP |
| 23 | #define NDN_MANAGEMENT_NFD_FACE_STATUS_HPP |
| 24 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 25 | // 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 Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 28 | #include "../encoding/tlv-nfd.hpp" |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 29 | #include "../encoding/encoding-buffer.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 30 | #include "../encoding/block-helpers.hpp" |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 31 | #include "../util/time.hpp" |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
| 34 | namespace nfd { |
| 35 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 36 | /** |
| 37 | * \ingroup management |
| 38 | * \brief represents Face status |
| 39 | * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 40 | */ |
| 41 | class FaceStatus : public FaceFlagsTraits<FaceStatus> |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
| 44 | class Error : public Tlv::Error |
| 45 | { |
| 46 | public: |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 47 | explicit |
| 48 | Error(const std::string& what) |
| 49 | : Tlv::Error(what) |
| 50 | { |
| 51 | } |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 54 | FaceStatus(); |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 55 | |
| 56 | explicit |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 57 | FaceStatus(const Block& block) |
| 58 | { |
| 59 | this->wireDecode(block); |
| 60 | } |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 62 | /** \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 | |
| 78 | public: // getters & setters |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 79 | uint64_t |
| 80 | getFaceId() const |
| 81 | { |
| 82 | return m_faceId; |
| 83 | } |
| 84 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 85 | 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 Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 121 | 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 Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 142 | 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 Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame^] | 212 | 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 Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 240 | private: |
| 241 | uint64_t m_faceId; |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 242 | std::string m_remoteUri; |
| 243 | std::string m_localUri; |
Alexander Afanasyev | e63eaf6 | 2014-06-30 12:40:55 -0700 | [diff] [blame] | 244 | time::milliseconds m_expirationPeriod; |
| 245 | bool m_hasExpirationPeriod; |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 246 | 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 Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame^] | 251 | uint64_t m_nInBytes; |
| 252 | uint64_t m_nOutBytes; |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 253 | |
| 254 | mutable Block m_wire; |
| 255 | }; |
| 256 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame^] | 257 | std::ostream& |
| 258 | operator<<(std::ostream& os, const FaceStatus& status); |
Alexander Afanasyev | 04fa37a | 2014-03-19 18:06:22 -0700 | [diff] [blame] | 259 | |
| 260 | } // namespace nfd |
| 261 | } // namespace ndn |
| 262 | |
Junxiao Shi | 7b1ba1a | 2014-03-29 01:01:56 -0700 | [diff] [blame] | 263 | #endif // NDN_MANAGEMENT_NFD_FACE_STATUS_HPP |