blob: 5e45b7bf4db82da0b0f0014951dfe00cca825490 [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib347b7f2017-07-23 14:01:58 +00002/*
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
33namespace nfd {
34namespace tools {
35namespace nfdc {
36
Junxiao Shid243d712016-08-19 06:45:31 +000037class FaceIdFetcher
38{
39public:
40 typedef std::function<void(uint32_t)> SuccessCallback;
41 typedef std::function<void(const std::string&)> FailureCallback;
42
43 /** \brief obtain FaceId from input
44 * \param face Reference to the Face that should be used to fetch data
45 * \param controller Reference to the controller that should be used to sign the Interest
46 * \param input User input, either FaceId or FaceUri
47 * \param allowCreate Whether creating face is allowed
48 * \param onSucceed Callback to be fired when faceId is obtained
49 * \param onFail Callback to be fired when an error occurs
50 */
51 static void
52 start(ndn::Face& face,
53 ndn::nfd::Controller& controller,
54 const std::string& input,
55 bool allowCreate,
56 const SuccessCallback& onSucceed,
57 const FailureCallback& onFail);
58
59private:
60 FaceIdFetcher(ndn::Face& face,
61 ndn::nfd::Controller& controller,
62 bool allowCreate,
63 const SuccessCallback& onSucceed,
64 const FailureCallback& onFail);
65
66 void
67 onQuerySuccess(const ndn::ConstBufferPtr& data,
68 const FaceUri& canonicalUri);
69
70 void
71 onQueryFailure(uint32_t errorCode,
72 const FaceUri& canonicalUri);
73
74 void
75 onCanonizeSuccess(const FaceUri& canonicalUri);
76
77 void
78 onCanonizeFailure(const std::string& reason);
79
80 void
81 startGetFaceId(const FaceUri& faceUri);
82
83 void
84 startFaceCreate(const FaceUri& canonicalUri);
85
86 void
Junxiao Shi29b41282016-08-22 03:47:02 +000087 onFaceCreateError(const ndn::nfd::ControlResponse& response,
Junxiao Shid243d712016-08-19 06:45:31 +000088 const std::string& message);
89
90 void
91 succeed(uint32_t faceId);
92
93 void
94 fail(const std::string& reason);
95
96private:
97 ndn::Face& m_face;
98 ndn::nfd::Controller& m_controller;
99 bool m_allowCreate;
100 SuccessCallback m_onSucceed;
101 FailureCallback m_onFail;
Junxiao Shid243d712016-08-19 06:45:31 +0000102};
103
104} // namespace nfdc
105} // namespace tools
106} // namespace nfd
107
108#endif // NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP