blob: 8abe2fb4da70a6a781372f186a3857342b6a714e [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,
Vince Lehman5144f822014-07-23 15:12:56 -070040 AppFace& face,
41 const Name& prefix,
42 ndn::KeyChain& keyChain)
43 : SegmentPublisher(face, prefix, keyChain)
Steve DiBenedettoef04f272014-06-04 14:28:31 -060044 , 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