face-helpers.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_TOOLS_NFDC_FACE_HELPERS_HPP
27 #define NFD_TOOLS_NFDC_FACE_HELPERS_HPP
28 
29 #include "execute-command.hpp"
30 
31 namespace nfd::tools::nfdc {
32 
33 using ndn::nfd::FaceQueryFilter;
34 using ndn::nfd::FaceStatus;
35 
39 class FindFace : noncopyable
40 {
41 public:
42  enum class Code {
43  OK = 0,
44  ERROR = 1,
45  NOT_FOUND = 3,
46  CANONIZE_ERROR = 4,
47  AMBIGUOUS = 5,
48  NOT_STARTED = -1,
49  IN_PROGRESS = -2,
50  };
51 
53  {
54  LOCAL_URI = 1
55  };
56 
57  explicit
59 
63  Code
64  execute(const FaceUri& faceUri, bool allowMulti = false);
65 
69  Code
70  execute(uint64_t faceId);
71 
77  Code
78  execute(const std::any& faceIdOrUri, bool allowMulti = false);
79 
83  Code
84  execute(const FaceQueryFilter& filter, bool allowMulti = false);
85 
88  const std::vector<FaceStatus>&
89  getResults() const
90  {
91  return m_results;
92  }
93 
96  std::set<uint64_t>
97  getFaceIds() const;
98 
102  const FaceStatus&
103  getFaceStatus() const;
104 
105  uint64_t
106  getFaceId() const
107  {
108  return this->getFaceStatus().getFaceId();
109  }
110 
111  const std::string&
113  {
114  return m_errorReason;
115  }
116 
119  void
120  printDisambiguation(std::ostream& os, DisambiguationStyle style) const;
121 
122 private:
123  std::optional<FaceUri>
124  canonize(const std::string& fieldName, const FaceUri& uri);
125 
130  void
131  query();
132 
133 private:
134  ExecuteContext& m_ctx;
135  FaceQueryFilter m_filter;
136  Code m_res = Code::NOT_STARTED;
137  std::vector<FaceStatus> m_results;
138  std::string m_errorReason;
139 };
140 
145 std::pair<std::optional<FaceUri>, std::string>
146 canonize(ExecuteContext& ctx, const FaceUri& uri);
147 
155 std::pair<FindFace::Code, std::string>
156 canonizeErrorHelper(const FaceUri& uri,
157  const std::string& error,
158  const std::string& field = "");
159 
160 } // namespace nfd::tools::nfdc
161 
162 #endif // NFD_TOOLS_NFDC_FACE_HELPERS_HPP
Context for command execution.
Procedure to find a face.
std::set< uint64_t > getFaceIds() const
const FaceStatus & getFaceStatus() const
FindFace(ExecuteContext &ctx)
uint64_t getFaceId() const
@ AMBIGUOUS
found multiple faces and allowMulti is false
@ CANONIZE_ERROR
error during FaceUri canonization
@ OK
found exactly one face, or found multiple faces when allowMulti is true
Code execute(const FaceUri &faceUri, bool allowMulti=false)
Find face by FaceUri.
const std::vector< FaceStatus > & getResults() const
const std::string & getErrorReason() const
void printDisambiguation(std::ostream &os, DisambiguationStyle style) const
Print results for disambiguation.
std::pair< FindFace::Code, std::string > canonizeErrorHelper(const FaceUri &uri, const std::string &error, const std::string &field)
Helper to generate exit code and error message for face canonization failures.
std::pair< std::optional< FaceUri >, std::string > canonize(ExecuteContext &ctx, const FaceUri &uri)
Canonize a FaceUri.