/** NDN-Atmos: Cataloging Service for distributed data originally developed
 *  for atmospheric science data
 *  Copyright (C) 2015 Colorado State University
 *
 *  NDN-Atmos 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-Atmos 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-Atmos.  If not, see <http://www.gnu.org/licenses/>.
 **/

#include "config.hpp"
#include "catalog/catalog.hpp"
#include "query/query-adapter.hpp"
#include "publish/publish-adapter.hpp"

#include <memory>
#include <getopt.h>
#include <ndn-cxx/face.hpp>
#include <ChronoSync/socket.hpp>

#ifdef HAVE_LOG4CXX
  INIT_LOGGER("atmos-catalog::Main");
#endif

void
usage()
{
  std::cout << "\n Usage:\n atmos-catalog "
    "[-h] [-f config file] \n"
    "   [-f config file]    - set the configuration file\n"
    "   [-h]                - print help and exit\n"
    "\n";
}

int
main(int argc, char** argv)
{
  int option;
  std::string configFile(DEFAULT_CONFIG_FILE);

#ifdef HAVE_LOG4CXX
  log4cxx::PropertyConfigurator::configure(LOG4CXX_CONFIG_FILE);
#endif

  while ((option = getopt(argc, argv, "f:h")) != -1) {
    switch (option) {
      case 'f':
        configFile.assign(optarg);
        break;
      case 'h':
      default:
        usage();
        return 0;
    }
  }

  argc -= optind;
  argv += optind;
  if (argc != 0) {
    usage();
    return 1;
  }

  std::shared_ptr<ndn::Face> face(new ndn::Face());
  std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain());

  // For now, share chronosync::Socket in both queryAdapter and publishAdapter
  // to allow queryAdapter to get the digest.
  // We may have to save digest in Database later
  std::shared_ptr<chronosync::Socket> syncSocket;

  std::unique_ptr<atmos::util::CatalogAdapter>
    queryAdapter(new atmos::query::QueryAdapter<ConnectionPool_T>(face, keyChain, syncSocket));
  std::unique_ptr<atmos::util::CatalogAdapter>
    publishAdapter(new atmos::publish::PublishAdapter<ConnectionPool_T>(face, keyChain, syncSocket));

  atmos::catalog::Catalog catalogInstance(face, keyChain, configFile);
  catalogInstance.addAdapter(publishAdapter);
  catalogInstance.addAdapter(queryAdapter);

  try {
    catalogInstance.initialize();
  }
  catch (std::exception& e) {
    _LOG_ERROR(e.what());
    return 1;
  }

#ifndef NDEBUG
  try {
#endif
    face->processEvents();
#ifndef NDEBUG
  }
  catch (std::exception& e) {
    _LOG_ERROR(e.what());
    return 1;
  }
#endif

  return 0;
}
