/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2015,  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 ndn-tools (Named Data Networking Essential Tools).
 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
 *
 * ndn-tools 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.
 *
 * ndn-tools 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
 * ndn-tools, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Copyright (c) 2014,  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/>.
 *
 * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
 */

#include "core/version.hpp"

namespace ndn {
namespace peek {

class NdnPeek : boost::noncopyable
{
public:
  explicit
  NdnPeek(char* programName)
    : m_programName(programName)
    , m_isVerbose(false)
    , m_mustBeFresh(false)
    , m_isChildSelectorRightmost(false)
    , m_minSuffixComponents(-1)
    , m_maxSuffixComponents(-1)
    , m_interestLifetime(-1)
    , m_isPayloadOnlySet(false)
    , m_timeout(-1)
    , m_prefixName("")
    , m_isDataReceived(false)
  {
  }

  void
  usage()
  {
    std::cout << "\n Usage:\n " << m_programName << " "
      "[-f] [-r] [-m min] [-M max] [-l lifetime] [-p] [-w timeout] ndn:/name\n"
      "   Get one data item matching the name prefix and write it to stdout\n"
      "   [-f]          - set MustBeFresh\n"
      "   [-r]          - set ChildSelector to select rightmost child\n"
      "   [-m min]      - set MinSuffixComponents\n"
      "   [-M max]      - set MaxSuffixComponents\n"
      "   [-l lifetime] - set InterestLifetime in time::milliseconds\n"
      "   [-p]          - print payload only, not full packet\n"
      "   [-w timeout]  - set Timeout in time::milliseconds\n"
      "   [-v]          - verbose output\n"
      "   [-h]          - print help and exit\n"
      "   [-V]          - print version and exit\n"
      "\n";
    exit(1);
  }

  void
  setVerbose()
  {
    m_isVerbose = true;
  }

  void
  setMustBeFresh()
  {
    m_mustBeFresh = true;
  }

  void
  setRightmostChildSelector()
  {
    m_isChildSelectorRightmost = true;
  }

  void
  setMinSuffixComponents(int minSuffixComponents)
  {
    if (minSuffixComponents < 0)
      usage();

    m_minSuffixComponents = minSuffixComponents;
  }

  void
  setMaxSuffixComponents(int maxSuffixComponents)
  {
    if (maxSuffixComponents < 0)
      usage();

    m_maxSuffixComponents = maxSuffixComponents;
  }

  void
  setInterestLifetime(int interestLifetime)
  {
    if (interestLifetime < 0)
      usage();

    m_interestLifetime = time::milliseconds(interestLifetime);
  }

  void
  setPayloadOnly()
  {
    m_isPayloadOnlySet = true;
  }

  void
  setTimeout(int timeout)
  {
    if (timeout < 0)
      usage();

    m_timeout = time::milliseconds(timeout);
  }

  void
  setPrefixName(char* prefixName)
  {
    m_prefixName = prefixName;

    if (m_prefixName.length() == 0)
      usage();
  }

  time::milliseconds
  getDefaultInterestLifetime()
  {
    return time::seconds(4);
  }

  Interest
  createInterestPacket()
  {
    Name interestName(m_prefixName);
    Interest interestPacket(interestName);

    if (m_mustBeFresh)
      interestPacket.setMustBeFresh(true);

    if (m_isChildSelectorRightmost)
      interestPacket.setChildSelector(1);

    if (m_minSuffixComponents >= 0)
      interestPacket.setMinSuffixComponents(m_minSuffixComponents);

    if (m_maxSuffixComponents >= 0)
      interestPacket.setMaxSuffixComponents(m_maxSuffixComponents);

    if (m_interestLifetime < time::milliseconds::zero())
      interestPacket.setInterestLifetime(getDefaultInterestLifetime());
    else
      interestPacket.setInterestLifetime(m_interestLifetime);

    if (m_isVerbose) {
      std::cerr << "INTEREST: " << interestPacket << std::endl;
    }

    return interestPacket;
  }

  void
  onData(const Interest& interest, Data& data)
  {
    m_isDataReceived = true;

    if (m_isVerbose) {
      std::cerr << "DATA, RTT: "
                << time::duration_cast<time::milliseconds>(time::steady_clock::now() - m_expressInterestTime).count()
                << "ms" << std::endl;
    }

    if (m_isPayloadOnlySet) {
      const Block& block = data.getContent();
      std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
    }
    else {
      const Block& block = data.wireEncode();
      std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
    }
  }

  void
  onTimeout(const Interest& interest)
  {
  }

  void
  run()
  {
    try {
      m_face.expressInterest(createInterestPacket(),
                             bind(&NdnPeek::onData, this, _1, _2),
                             bind(&NdnPeek::onTimeout, this, _1));
      m_expressInterestTime = time::steady_clock::now();
      if (m_timeout < time::milliseconds::zero()) {
        m_timeout = m_interestLifetime < time::milliseconds::zero() ?
                    getDefaultInterestLifetime() : m_interestLifetime;
      }
      m_face.processEvents(m_timeout);
    }
    catch (std::exception& e) {
      std::cerr << "ERROR: " << e.what() << std::endl;
      exit(1);
    }
    if (m_isVerbose && !m_isDataReceived) {
      std::cerr << "TIMEOUT" << std::endl;
    }
  }

  bool
  isDataReceived() const
  {
    return m_isDataReceived;
  }

private:
  std::string m_programName;
  bool m_isVerbose;
  bool m_mustBeFresh;
  bool m_isChildSelectorRightmost;
  int m_minSuffixComponents;
  int m_maxSuffixComponents;
  time::milliseconds m_interestLifetime;
  bool m_isPayloadOnlySet;
  time::milliseconds m_timeout;
  std::string m_prefixName;
  time::steady_clock::TimePoint m_expressInterestTime;
  bool m_isDataReceived;
  Face m_face;
};

int
main(int argc, char* argv[])
{
  NdnPeek program(argv[0]);
  int option;
  while ((option = getopt(argc, argv, "hvfrm:M:l:pw:V")) != -1) {
    switch (option) {
    case 'h':
      program.usage();
      break;
    case 'v':
      program.setVerbose();
      break;
    case 'f':
      program.setMustBeFresh();
      break;
    case 'r':
      program.setRightmostChildSelector();
      break;
    case 'm':
      program.setMinSuffixComponents(atoi(optarg));
      break;
    case 'M':
      program.setMaxSuffixComponents(atoi(optarg));
      break;
    case 'l':
      program.setInterestLifetime(atoi(optarg));
      break;
    case 'p':
      program.setPayloadOnly();
      break;
    case 'w':
      program.setTimeout(atoi(optarg));
      break;
    case 'V':
      std::cout << "ndnpeek " << tools::VERSION << std::endl;
      return 0;
    default:
      program.usage();
      break;
    }
  }

  argc -= optind;
  argv += optind;

  if (argv[0] == 0)
    program.usage();

  program.setPrefixName(argv[0]);
  program.run();

  if (program.isDataReceived())
    return 0;
  else
    return 1;
}

} // namespace peek
} // namespace ndn

int
main(int argc, char** argv)
{
  return ndn::peek::main(argc, argv);
}
