find-face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, 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_FIND_FACE_HPP
27 #define NFD_TOOLS_NFDC_FIND_FACE_HPP
28 
29 #include "execute-command.hpp"
30 
31 namespace nfd {
32 namespace tools {
33 namespace nfdc {
34 
35 using ndn::nfd::FaceQueryFilter;
36 using ndn::nfd::FaceStatus;
37 
40 class FindFace : noncopyable
41 {
42 public:
43  enum class Code {
44  OK = 0,
45  ERROR = 1,
46  NOT_FOUND = 3,
47  CANONIZE_ERROR = 4,
48  AMBIGUOUS = 5,
49  NOT_STARTED = -1,
50  IN_PROGRESS = -2,
51  };
52 
54  {
55  LOCAL_URI = 1
56  };
57 
58  explicit
60 
64  Code
65  execute(const FaceUri& faceUri, bool allowMulti = false);
66 
70  Code
71  execute(uint64_t faceId);
72 
78  Code
79  execute(const ndn::any& faceIdOrUri, bool allowMulti = false);
80 
84  Code
85  execute(const FaceQueryFilter& filter, bool allowMulti = false);
86 
89  const std::vector<FaceStatus>&
90  getResults() const
91  {
92  return m_results;
93  }
94 
97  std::set<uint64_t>
98  getFaceIds() const;
99 
103  const FaceStatus&
104  getFaceStatus() const;
105 
106  uint64_t
107  getFaceId() const
108  {
109  return this->getFaceStatus().getFaceId();
110  }
111 
112  const std::string&
114  {
115  return m_errorReason;
116  }
117 
120  void
121  printDisambiguation(std::ostream& os, DisambiguationStyle style) const;
122 
123 private:
128  optional<FaceUri>
129  canonize(const std::string& fieldName, const FaceUri& input);
130 
135  void
136  query();
137 
138 private:
139  ExecuteContext& m_ctx;
140  FaceQueryFilter m_filter;
141  Code m_res = Code::NOT_STARTED;
142  std::vector<FaceStatus> m_results;
143  std::string m_errorReason;
144 };
145 
146 } // namespace nfdc
147 } // namespace tools
148 } // namespace nfd
149 
150 #endif // NFD_TOOLS_NFDC_FIND_FACE_HPP
FindFace(ExecuteContext &ctx)
Definition: find-face.cpp:37
context for command execution
found exactly one face, or found multiple faces when allowMulti is true
error during FaceUri canonization
found multiple faces and allowMulti is false
void printDisambiguation(std::ostream &os, DisambiguationStyle style) const
print results for disambiguation
Definition: find-face.cpp:170
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
procedure to find a face
Definition: find-face.hpp:40
Code execute(const FaceUri &faceUri, bool allowMulti=false)
find face by FaceUri
Definition: find-face.cpp:43
uint64_t getFaceId() const
Definition: find-face.hpp:107
const FaceStatus & getFaceStatus() const
Definition: find-face.cpp:163
const std::string & getErrorReason() const
Definition: find-face.hpp:113
const std::vector< FaceStatus > & getResults() const
Definition: find-face.hpp:90
std::set< uint64_t > getFaceIds() const
Definition: find-face.cpp:153