29 #include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
30 #include <ndn-cxx/util/logger.hpp>
44 FaceQueryFilter filter;
45 filter.setRemoteUri(faceUri.toString());
46 return this->
execute(filter, allowMulti);
52 FaceQueryFilter filter;
53 filter.setFaceId(faceId);
60 const uint64_t* faceId = std::any_cast<uint64_t>(&faceIdOrUri);
61 if (faceId !=
nullptr) {
65 return this->
execute(std::any_cast<FaceUri>(faceIdOrUri), allowMulti);
76 if (m_filter.hasRemoteUri()) {
77 auto remoteUri = canonize(
"remote FaceUri", FaceUri(m_filter.getRemoteUri()));
81 m_filter.setRemoteUri(remoteUri->toString());
84 if (m_filter.hasLocalUri()) {
85 auto localUri = canonize(
"local FaceUri", FaceUri(m_filter.getLocalUri()));
89 m_filter.setLocalUri(localUri->toString());
94 if (m_results.size() == 0) {
96 m_errorReason =
"Face not found";
98 else if (m_results.size() > 1 && !allowMulti) {
100 m_errorReason =
"Multiple faces match the query";
106 std::optional<FaceUri>
107 FindFace::canonize(
const std::string& fieldName,
const FaceUri& uri)
110 if (!FaceUri::canCanonize(uri.getScheme())) {
111 NDN_LOG_DEBUG(
"Using " << fieldName <<
"=" << uri <<
" without canonization");
130 auto datasetCb = [
this] (
const auto& result) {
134 auto failureCb = [
this] (uint32_t code,
const auto& reason) {
136 m_errorReason =
"Error " + std::to_string(code) +
" when querying face: " + reason;
139 if (m_filter.empty()) {
140 m_ctx.
controller.fetch<ndn::nfd::FaceDataset>(
144 m_ctx.
controller.fetch<ndn::nfd::FaceQueryDataset>(
147 m_ctx.
face.processEvents();
153 std::set<uint64_t> faceIds;
154 for (
const FaceStatus& faceStatus : m_results) {
155 faceIds.insert(faceStatus.getFaceId());
163 BOOST_ASSERT(m_results.size() == 1);
164 return m_results.front();
171 for (
const auto& item : m_results) {
175 os << item.getFaceId() <<
" (local=" << item.getLocalUri() <<
')';
181 std::pair<std::optional<FaceUri>, std::string>
184 std::optional<FaceUri> result;
187 [&result] (
const auto& canonicalUri) { result = canonicalUri; },
188 [&error] (
const auto& errorReason) { error = errorReason; },
190 ctx.
face.processEvents();
192 return {result, error};
195 std::pair<FindFace::Code, std::string>
197 const std::string& error,
198 const std::string& field)
200 std::string msg =
"Error during canonization of ";
201 if (!field.empty()) {
204 msg +=
"'" + uri.toString() +
"': " + error;
Context for command execution.
ndn::nfd::Controller & controller
ndn::nfd::CommandOptions makeCommandOptions() const
ndn::time::nanoseconds getTimeout() const
Print different string on first and subsequent usage.