blob: bb14879957b4572ebc52f9855a2fffe043e1c359 [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"
Steve DiBenedettoef04f272014-06-04 14:28:31 -060027#include "face/protocol-factory.hpp"
28#include "face/channel.hpp"
29
30#include <ndn-cxx/management/nfd-channel-status.hpp>
31
32namespace nfd {
33
Steve DiBenedettoef04f272014-06-04 14:28:31 -060034ChannelStatusPublisher::ChannelStatusPublisher(const FactoryMap& factories,
Vince Lehman5144f822014-07-23 15:12:56 -070035 AppFace& face,
36 const Name& prefix,
37 ndn::KeyChain& keyChain)
38 : SegmentPublisher(face, prefix, keyChain)
Steve DiBenedettoef04f272014-06-04 14:28:31 -060039 , m_factories(factories)
40{
Steve DiBenedettoef04f272014-06-04 14:28:31 -060041}
42
Steve DiBenedettoef04f272014-06-04 14:28:31 -060043ChannelStatusPublisher::~ChannelStatusPublisher()
44{
Steve DiBenedettoef04f272014-06-04 14:28:31 -060045}
46
47size_t
48ChannelStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
49{
50 size_t totalLength = 0;
51 std::set<shared_ptr<ProtocolFactory> > seenFactories;
52
53 for (FactoryMap::const_iterator i = m_factories.begin();
54 i != m_factories.end(); ++i)
55 {
56 const shared_ptr<ProtocolFactory>& factory = i->second;
57
58 if (seenFactories.find(factory) != seenFactories.end())
59 {
60 continue;
61 }
62 seenFactories.insert(factory);
63
64 std::list<shared_ptr<const Channel> > channels = factory->getChannels();
65
66 for (std::list<shared_ptr<const Channel> >::const_iterator j = channels.begin();
67 j != channels.end(); ++j)
68 {
69 ndn::nfd::ChannelStatus entry;
70 entry.setLocalUri((*j)->getUri().toString());
71
72 totalLength += entry.wireEncode(outBuffer);
73 }
74 }
75
76 return totalLength;
77}
78
79} // namespace nfd