blob: 88ce6488b2958030f791c50cfe8341f19f886d28 [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi7f012472017-12-07 20:40:47 +00002/*
Davide Pesavento3b101d02018-07-21 22:44:09 -04003 * Copyright (c) 2013-2018 Regents of the University of California.
Junxiao Shi034c1882016-06-24 18:06:51 +00004 *
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 Shi7357ef22016-09-07 02:39:37 +000022#include "status-dataset.hpp"
23#include "../../util/concepts.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000024
25namespace ndn {
26namespace nfd {
27
28StatusDataset::StatusDataset(const PartialName& datasetName)
29 : m_datasetName(datasetName)
30{
31}
32
Davide Pesavento7f20d6e2017-01-16 14:43:58 -050033StatusDataset::~StatusDataset() = default;
34
Junxiao Shi034c1882016-06-24 18:06:51 +000035Name
36StatusDataset::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
44void
45StatusDataset::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 */
56template<typename T>
57static std::vector<T>
58parseDatasetVector(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
80ForwarderGeneralStatusDataset::ForwarderGeneralStatusDataset()
81 : StatusDataset("status/general")
82{
83}
84
85ForwarderGeneralStatusDataset::ResultType
86ForwarderGeneralStatusDataset::parseResult(ConstBufferPtr payload) const
87{
Davide Pesavento3b101d02018-07-21 22:44:09 -040088 return ForwarderStatus(Block(tlv::Content, std::move(payload)));
Junxiao Shi034c1882016-06-24 18:06:51 +000089}
90
91FaceDatasetBase::FaceDatasetBase(const PartialName& datasetName)
92 : StatusDataset(datasetName)
93{
94}
95
96FaceDatasetBase::ResultType
97FaceDatasetBase::parseResult(ConstBufferPtr payload) const
98{
Davide Pesavento3b101d02018-07-21 22:44:09 -040099 return parseDatasetVector<FaceStatus>(std::move(payload));
Junxiao Shi034c1882016-06-24 18:06:51 +0000100}
101
102FaceDataset::FaceDataset()
103 : FaceDatasetBase("faces/list")
104{
105}
106
107FaceQueryDataset::FaceQueryDataset(const FaceQueryFilter& filter)
108 : FaceDatasetBase("faces/query")
109 , m_filter(filter)
110{
111}
112
113void
114FaceQueryDataset::addParameters(Name& name) const
115{
116 name.append(m_filter.wireEncode());
117}
118
Junxiao Shi1eacb972016-07-07 22:51:07 +0000119ChannelDataset::ChannelDataset()
120 : StatusDataset("faces/channels")
121{
122}
123
124ChannelDataset::ResultType
125ChannelDataset::parseResult(ConstBufferPtr payload) const
126{
Davide Pesavento3b101d02018-07-21 22:44:09 -0400127 return parseDatasetVector<ChannelStatus>(std::move(payload));
Junxiao Shi1eacb972016-07-07 22:51:07 +0000128}
129
Junxiao Shi034c1882016-06-24 18:06:51 +0000130FibDataset::FibDataset()
131 : StatusDataset("fib/list")
132{
133}
134
135FibDataset::ResultType
136FibDataset::parseResult(ConstBufferPtr payload) const
137{
Davide Pesavento3b101d02018-07-21 22:44:09 -0400138 return parseDatasetVector<FibEntry>(std::move(payload));
Junxiao Shi034c1882016-06-24 18:06:51 +0000139}
140
Junxiao Shi7f012472017-12-07 20:40:47 +0000141CsInfoDataset::CsInfoDataset()
142 : StatusDataset("cs/info")
143{
144}
145
146CsInfoDataset::ResultType
147CsInfoDataset::parseResult(ConstBufferPtr payload) const
148{
Davide Pesavento3b101d02018-07-21 22:44:09 -0400149 return CsInfo(Block(std::move(payload)));
Junxiao Shi7f012472017-12-07 20:40:47 +0000150}
151
Junxiao Shi034c1882016-06-24 18:06:51 +0000152StrategyChoiceDataset::StrategyChoiceDataset()
153 : StatusDataset("strategy-choice/list")
154{
155}
156
157StrategyChoiceDataset::ResultType
158StrategyChoiceDataset::parseResult(ConstBufferPtr payload) const
159{
Davide Pesavento3b101d02018-07-21 22:44:09 -0400160 return parseDatasetVector<StrategyChoice>(std::move(payload));
Junxiao Shi034c1882016-06-24 18:06:51 +0000161}
162
163RibDataset::RibDataset()
164 : StatusDataset("rib/list")
165{
166}
167
168RibDataset::ResultType
169RibDataset::parseResult(ConstBufferPtr payload) const
170{
Davide Pesavento3b101d02018-07-21 22:44:09 -0400171 return parseDatasetVector<RibEntry>(std::move(payload));
Junxiao Shi034c1882016-06-24 18:06:51 +0000172}
173
174} // namespace nfd
175} // namespace ndn