Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | #include "face-status-publisher.hpp" |
| 7 | |
| 8 | namespace nfd { |
| 9 | |
| 10 | NFD_LOG_INIT("FaceStatusPublisher"); |
| 11 | |
| 12 | |
| 13 | FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable, |
| 14 | shared_ptr<AppFace> face, |
| 15 | const Name& prefix) |
| 16 | : SegmentPublisher(face, prefix) |
| 17 | , m_faceTable(faceTable) |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | |
| 23 | FaceStatusPublisher::~FaceStatusPublisher() |
| 24 | { |
| 25 | |
| 26 | } |
| 27 | |
| 28 | size_t |
| 29 | FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer) |
| 30 | { |
| 31 | size_t totalLength = 0; |
| 32 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 33 | for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin(); |
| 34 | i != m_faceTable.rend(); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 35 | ++i) |
| 36 | { |
| 37 | const shared_ptr<Face>& face = *i; |
| 38 | const FaceCounters& counters = face->getCounters(); |
| 39 | const std::string uri = face->getUri().toString(); |
| 40 | |
| 41 | size_t statusLength = 0; |
| 42 | |
| 43 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 44 | ndn::tlv::nfd::TotalOutgoingDataCounter, |
| 45 | counters.getOutData()); |
| 46 | |
| 47 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 48 | ndn::tlv::nfd::TotalOutgoingInterestCounter, |
| 49 | counters.getOutInterest()); |
| 50 | |
| 51 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 52 | ndn::tlv::nfd::TotalIncomingDataCounter, |
| 53 | counters.getInData()); |
| 54 | |
| 55 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 56 | ndn::tlv::nfd::TotalIncomingInterestCounter, |
| 57 | counters.getInInterest()); |
| 58 | |
| 59 | statusLength += prependByteArrayBlock(outBuffer, |
| 60 | ndn::tlv::nfd::Uri, |
| 61 | reinterpret_cast<const uint8_t*>(uri.c_str()), |
| 62 | uri.size()); |
| 63 | |
| 64 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 65 | ndn::tlv::nfd::FaceId, |
| 66 | face->getId()); |
| 67 | |
| 68 | statusLength += outBuffer.prependVarNumber(statusLength); |
| 69 | statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus); |
| 70 | |
| 71 | totalLength += statusLength; |
| 72 | } |
| 73 | return totalLength; |
| 74 | } |
| 75 | |
| 76 | } // namespace nfd |