Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 7f20d6e | 2017-01-16 14:43:58 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "status-dataset.hpp" |
| 23 | #include "../../util/concepts.hpp" |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 24 | |
| 25 | namespace ndn { |
| 26 | namespace nfd { |
| 27 | |
| 28 | StatusDataset::StatusDataset(const PartialName& datasetName) |
| 29 | : m_datasetName(datasetName) |
| 30 | { |
| 31 | } |
| 32 | |
Davide Pesavento | 7f20d6e | 2017-01-16 14:43:58 -0500 | [diff] [blame^] | 33 | StatusDataset::~StatusDataset() = default; |
| 34 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 35 | Name |
| 36 | StatusDataset::getDatasetPrefix(const Name& prefix) const |
| 37 | { |
| 38 | Name name; |
| 39 | name.append(prefix).append(m_datasetName); |
| 40 | this->addParameters(name); |
| 41 | return name; |
| 42 | } |
| 43 | |
| 44 | void |
| 45 | StatusDataset::addParameters(Name& name) const |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * \brief parses elements into a vector of T |
| 51 | * \tparam T element type |
| 52 | * \param payload pointer to a buffer of zero or more blocks of decodable by T |
| 53 | * \return a vector of T |
| 54 | * \throw tlv::Error cannot parse payload |
| 55 | */ |
| 56 | template<typename T> |
| 57 | static std::vector<T> |
| 58 | parseDatasetVector(ConstBufferPtr payload) |
| 59 | { |
| 60 | BOOST_CONCEPT_ASSERT((WireDecodable<T>)); |
| 61 | |
| 62 | std::vector<T> result; |
| 63 | |
| 64 | size_t offset = 0; |
| 65 | while (offset < payload->size()) { |
| 66 | bool isOk = false; |
| 67 | Block block; |
| 68 | std::tie(isOk, block) = Block::fromBuffer(payload, offset); |
| 69 | if (!isOk) { |
| 70 | BOOST_THROW_EXCEPTION(StatusDataset::ParseResultError("cannot decode Block")); |
| 71 | } |
| 72 | |
| 73 | offset += block.size(); |
| 74 | result.emplace_back(block); |
| 75 | } |
| 76 | |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | ForwarderGeneralStatusDataset::ForwarderGeneralStatusDataset() |
| 81 | : StatusDataset("status/general") |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | ForwarderGeneralStatusDataset::ResultType |
| 86 | ForwarderGeneralStatusDataset::parseResult(ConstBufferPtr payload) const |
| 87 | { |
| 88 | return ForwarderStatus(Block(tlv::Content, payload)); |
| 89 | } |
| 90 | |
| 91 | FaceDatasetBase::FaceDatasetBase(const PartialName& datasetName) |
| 92 | : StatusDataset(datasetName) |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | FaceDatasetBase::ResultType |
| 97 | FaceDatasetBase::parseResult(ConstBufferPtr payload) const |
| 98 | { |
| 99 | return parseDatasetVector<FaceStatus>(payload); |
| 100 | } |
| 101 | |
| 102 | FaceDataset::FaceDataset() |
| 103 | : FaceDatasetBase("faces/list") |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | FaceQueryDataset::FaceQueryDataset(const FaceQueryFilter& filter) |
| 108 | : FaceDatasetBase("faces/query") |
| 109 | , m_filter(filter) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | FaceQueryDataset::addParameters(Name& name) const |
| 115 | { |
| 116 | name.append(m_filter.wireEncode()); |
| 117 | } |
| 118 | |
Junxiao Shi | 1eacb97 | 2016-07-07 22:51:07 +0000 | [diff] [blame] | 119 | ChannelDataset::ChannelDataset() |
| 120 | : StatusDataset("faces/channels") |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | ChannelDataset::ResultType |
| 125 | ChannelDataset::parseResult(ConstBufferPtr payload) const |
| 126 | { |
| 127 | return parseDatasetVector<ChannelStatus>(payload); |
| 128 | } |
| 129 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 130 | FibDataset::FibDataset() |
| 131 | : StatusDataset("fib/list") |
| 132 | { |
| 133 | } |
| 134 | |
| 135 | FibDataset::ResultType |
| 136 | FibDataset::parseResult(ConstBufferPtr payload) const |
| 137 | { |
| 138 | return parseDatasetVector<FibEntry>(payload); |
| 139 | } |
| 140 | |
| 141 | StrategyChoiceDataset::StrategyChoiceDataset() |
| 142 | : StatusDataset("strategy-choice/list") |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | StrategyChoiceDataset::ResultType |
| 147 | StrategyChoiceDataset::parseResult(ConstBufferPtr payload) const |
| 148 | { |
| 149 | return parseDatasetVector<StrategyChoice>(payload); |
| 150 | } |
| 151 | |
| 152 | RibDataset::RibDataset() |
| 153 | : StatusDataset("rib/list") |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | RibDataset::ResultType |
| 158 | RibDataset::parseResult(ConstBufferPtr payload) const |
| 159 | { |
| 160 | return parseDatasetVector<RibEntry>(payload); |
| 161 | } |
| 162 | |
| 163 | } // namespace nfd |
| 164 | } // namespace ndn |