/*
 * This file is part of the Owl Positioning System (OwlPS) project.
 * It is subject to the copyright notice and license terms in the
 * COPYRIGHT.t2t file found in the top-level directory of this
 * distribution and at
 *   https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
 * No part of the OwlPS Project, including this file, may be copied,
 * modified, propagated, or distributed except according to the terms
 * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
 * distributed along with this file, either separately or by replacing
 * this notice by the COPYRIGHT.t2t file's contents.
 *
 ***********************************************************************
 *
 * This is the main source file of OwlPS Positioner, the program that
 * computes the position of the mobile terminals.
 */


#include "userinterface.hh"
#include "configuration.hh"
#include "inputdatareader.hh"
#include "stock.hh"
#include "positioning.hh"

#include <owlps.h>

#include <iostream>

#include <csignal>

using namespace std ;


int main(const int argc, const char **const argv)
{
  owl_run = true ;

  /* Read options & configuration */
  delete new UserInterface(argc, argv) ;

  if (owl_run)
    {
      /* Read input data */
      delete new InputDataReader() ;

      /* Set up signal handlers */
      struct sigaction action ;
      action.sa_flags = 0 ;
      sigemptyset(&action.sa_mask) ;
      action.sa_handler = owl_sigint_handler ;
      sigaction(SIGINT, &action, nullptr) ;
      action.sa_handler = owl_sigterm_handler ;
      sigaction(SIGTERM, &action, nullptr) ;

      /* Run! */
      Positioning positioning ;

      /* Clean */
      Stock::clear() ;
    }

  if (Configuration::is_configured("verbose"))
    cerr << argv[0] << ": exiting." << endl ;

  return 0 ;
}
