| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2014-2016, Regents of the University of California, |
| * Arizona Board of Regents, |
| * Colorado State University, |
| * University Pierre & Marie Curie, Sorbonne University, |
| * Washington University in St. Louis, |
| * Beijing Institute of Technology, |
| * The University of Memphis. |
| * |
| * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| * See AUTHORS.md for complete list of NFD authors and contributors. |
| * |
| * NFD is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #ifndef NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP |
| #define NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP |
| |
| #include "core/common.hpp" |
| #include <ndn-cxx/face.hpp> |
| #include <ndn-cxx/management/nfd-controller.hpp> |
| #include <ndn-cxx/util/face-uri.hpp> |
| #include <ndn-cxx/security/validator-null.hpp> |
| |
| namespace nfd { |
| namespace tools { |
| namespace nfdc { |
| |
| using ndn::util::FaceUri; |
| |
| class FaceIdFetcher |
| { |
| public: |
| typedef std::function<void(uint32_t)> SuccessCallback; |
| typedef std::function<void(const std::string&)> FailureCallback; |
| |
| /** \brief obtain FaceId from input |
| * \param face Reference to the Face that should be used to fetch data |
| * \param controller Reference to the controller that should be used to sign the Interest |
| * \param input User input, either FaceId or FaceUri |
| * \param allowCreate Whether creating face is allowed |
| * \param onSucceed Callback to be fired when faceId is obtained |
| * \param onFail Callback to be fired when an error occurs |
| */ |
| static void |
| start(ndn::Face& face, |
| ndn::nfd::Controller& controller, |
| const std::string& input, |
| bool allowCreate, |
| const SuccessCallback& onSucceed, |
| const FailureCallback& onFail); |
| |
| private: |
| FaceIdFetcher(ndn::Face& face, |
| ndn::nfd::Controller& controller, |
| bool allowCreate, |
| const SuccessCallback& onSucceed, |
| const FailureCallback& onFail); |
| |
| void |
| onQuerySuccess(const ndn::ConstBufferPtr& data, |
| const FaceUri& canonicalUri); |
| |
| void |
| onQueryFailure(uint32_t errorCode, |
| const FaceUri& canonicalUri); |
| |
| void |
| onCanonizeSuccess(const FaceUri& canonicalUri); |
| |
| void |
| onCanonizeFailure(const std::string& reason); |
| |
| void |
| startGetFaceId(const FaceUri& faceUri); |
| |
| void |
| startFaceCreate(const FaceUri& canonicalUri); |
| |
| void |
| onFaceCreateError(const ndn::nfd::ControlResponse& response, |
| const std::string& message); |
| |
| void |
| succeed(uint32_t faceId); |
| |
| void |
| fail(const std::string& reason); |
| |
| private: |
| ndn::Face& m_face; |
| ndn::nfd::Controller& m_controller; |
| bool m_allowCreate; |
| SuccessCallback m_onSucceed; |
| FailureCallback m_onFail; |
| ndn::ValidatorNull m_validator; |
| }; |
| |
| } // namespace nfdc |
| } // namespace tools |
| } // namespace nfd |
| |
| #endif // NFD_TOOLS_NFDC_FACE_ID_FETCHER_HPP |