Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 83be1da | 2017-06-30 13:37:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 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> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace tools { |
| 35 | namespace nfdc { |
| 36 | |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 37 | class FaceIdFetcher |
| 38 | { |
| 39 | public: |
| 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 | |
| 59 | private: |
| 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 Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 87 | onFaceCreateError(const ndn::nfd::ControlResponse& response, |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 88 | const std::string& message); |
| 89 | |
| 90 | void |
| 91 | succeed(uint32_t faceId); |
| 92 | |
| 93 | void |
| 94 | fail(const std::string& reason); |
| 95 | |
| 96 | private: |
| 97 | ndn::Face& m_face; |
| 98 | ndn::nfd::Controller& m_controller; |
| 99 | bool m_allowCreate; |
| 100 | SuccessCallback m_onSucceed; |
| 101 | FailureCallback m_onFail; |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace nfdc |
| 105 | } // namespace tools |
| 106 | } // namespace nfd |
| 107 | |
| 108 | #endif // NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP |