blob: c212f72180427ee03b8c2c35131726dbcfb34a1d [file] [log] [blame]
Steve DiBenedettoef04f272014-06-04 14:28:31 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "channel-status-publisher.hpp"
27
Steve DiBenedettoef04f272014-06-04 14:28:31 -060028#include "core/logger.hpp"
29#include "face/protocol-factory.hpp"
30#include "face/channel.hpp"
31
32#include <ndn-cxx/management/nfd-channel-status.hpp>
33
34namespace nfd {
35
36NFD_LOG_INIT("ChannelStatusPublisher");
37
38
39ChannelStatusPublisher::ChannelStatusPublisher(const FactoryMap& factories,
40 shared_ptr<AppFace> face,
41 const Name& prefix)
42 : SegmentPublisher(face, prefix)
43 , m_factories(factories)
44{
45
46}
47
48
49ChannelStatusPublisher::~ChannelStatusPublisher()
50{
51
52}
53
54size_t
55ChannelStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
56{
57 size_t totalLength = 0;
58 std::set<shared_ptr<ProtocolFactory> > seenFactories;
59
60 for (FactoryMap::const_iterator i = m_factories.begin();
61 i != m_factories.end(); ++i)
62 {
63 const shared_ptr<ProtocolFactory>& factory = i->second;
64
65 if (seenFactories.find(factory) != seenFactories.end())
66 {
67 continue;
68 }
69 seenFactories.insert(factory);
70
71 std::list<shared_ptr<const Channel> > channels = factory->getChannels();
72
73 for (std::list<shared_ptr<const Channel> >::const_iterator j = channels.begin();
74 j != channels.end(); ++j)
75 {
76 ndn::nfd::ChannelStatus entry;
77 entry.setLocalUri((*j)->getUri().toString());
78
79 totalLength += entry.wireEncode(outBuffer);
80 }
81 }
82
83 return totalLength;
84}
85
86} // namespace nfd