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 | */ |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 6 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 7 | #include "face-status-publisher.hpp" |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 8 | #include "face-flags.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 9 | #include "core/logger.hpp" |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 10 | #include <ndn-cpp-dev/management/nfd-face-status.hpp> |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
| 13 | |
| 14 | NFD_LOG_INIT("FaceStatusPublisher"); |
| 15 | |
| 16 | |
| 17 | FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable, |
| 18 | shared_ptr<AppFace> face, |
| 19 | const Name& prefix) |
| 20 | : SegmentPublisher(face, prefix) |
| 21 | , m_faceTable(faceTable) |
| 22 | { |
| 23 | |
| 24 | } |
| 25 | |
| 26 | |
| 27 | FaceStatusPublisher::~FaceStatusPublisher() |
| 28 | { |
| 29 | |
| 30 | } |
| 31 | |
| 32 | size_t |
| 33 | FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer) |
| 34 | { |
| 35 | size_t totalLength = 0; |
| 36 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 37 | for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 38 | i != m_faceTable.rend(); ++i) { |
| 39 | const shared_ptr<Face>& face = *i; |
| 40 | const FaceCounters& counters = face->getCounters(); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 41 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 42 | ndn::nfd::FaceStatus status; |
| 43 | status.setFaceId(face->getId()) |
| 44 | .setRemoteUri(face->getRemoteUri().toString()) |
| 45 | .setLocalUri(face->getLocalUri().toString()) |
| 46 | .setFlags(getFaceFlags(*face)) |
| 47 | .setNInInterests(counters.getNInInterests()) |
| 48 | .setNInDatas(counters.getNInDatas()) |
| 49 | .setNOutInterests(counters.getNOutInterests()) |
| 50 | .setNOutDatas(counters.getNOutDatas()); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 51 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 52 | totalLength += status.wireEncode(outBuffer); |
| 53 | } |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 54 | return totalLength; |
| 55 | } |
| 56 | |
| 57 | } // namespace nfd |