Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 1 | /* -*- 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 DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 27 | #include "face/protocol-factory.hpp" |
| 28 | #include "face/channel.hpp" |
| 29 | |
| 30 | #include <ndn-cxx/management/nfd-channel-status.hpp> |
| 31 | |
| 32 | namespace nfd { |
| 33 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 34 | ChannelStatusPublisher::ChannelStatusPublisher(const FactoryMap& factories, |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 35 | AppFace& face, |
| 36 | const Name& prefix, |
| 37 | ndn::KeyChain& keyChain) |
| 38 | : SegmentPublisher(face, prefix, keyChain) |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 39 | , m_factories(factories) |
| 40 | { |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 41 | } |
| 42 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 43 | ChannelStatusPublisher::~ChannelStatusPublisher() |
| 44 | { |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | size_t |
| 48 | ChannelStatusPublisher::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 |