blob: 42e4f3ace8f1aa86a5318e6b6c2a68e3792064df [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
28#include "face-flags.hpp"
29#include "core/logger.hpp"
30#include "face/protocol-factory.hpp"
31#include "face/channel.hpp"
32
33#include <ndn-cxx/management/nfd-channel-status.hpp>
34
35namespace nfd {
36
37NFD_LOG_INIT("ChannelStatusPublisher");
38
39
40ChannelStatusPublisher::ChannelStatusPublisher(const FactoryMap& factories,
41 shared_ptr<AppFace> face,
42 const Name& prefix)
43 : SegmentPublisher(face, prefix)
44 , m_factories(factories)
45{
46
47}
48
49
50ChannelStatusPublisher::~ChannelStatusPublisher()
51{
52
53}
54
55size_t
56ChannelStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
57{
58 size_t totalLength = 0;
59 std::set<shared_ptr<ProtocolFactory> > seenFactories;
60
61 for (FactoryMap::const_iterator i = m_factories.begin();
62 i != m_factories.end(); ++i)
63 {
64 const shared_ptr<ProtocolFactory>& factory = i->second;
65
66 if (seenFactories.find(factory) != seenFactories.end())
67 {
68 continue;
69 }
70 seenFactories.insert(factory);
71
72 std::list<shared_ptr<const Channel> > channels = factory->getChannels();
73
74 for (std::list<shared_ptr<const Channel> >::const_iterator j = channels.begin();
75 j != channels.end(); ++j)
76 {
77 ndn::nfd::ChannelStatus entry;
78 entry.setLocalUri((*j)->getUri().toString());
79
80 totalLength += entry.wireEncode(outBuffer);
81 }
82 }
83
84 return totalLength;
85}
86
87} // namespace nfd