/* -*- 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_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP
#define NFD_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP

#include "fw/forwarder.hpp"

namespace nfd {
namespace fw {
class Strategy;
} // namespace fw

namespace tests {

/** \brief install a strategy to forwarder
 *  \tparam S strategy type
 *  \param forwarder the forwarder
 *  \param args arguments to strategy constructor
 *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
 *                       and has an incompatible type
 *  \return a reference to the strategy
 *  \deprecated use strategy registry
 *  \todo #3868 delete this function template
 */
template<typename S, typename ...Args>
typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
install(Forwarder& forwarder, Args&&... args)
{
  auto strategy = make_unique<S>(ref(forwarder), std::forward<Args>(args)...);
  fw::Strategy* installed = forwarder.getStrategyChoice().install(std::move(strategy)).second;
  return dynamic_cast<S&>(*installed);
}

/** \brief install a strategy to forwarder, and choose the strategy for a namespace
 *  \tparam S strategy type
 *  \param forwarder the forwarder
 *  \param prefix namespace to choose the strategy for
 *  \param args arguments to strategy constructor
 *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
 *                       and has an incompatible type
 *  \return a reference to the strategy
 *  \todo #3868 disallow args
 */
template<typename S, typename ...Args>
typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
choose(Forwarder& forwarder, const Name& prefix, Args&&... args)
{
  S& strategy = install<S>(forwarder, std::forward<Args>(args)...);
  StrategyChoice& sc = forwarder.getStrategyChoice();
  sc.insert(prefix, strategy.getName());
  return dynamic_cast<S&>(sc.findEffectiveStrategy(prefix));
}

/** \brief install a strategy to forwarder, and choose the strategy as default
 *  \tparam S strategy type
 *  \param forwarder the forwarder
 *  \throw std::bad_cast a strategy with duplicate strategyName is already installed
 *                       and has an incompatible type
 *  \return a reference to the strategy
 *  \todo #3868 merge into the other overload with default argument
 */
template<typename S>
typename std::enable_if<std::is_base_of<fw::Strategy, S>::value, S&>::type
choose(Forwarder& forwarder)
{
  return choose<S>(forwarder, "ndn:/");
}

} // namespace tests
} // namespace nfd

#endif // NFD_TESTS_DAEMON_FW_INSTALL_STRATEGY_HPP
