blob: 7c9a40f9871419b8b1de115ea46a381e1d2b5cc4 [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi83be1da2017-06-30 13:37:37 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shid243d712016-08-19 06:45:31 +00004 * 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_ID_FETCHER_HPP
27#define NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP
28
29#include "core/common.hpp"
30#include <ndn-cxx/face.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000031#include <ndn-cxx/mgmt/nfd/controller.hpp>
Junxiao Shid243d712016-08-19 06:45:31 +000032#include <ndn-cxx/security/validator-null.hpp>
33
34namespace nfd {
35namespace tools {
36namespace nfdc {
37
Junxiao Shid243d712016-08-19 06:45:31 +000038class FaceIdFetcher
39{
40public:
41 typedef std::function<void(uint32_t)> SuccessCallback;
42 typedef std::function<void(const std::string&)> FailureCallback;
43
44 /** \brief obtain FaceId from input
45 * \param face Reference to the Face that should be used to fetch data
46 * \param controller Reference to the controller that should be used to sign the Interest
47 * \param input User input, either FaceId or FaceUri
48 * \param allowCreate Whether creating face is allowed
49 * \param onSucceed Callback to be fired when faceId is obtained
50 * \param onFail Callback to be fired when an error occurs
51 */
52 static void
53 start(ndn::Face& face,
54 ndn::nfd::Controller& controller,
55 const std::string& input,
56 bool allowCreate,
57 const SuccessCallback& onSucceed,
58 const FailureCallback& onFail);
59
60private:
61 FaceIdFetcher(ndn::Face& face,
62 ndn::nfd::Controller& controller,
63 bool allowCreate,
64 const SuccessCallback& onSucceed,
65 const FailureCallback& onFail);
66
67 void
68 onQuerySuccess(const ndn::ConstBufferPtr& data,
69 const FaceUri& canonicalUri);
70
71 void
72 onQueryFailure(uint32_t errorCode,
73 const FaceUri& canonicalUri);
74
75 void
76 onCanonizeSuccess(const FaceUri& canonicalUri);
77
78 void
79 onCanonizeFailure(const std::string& reason);
80
81 void
82 startGetFaceId(const FaceUri& faceUri);
83
84 void
85 startFaceCreate(const FaceUri& canonicalUri);
86
87 void
Junxiao Shi29b41282016-08-22 03:47:02 +000088 onFaceCreateError(const ndn::nfd::ControlResponse& response,
Junxiao Shid243d712016-08-19 06:45:31 +000089 const std::string& message);
90
91 void
92 succeed(uint32_t faceId);
93
94 void
95 fail(const std::string& reason);
96
97private:
98 ndn::Face& m_face;
99 ndn::nfd::Controller& m_controller;
100 bool m_allowCreate;
101 SuccessCallback m_onSucceed;
102 FailureCallback m_onFail;
103 ndn::ValidatorNull m_validator;
104};
105
106} // namespace nfdc
107} // namespace tools
108} // namespace nfd
109
110#endif // NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP