Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014 University of Memphis, |
| 4 | * Regents of the University of California |
| 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | **/ |
| 21 | |
| 22 | #include "face-controller.hpp" |
| 23 | #include "logger.hpp" |
| 24 | |
| 25 | namespace nlsr { |
| 26 | namespace util { |
| 27 | |
| 28 | INIT_LOGGER("FaceController"); |
| 29 | |
| 30 | using ndn::util::FaceUri; |
| 31 | |
| 32 | const ndn::time::seconds FaceController::TIME_ALLOWED_FOR_CANONIZATION = ndn::time::seconds(4); |
| 33 | |
| 34 | void |
| 35 | FaceController::createFace(const std::string& request, |
| 36 | const CommandSuccessCallback& onSuccess, |
| 37 | const CommandFailureCallback& onFailure) |
| 38 | { |
| 39 | FaceUri uri(request); |
| 40 | |
| 41 | _LOG_TRACE("Converting " << uri << " to canonical form"); |
| 42 | uri.canonize(bind(&FaceController::onCanonizeSuccess, this, _1, onSuccess, onFailure, uri), |
| 43 | bind(&FaceController::onCanonizeFailure, this, _1, onSuccess, onFailure, uri), |
| 44 | m_ioService, TIME_ALLOWED_FOR_CANONIZATION); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | FaceController::createFaceInNfd(const FaceUri& uri, |
| 49 | const CommandSuccessCallback& onSuccess, |
| 50 | const CommandFailureCallback& onFailure) |
| 51 | { |
| 52 | ndn::nfd::ControlParameters faceParameters; |
| 53 | faceParameters.setUri(uri.toString()); |
| 54 | |
| 55 | _LOG_DEBUG("Creating Face in NFD with face-uri: " << uri); |
| 56 | m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters, onSuccess, onFailure); |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | FaceController::onCanonizeSuccess(const FaceUri& uri, |
| 61 | const CommandSuccessCallback& onSuccess, |
| 62 | const CommandFailureCallback& onFailure, |
| 63 | const FaceUri& request) |
| 64 | { |
| 65 | _LOG_DEBUG("Converted " << request << " to canonical form: " << uri); |
| 66 | |
| 67 | createFaceInNfd(uri, onSuccess, onFailure); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | FaceController::onCanonizeFailure(const std::string& reason, |
| 72 | const CommandSuccessCallback& onSuccess, |
| 73 | const CommandFailureCallback& onFailure, |
| 74 | const FaceUri& request) |
| 75 | { |
| 76 | _LOG_WARN("Could not convert " << request << " to canonical form: " << reason); |
| 77 | onFailure(CANONIZE_ERROR_CODE, "Could not canonize face-uri: " + request.toString()); |
| 78 | } |
| 79 | |
| 80 | } // namespace util |
| 81 | } // namespace nlsr |