blob: cc0d6ea386c7fb362fdc74b103a1d627281bd2da [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento7f20d6e2017-01-16 14:43:58 -05003 * Copyright (c) 2013-2017 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{
88 return ForwarderStatus(Block(tlv::Content, payload));
89}
90
91FaceDatasetBase::FaceDatasetBase(const PartialName& datasetName)
92 : StatusDataset(datasetName)
93{
94}
95
96FaceDatasetBase::ResultType
97FaceDatasetBase::parseResult(ConstBufferPtr payload) const
98{
99 return parseDatasetVector<FaceStatus>(payload);
100}
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{
127 return parseDatasetVector<ChannelStatus>(payload);
128}
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{
138 return parseDatasetVector<FibEntry>(payload);
139}
140
141StrategyChoiceDataset::StrategyChoiceDataset()
142 : StatusDataset("strategy-choice/list")
143{
144}
145
146StrategyChoiceDataset::ResultType
147StrategyChoiceDataset::parseResult(ConstBufferPtr payload) const
148{
149 return parseDatasetVector<StrategyChoice>(payload);
150}
151
152RibDataset::RibDataset()
153 : StatusDataset("rib/list")
154{
155}
156
157RibDataset::ResultType
158RibDataset::parseResult(ConstBufferPtr payload) const
159{
160 return parseDatasetVector<RibEntry>(payload);
161}
162
163} // namespace nfd
164} // namespace ndn