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