2012-02-06 16:44:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
2012-11-03 14:52:33 +01:00
|
|
|
* OwlPS is a project of the University of Franche-Comte
|
2012-02-06 16:44:09 +01:00
|
|
|
* (Université de Franche-Comté), France.
|
2012-11-03 14:52:33 +01:00
|
|
|
*
|
|
|
|
* Copyright © Université de Franche-Comté 2007-2012.
|
|
|
|
*
|
|
|
|
* Corresponding author: Matteo Cypriani <mcy@lm7.fr>
|
|
|
|
*
|
|
|
|
***********************************************************************
|
|
|
|
*
|
|
|
|
* This software is governed by the CeCILL license under French law and
|
|
|
|
* abiding by the rules of distribution of free software. You can use,
|
|
|
|
* modify and/or redistribute the software under the terms of the CeCILL
|
|
|
|
* license as circulated by CEA, CNRS and INRIA at the following URL:
|
|
|
|
* http://www.cecill.info
|
|
|
|
*
|
|
|
|
* As a counterpart to the access to the source code and rights to copy,
|
|
|
|
* modify and redistribute granted by the license, users are provided
|
|
|
|
* only with a limited warranty and the software's authors, the holder
|
|
|
|
* of the economic rights, and the successive licensors have only
|
|
|
|
* limited liability.
|
|
|
|
*
|
|
|
|
* In this respect, the user's attention is drawn to the risks
|
|
|
|
* associated with loading, using, modifying and/or developing or
|
|
|
|
* reproducing the software by the user in light of its specific status
|
|
|
|
* of free software, that may mean that it is complicated to manipulate,
|
|
|
|
* and that also therefore means that it is reserved for developers and
|
|
|
|
* experienced professionals having in-depth computer knowledge. Users
|
|
|
|
* are therefore encouraged to load and test the software's suitability
|
|
|
|
* as regards their requirements in conditions enabling the security of
|
|
|
|
* their systems and/or data to be ensured and, more generally, to use
|
|
|
|
* and operate it in the same conditions as regards security.
|
|
|
|
*
|
|
|
|
* The fact that you are presently reading this means that you have had
|
|
|
|
* knowledge of the CeCILL license and that you accept its terms.
|
|
|
|
*
|
|
|
|
***********************************************************************
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-02-11 17:24:21 +01:00
|
|
|
#include "input.hh"
|
|
|
|
#include "inputcsv.hh"
|
2011-03-18 10:37:06 +01:00
|
|
|
#include "inputudpsocket.hh"
|
2010-02-16 16:19:39 +01:00
|
|
|
#include "inputlogcsv.hh"
|
2010-02-19 11:42:04 +01:00
|
|
|
#include "calibrationrequest.hh"
|
2010-02-11 17:24:21 +01:00
|
|
|
#include "configuration.hh"
|
|
|
|
#include "posexcept.hh"
|
2010-02-19 11:42:04 +01:00
|
|
|
#include "stock.hh"
|
2010-02-11 17:24:21 +01:00
|
|
|
|
2011-07-25 16:50:35 +02:00
|
|
|
#include <iostream>
|
2010-03-03 17:57:32 +01:00
|
|
|
#include <string>
|
|
|
|
|
2010-02-11 17:24:21 +01:00
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-02-11 17:24:21 +01:00
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
Input::Input():
|
|
|
|
medium(NULL)
|
2010-02-11 17:24:21 +01:00
|
|
|
{
|
|
|
|
initialise_input_medium() ;
|
2010-02-16 16:19:39 +01:00
|
|
|
initialise_log_media() ;
|
2010-02-11 17:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Input::~Input()
|
|
|
|
{
|
|
|
|
delete medium ;
|
2010-03-03 17:57:32 +01:00
|
|
|
|
|
|
|
for (vector<InputLogMedium*>::const_iterator i = log_media.begin() ;
|
|
|
|
i != log_media.end() ; ++i)
|
|
|
|
delete *i ;
|
|
|
|
log_media.clear() ;
|
2010-02-11 17:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
void Input::initialise_input_medium()
|
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("input.medium"))
|
2010-04-20 15:59:27 +02:00
|
|
|
throw missing_configuration(
|
|
|
|
"No input medium specified in configuration!") ;
|
2010-02-11 17:24:21 +01:00
|
|
|
|
|
|
|
const string &medium_name =
|
2010-02-16 16:19:39 +01:00
|
|
|
Configuration::string_value("input.medium") ;
|
2010-02-11 17:24:21 +01:00
|
|
|
|
|
|
|
if (medium_name == "CSV")
|
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("input.csv-file"))
|
2010-04-20 15:59:27 +02:00
|
|
|
throw missing_configuration(
|
|
|
|
"No input CSV file specified in the configuration!") ;
|
2010-02-11 17:24:21 +01:00
|
|
|
medium = new
|
2010-02-16 16:19:39 +01:00
|
|
|
InputCSV(Configuration::string_value("input.csv-file")) ;
|
2010-02-11 17:24:21 +01:00
|
|
|
}
|
|
|
|
|
2011-03-28 17:51:06 +02:00
|
|
|
else if (medium_name == "UDP")
|
2011-03-18 10:37:06 +01:00
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("input.udp-port"))
|
|
|
|
throw missing_configuration(
|
|
|
|
"No input UDP port specified in the configuration!") ;
|
|
|
|
medium = new
|
|
|
|
InputUDPSocket(Configuration::int_value("input.udp-port")) ;
|
|
|
|
}
|
|
|
|
|
2010-02-11 17:24:21 +01:00
|
|
|
else
|
2010-04-20 15:59:27 +02:00
|
|
|
throw bad_configuration(
|
2012-01-24 18:43:00 +01:00
|
|
|
"The specified input medium \""+ medium_name +"\" is unknown!") ;
|
2010-02-11 17:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 16:19:39 +01:00
|
|
|
void Input::initialise_log_media()
|
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("log.medium"))
|
|
|
|
return ;
|
|
|
|
|
|
|
|
if (Configuration::value_exists_in_string_vector("log.medium", "none"))
|
|
|
|
return ;
|
|
|
|
|
|
|
|
const vector<string> &media_names =
|
|
|
|
Configuration::string_vector_value("log.medium") ;
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator i = media_names.begin() ;
|
|
|
|
i != media_names.end() ; ++i)
|
|
|
|
{
|
|
|
|
if (*i == "CSV")
|
|
|
|
initialise_log_csv() ;
|
|
|
|
|
|
|
|
else
|
2010-04-20 15:59:27 +02:00
|
|
|
throw bad_configuration(
|
2012-01-24 18:43:00 +01:00
|
|
|
"The input medium \""+ *i +
|
|
|
|
"\" specified for request logging is unknown!") ;
|
2010-02-16 16:19:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Input::initialise_log_csv()
|
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("log.csv-file"))
|
2010-04-20 15:59:27 +02:00
|
|
|
throw missing_configuration(
|
|
|
|
"No log CSV file specified in the configuration!") ;
|
2010-02-16 16:19:39 +01:00
|
|
|
|
|
|
|
log_media.push_back(
|
|
|
|
new InputLogCSV(
|
|
|
|
Configuration::string_value("log.csv-file"))) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 17:24:21 +01:00
|
|
|
const Request& Input::get_next_request() const
|
|
|
|
{
|
2012-06-08 18:23:14 +02:00
|
|
|
if (eof())
|
|
|
|
return medium->get_current_request() ;
|
|
|
|
|
|
|
|
const Request& request = medium->get_next_request() ;
|
|
|
|
log_current_request() ;
|
|
|
|
|
|
|
|
if (! request)
|
|
|
|
return medium->get_current_request() ;
|
|
|
|
|
|
|
|
/* Update the current time */
|
2012-06-08 19:08:56 +02:00
|
|
|
if (Configuration::bool_value("replay"))
|
2012-06-08 18:23:14 +02:00
|
|
|
Timestamp::update_current_time(request.get_time_sent()) ;
|
|
|
|
|
|
|
|
/* Clean the old requests */
|
|
|
|
unsigned int cr_timeout =
|
|
|
|
Configuration::uint_value(
|
|
|
|
"positioning.calibration-requests-timeout") ;
|
|
|
|
if (cr_timeout > 0)
|
|
|
|
Stock::delete_calibration_requests_older_than(cr_timeout) ;
|
|
|
|
|
|
|
|
/* If the request is a calibration request, add it to the Stock */
|
2012-07-24 16:21:03 +02:00
|
|
|
CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<CalibrationRequest*>(const_cast<Request*>(&request)) ;
|
|
|
|
if (calibration_request != NULL)
|
2010-02-16 16:19:39 +01:00
|
|
|
{
|
2012-07-24 16:21:03 +02:00
|
|
|
if (Configuration::bool_value(
|
2012-08-24 16:28:13 +02:00
|
|
|
"positioning.accept-new-calibration-requests"))
|
2011-06-17 16:02:19 +02:00
|
|
|
{
|
2012-07-24 16:21:03 +02:00
|
|
|
if (Configuration::is_configured("verbose"))
|
|
|
|
cerr
|
2012-08-24 16:28:13 +02:00
|
|
|
<< "Got a new calibration request (total "
|
|
|
|
<< Stock::nb_calibration_requests() << " in "
|
|
|
|
<< Stock::nb_reference_points()
|
|
|
|
<< " reference points).\n" ;
|
2012-07-24 16:21:03 +02:00
|
|
|
|
2012-06-08 18:43:41 +02:00
|
|
|
if (Configuration::bool_value(
|
|
|
|
"positioning.unique-calibration-requests"))
|
|
|
|
calibration_request->reference_point_delete_requests() ;
|
2012-06-08 18:23:14 +02:00
|
|
|
Stock::store_calibration_request(*calibration_request) ;
|
|
|
|
|
2013-05-17 20:02:38 +02:00
|
|
|
if (Configuration::autocalibration_enabled())
|
2012-06-08 18:23:14 +02:00
|
|
|
Stock::regenerate_reference_points() ;
|
2012-07-24 16:21:03 +02:00
|
|
|
}
|
|
|
|
else if (Configuration::is_configured("verbose"))
|
|
|
|
cerr
|
2012-08-24 16:28:13 +02:00
|
|
|
<< "Ignored new calibration request (positioning."
|
|
|
|
<< "accept-new-calibration-requests = false).\n" ;
|
2012-06-08 18:23:14 +02:00
|
|
|
|
2012-07-24 16:21:03 +02:00
|
|
|
if (! Configuration::bool_value(
|
2012-08-24 16:28:13 +02:00
|
|
|
"positioning.position-calibration-requests"))
|
2012-07-24 16:21:03 +02:00
|
|
|
medium->clear_current_request() ;
|
2010-02-16 16:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return medium->get_current_request() ;
|
2010-02-11 17:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Input::eof() const
|
|
|
|
{
|
|
|
|
if (medium == NULL)
|
|
|
|
throw null_input_medium() ;
|
|
|
|
return medium->eof() ;
|
|
|
|
}
|
2010-02-16 16:19:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Input::log_current_request() const
|
|
|
|
{
|
|
|
|
for (vector<InputLogMedium*>::const_iterator i = log_media.begin() ;
|
|
|
|
i != log_media.end() ; ++i)
|
|
|
|
(*i)->log_request(medium->get_current_request()) ;
|
|
|
|
}
|