nfdc: merge canonizer.hpp and find-face.hpp into face-helpers.hpp
Change-Id: I19ca5cbce8cab54e61eb7af0a32c33c3aa73faf1
diff --git a/tools/nfdc/canonizer.cpp b/tools/nfdc/canonizer.cpp
deleted file mode 100644
index c6f150b..0000000
--- a/tools/nfdc/canonizer.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "canonizer.hpp"
-
-namespace nfd::tools::nfdc {
-
-std::pair<std::optional<FaceUri>, std::string>
-canonize(ExecuteContext& ctx, const FaceUri& uri)
-{
- std::optional<FaceUri> result;
- std::string error;
- uri.canonize(
- [&result] (const FaceUri& canonicalUri) { result = canonicalUri; },
- [&error] (const std::string& errorReason) { error = errorReason; },
- ctx.face.getIoService(), ctx.getTimeout());
- ctx.face.processEvents();
-
- return {result, error};
-}
-
-std::pair<FindFace::Code, std::string>
-canonizeErrorHelper(const FaceUri& uri,
- const std::string& error,
- const std::string& field)
-{
- std::string msg = "Error during canonization of ";
- if (!field.empty()) {
- msg += field + " ";
- }
- msg += "'" + uri.toString() + "': " + error;
- return {FindFace::Code::CANONIZE_ERROR, msg};
-}
-
-} // namespace nfd::tools::nfdc
diff --git a/tools/nfdc/canonizer.hpp b/tools/nfdc/canonizer.hpp
deleted file mode 100644
index d693a55..0000000
--- a/tools/nfdc/canonizer.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_TOOLS_NFDC_CANONIZER_HPP
-#define NFD_TOOLS_NFDC_CANONIZER_HPP
-
-#include "core/common.hpp"
-#include "execute-command.hpp"
-#include "find-face.hpp"
-
-#include <ndn-cxx/net/face-uri.hpp>
-
-namespace nfd::tools::nfdc {
-
-/** \brief canonize FaceUri
- * \return pair of canonical FaceUri (nullopt if failure) and error string
- */
-std::pair<std::optional<FaceUri>, std::string>
-canonize(ExecuteContext& ctx, const FaceUri& uri);
-
-/** \brief helper to generate exit code and error message for face canonization failures
- * \param uri FaceUri
- * \param error error string returned by canonization process
- * \param field optional field identifier to include with message
- * \return pair of exit code and error message
- */
-std::pair<FindFace::Code, std::string>
-canonizeErrorHelper(const FaceUri& uri,
- const std::string& error,
- const std::string& field = "");
-
-} // namespace nfd::tools::nfdc
-
-#endif // NFD_TOOLS_NFDC_CANONIZER_HPP
diff --git a/tools/nfdc/command-definition.cpp b/tools/nfdc/command-definition.cpp
index c98197e..443aff0 100644
--- a/tools/nfdc/command-definition.cpp
+++ b/tools/nfdc/command-definition.cpp
@@ -228,6 +228,18 @@
NDN_THROW(std::invalid_argument("unrecognized boolean value '" + s + "'"));
}
+static ReportFormat
+parseReportFormat(const std::string& s)
+{
+ if (s == "xml") {
+ return ReportFormat::XML;
+ }
+ if (s == "text") {
+ return ReportFormat::TEXT;
+ }
+ NDN_THROW(std::invalid_argument("unrecognized ReportFormat '" + s + "'"));
+}
+
static FacePersistency
parseFacePersistency(const std::string& s)
{
diff --git a/tools/nfdc/find-face.cpp b/tools/nfdc/face-helpers.cpp
similarity index 83%
rename from tools/nfdc/find-face.cpp
rename to tools/nfdc/face-helpers.cpp
index 054cba9..93b896c 100644
--- a/tools/nfdc/find-face.cpp
+++ b/tools/nfdc/face-helpers.cpp
@@ -23,8 +23,7 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "find-face.hpp"
-#include "canonizer.hpp"
+#include "face-helpers.hpp"
#include "format-helpers.hpp"
#include <ndn-cxx/util/logger.hpp>
@@ -127,11 +126,11 @@
void
FindFace::query()
{
- auto datasetCb = [this] (const std::vector<ndn::nfd::FaceStatus>& result) {
+ auto datasetCb = [this] (const auto& result) {
m_res = Code::OK;
m_results = result;
};
- auto failureCb = [this] (uint32_t code, const std::string& reason) {
+ auto failureCb = [this] (uint32_t code, const auto& reason) {
m_res = Code::ERROR;
m_errorReason = "Error " + to_string(code) + " when querying face: " + reason;
};
@@ -178,4 +177,31 @@
}
}
+std::pair<std::optional<FaceUri>, std::string>
+canonize(ExecuteContext& ctx, const FaceUri& uri)
+{
+ std::optional<FaceUri> result;
+ std::string error;
+ uri.canonize(
+ [&result] (const auto& canonicalUri) { result = canonicalUri; },
+ [&error] (const auto& errorReason) { error = errorReason; },
+ ctx.face.getIoService(), ctx.getTimeout());
+ ctx.face.processEvents();
+
+ return {result, error};
+}
+
+std::pair<FindFace::Code, std::string>
+canonizeErrorHelper(const FaceUri& uri,
+ const std::string& error,
+ const std::string& field)
+{
+ std::string msg = "Error during canonization of ";
+ if (!field.empty()) {
+ msg += field + " ";
+ }
+ msg += "'" + uri.toString() + "': " + error;
+ return {FindFace::Code::CANONIZE_ERROR, msg};
+}
+
} // namespace nfd::tools::nfdc
diff --git a/tools/nfdc/find-face.hpp b/tools/nfdc/face-helpers.hpp
similarity index 82%
rename from tools/nfdc/find-face.hpp
rename to tools/nfdc/face-helpers.hpp
index 02de011..5c4ea18 100644
--- a/tools/nfdc/find-face.hpp
+++ b/tools/nfdc/face-helpers.hpp
@@ -23,8 +23,8 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_TOOLS_NFDC_FIND_FACE_HPP
-#define NFD_TOOLS_NFDC_FIND_FACE_HPP
+#ifndef NFD_TOOLS_NFDC_FACE_HELPERS_HPP
+#define NFD_TOOLS_NFDC_FACE_HELPERS_HPP
#include "execute-command.hpp"
@@ -33,7 +33,8 @@
using ndn::nfd::FaceQueryFilter;
using ndn::nfd::FaceStatus;
-/** \brief procedure to find a face
+/**
+ * \brief Procedure to find a face
*/
class FindFace : noncopyable
{
@@ -137,6 +138,25 @@
std::string m_errorReason;
};
+/**
+ * \brief Canonize a FaceUri
+ * \return canonical FaceUri (nullopt on failure) and error string
+ */
+std::pair<std::optional<FaceUri>, std::string>
+canonize(ExecuteContext& ctx, const FaceUri& uri);
+
+/**
+ * \brief Helper to generate exit code and error message for face canonization failures
+ * \param uri The FaceUri
+ * \param error The error string returned by the canonization process
+ * \param field An optional field identifier to include with the message
+ * \return exit code and error message
+ */
+std::pair<FindFace::Code, std::string>
+canonizeErrorHelper(const FaceUri& uri,
+ const std::string& error,
+ const std::string& field = "");
+
} // namespace nfd::tools::nfdc
-#endif // NFD_TOOLS_NFDC_FIND_FACE_HPP
+#endif // NFD_TOOLS_NFDC_FACE_HELPERS_HPP
diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp
index 4d9d3a2..446a281 100644
--- a/tools/nfdc/face-module.cpp
+++ b/tools/nfdc/face-module.cpp
@@ -24,8 +24,7 @@
*/
#include "face-module.hpp"
-#include "canonizer.hpp"
-#include "find-face.hpp"
+#include "face-helpers.hpp"
#include <boost/lexical_cast/try_lexical_convert.hpp>
@@ -368,7 +367,7 @@
const CommandOptions& options)
{
controller.fetch<ndn::nfd::FaceDataset>(
- [this, onSuccess] (const std::vector<FaceStatus>& result) {
+ [this, onSuccess] (const auto& result) {
m_status = result;
onSuccess();
},
diff --git a/tools/nfdc/rib-module.cpp b/tools/nfdc/rib-module.cpp
index d0489cf..bf3b662 100644
--- a/tools/nfdc/rib-module.cpp
+++ b/tools/nfdc/rib-module.cpp
@@ -24,9 +24,8 @@
*/
#include "rib-module.hpp"
-#include "canonizer.hpp"
#include "face-module.hpp"
-#include "find-face.hpp"
+#include "face-helpers.hpp"
#include "format-helpers.hpp"
namespace nfd::tools::nfdc {
@@ -97,7 +96,7 @@
nexthops = findFace.getFaceIds();
}
- listRoutesImpl(ctx, [&] (const RibEntry& entry, const Route& route) {
+ listRoutesImpl(ctx, [&] (const RibEntry&, const Route& route) {
return (nexthops.empty() || nexthops.count(route.getFaceId()) > 0) &&
(!origin || route.getOrigin() == *origin);
});
@@ -108,7 +107,7 @@
{
auto prefix = ctx.args.get<Name>("prefix");
- listRoutesImpl(ctx, [&] (const RibEntry& entry, const Route& route) {
+ listRoutesImpl(ctx, [&] (const RibEntry& entry, const Route&) {
return entry.getName() == prefix;
});
}
@@ -117,7 +116,7 @@
RibModule::listRoutesImpl(ExecuteContext& ctx, const RoutePredicate& filter)
{
ctx.controller.fetch<ndn::nfd::RibDataset>(
- [&] (const std::vector<RibEntry>& dataset) {
+ [&] (const auto& dataset) {
bool hasRoute = false;
for (const RibEntry& entry : dataset) {
for (const Route& route : entry.getRoutes()) {
@@ -307,7 +306,7 @@
const CommandOptions& options)
{
controller.fetch<ndn::nfd::RibDataset>(
- [this, onSuccess] (const std::vector<RibEntry>& result) {
+ [this, onSuccess] (const auto& result) {
m_status = result;
onSuccess();
},
diff --git a/tools/nfdc/status-report.cpp b/tools/nfdc/status-report.cpp
index ff0ea1c..3611e0f 100644
--- a/tools/nfdc/status-report.cpp
+++ b/tools/nfdc/status-report.cpp
@@ -28,18 +28,6 @@
namespace nfd::tools::nfdc {
-ReportFormat
-parseReportFormat(const std::string& s)
-{
- if (s == "xml") {
- return ReportFormat::XML;
- }
- if (s == "text") {
- return ReportFormat::TEXT;
- }
- NDN_THROW(std::invalid_argument("unrecognized ReportFormat '" + s + "'"));
-}
-
std::ostream&
operator<<(std::ostream& os, ReportFormat fmt)
{
diff --git a/tools/nfdc/status-report.hpp b/tools/nfdc/status-report.hpp
index 20c364d..67ff429 100644
--- a/tools/nfdc/status-report.hpp
+++ b/tools/nfdc/status-report.hpp
@@ -40,12 +40,9 @@
enum class ReportFormat {
XML = 1,
- TEXT = 2
+ TEXT = 2,
};
-ReportFormat
-parseReportFormat(const std::string& s);
-
std::ostream&
operator<<(std::ostream& os, ReportFormat fmt);