blob: 89c731e003b3334831907c0eec9fe07a2a87b11a [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (C) 2014 Named Data Networking Project
* See COPYING for copyright and distribution information.
*/
#include "face-status-publisher.hpp"
namespace nfd {
NFD_LOG_INIT("FaceStatusPublisher");
FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable,
shared_ptr<AppFace> face,
const Name& prefix)
: SegmentPublisher(face, prefix)
, m_faceTable(faceTable)
{
}
FaceStatusPublisher::~FaceStatusPublisher()
{
}
size_t
FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
{
size_t totalLength = 0;
for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
i != m_faceTable.rend();
++i)
{
const shared_ptr<Face>& face = *i;
const FaceCounters& counters = face->getCounters();
const std::string uri = face->getUri().toString();
size_t statusLength = 0;
statusLength += prependNonNegativeIntegerBlock(outBuffer,
ndn::tlv::nfd::NOutDatas,
counters.getOutData());
statusLength += prependNonNegativeIntegerBlock(outBuffer,
ndn::tlv::nfd::NOutInterests,
counters.getOutInterest());
statusLength += prependNonNegativeIntegerBlock(outBuffer,
ndn::tlv::nfd::NInDatas,
counters.getInData());
statusLength += prependNonNegativeIntegerBlock(outBuffer,
ndn::tlv::nfd::NInInterests,
counters.getInInterest());
statusLength += prependByteArrayBlock(outBuffer,
ndn::tlv::nfd::Uri,
reinterpret_cast<const uint8_t*>(uri.c_str()),
uri.size());
statusLength += prependNonNegativeIntegerBlock(outBuffer,
ndn::tlv::nfd::FaceId,
face->getId());
statusLength += outBuffer.prependVarNumber(statusLength);
statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus);
totalLength += statusLength;
}
return totalLength;
}
} // namespace nfd