299 lines
7.9 KiB
C++
299 lines
7.9 KiB
C++
/*
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
|
* OwlPS is a project of the University of Franche-Comte
|
|
* (Université de Franche-Comté), France.
|
|
*
|
|
* 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.
|
|
*
|
|
***********************************************************************
|
|
*/
|
|
|
|
|
|
#include "inputdatareader.hh"
|
|
#include "accesspointsreadercsv.hh"
|
|
#include "mobilesreadercsv.hh"
|
|
#include "topologyreadercsv.hh"
|
|
#include "inputcsv.hh"
|
|
#include "calibrationrequest.hh"
|
|
#include "configuration.hh"
|
|
#include "posexcept.hh"
|
|
#include "stock.hh"
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
InputDataReader::InputDataReader()
|
|
{
|
|
read_access_points() ;
|
|
read_mobiles() ;
|
|
read_topology() ;
|
|
read_reference_points() ;
|
|
}
|
|
|
|
|
|
InputDataReader::~InputDataReader()
|
|
{
|
|
for (vector<InputMedium*>::const_iterator i =
|
|
reference_points_media.begin() ;
|
|
i != reference_points_media.end() ; ++i)
|
|
delete *i ;
|
|
reference_points_media.clear() ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Access points *** */
|
|
|
|
|
|
void InputDataReader::read_access_points()
|
|
{
|
|
if (! Configuration::is_configured("data-input.ap-medium"))
|
|
return ;
|
|
|
|
initialise_access_points_media() ;
|
|
|
|
if (Configuration::is_configured("verbose"))
|
|
cerr << Stock::nb_aps() << " access points stored.\n" ;
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_access_points_media()
|
|
{
|
|
const vector<string> &media_names =
|
|
Configuration::string_vector_value("data-input.ap-medium") ;
|
|
|
|
for (vector<string>::const_iterator i = media_names.begin() ;
|
|
i != media_names.end() ; ++i)
|
|
{
|
|
if (*i == "CSV")
|
|
initialise_access_points_csv() ;
|
|
|
|
else
|
|
throw bad_configuration(
|
|
"Access points input medium type unknown \""+ *i +"\"") ;
|
|
}
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_access_points_csv()
|
|
{
|
|
if (! Configuration::is_configured("data-input.ap-csv-file"))
|
|
throw missing_configuration(
|
|
"No input CSV file specified for access points") ;
|
|
|
|
AccessPointsReaderCSV(
|
|
Configuration::string_value("data-input.ap-csv-file")) ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Mobiles *** */
|
|
|
|
|
|
void InputDataReader::read_mobiles()
|
|
{
|
|
if (! Configuration::is_configured("data-input.mobile-medium"))
|
|
return ;
|
|
|
|
initialise_mobiles_media() ;
|
|
|
|
if (Configuration::is_configured("verbose"))
|
|
cerr << Stock::nb_mobiles() << " mobiles stored.\n" ;
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_mobiles_media()
|
|
{
|
|
const vector<string> &media_names =
|
|
Configuration::string_vector_value("data-input.mobile-medium") ;
|
|
|
|
for (vector<string>::const_iterator i = media_names.begin() ;
|
|
i != media_names.end() ; ++i)
|
|
{
|
|
if (*i == "CSV")
|
|
initialise_mobiles_csv() ;
|
|
|
|
else
|
|
throw bad_configuration(
|
|
"Mobiles' input medium type unknown \""+ *i +"\"") ;
|
|
}
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_mobiles_csv()
|
|
{
|
|
if (! Configuration::is_configured("data-input.mobile-csv-file"))
|
|
throw missing_configuration(
|
|
"No input CSV file specified for mobiles") ;
|
|
|
|
MobilesReaderCSV(
|
|
Configuration::string_value("data-input.mobile-csv-file")) ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Topology *** */
|
|
|
|
|
|
void InputDataReader::read_topology()
|
|
{
|
|
if (! Configuration::is_configured("data-input.topology-medium"))
|
|
return ;
|
|
|
|
initialise_topology_media() ;
|
|
|
|
if (Configuration::is_configured("verbose"))
|
|
{
|
|
cerr
|
|
<< Stock::nb_buildings() << " buildings stored.\n"
|
|
<< Stock::nb_waypoints() << " waypoints stored.\n" ;
|
|
}
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_topology_media()
|
|
{
|
|
const vector<string> &media_names =
|
|
Configuration::string_vector_value("data-input.topology-medium") ;
|
|
|
|
for (vector<string>::const_iterator i = media_names.begin() ;
|
|
i != media_names.end() ; ++i)
|
|
{
|
|
if (*i == "CSV")
|
|
initialise_topology_csv() ;
|
|
|
|
else
|
|
throw bad_configuration(
|
|
"Topology input medium type unknown \""+ *i +"\"") ;
|
|
}
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_topology_csv()
|
|
{
|
|
if (! Configuration::is_configured("data-input.areas-csv-file"))
|
|
throw missing_configuration(
|
|
"No topology input CSV file specified for areas") ;
|
|
|
|
if (! Configuration::is_configured("data-input.waypoints-csv-file"))
|
|
throw missing_configuration(
|
|
"No topology input CSV file specified for waypoints") ;
|
|
|
|
TopologyReaderCSV(
|
|
Configuration::string_value("data-input.areas-csv-file"),
|
|
Configuration::string_value("data-input.waypoints-csv-file")) ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Reference points *** */
|
|
|
|
|
|
void InputDataReader::read_reference_points()
|
|
{
|
|
if (! Configuration::is_configured("data-input.reference-points-medium"))
|
|
return ;
|
|
|
|
initialise_reference_points_media() ;
|
|
read_from_reference_points_media() ;
|
|
|
|
if (Configuration::is_configured("verbose"))
|
|
cerr
|
|
<< Stock::nb_calibration_requests()
|
|
<< " calibration requests stored, in\n"
|
|
<< Stock::nb_reference_points() << " reference points.\n" ;
|
|
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_reference_points_media()
|
|
{
|
|
const vector<string> &media_names =
|
|
Configuration::string_vector_value("data-input.reference-points-medium") ;
|
|
|
|
for (vector<string>::const_iterator i = media_names.begin() ;
|
|
i != media_names.end() ; ++i)
|
|
{
|
|
if (*i == "CSV")
|
|
initialise_reference_points_csv() ;
|
|
|
|
else
|
|
throw bad_configuration(
|
|
"Reference points input medium type unknown \""+ *i +"\"") ;
|
|
}
|
|
}
|
|
|
|
|
|
void InputDataReader::initialise_reference_points_csv()
|
|
{
|
|
if (! Configuration::is_configured("data-input.reference-points-csv-file"))
|
|
throw missing_configuration(
|
|
"No reference points input CSV file is configured") ;
|
|
|
|
reference_points_media.push_back(
|
|
new InputCSV(
|
|
Configuration::string_value("data-input.reference-points-csv-file"))) ;
|
|
}
|
|
|
|
|
|
void InputDataReader::read_from_reference_points_media()
|
|
{
|
|
for (vector<InputMedium*>::const_iterator i =
|
|
reference_points_media.begin() ;
|
|
i != reference_points_media.end() ; ++i)
|
|
{
|
|
while (! (*i)->eof())
|
|
{
|
|
const Request &request = (*i)->get_next_request() ;
|
|
|
|
if (! request)
|
|
continue ;
|
|
|
|
CalibrationRequest *calibration_request =
|
|
dynamic_cast<CalibrationRequest*>(
|
|
const_cast<Request*>(&request)) ;
|
|
if (calibration_request == NULL)
|
|
cerr << "Warning! Invalid calibration request at line "
|
|
<< (*i)->get_current_line_nb() << endl ;
|
|
else
|
|
Stock::store_calibration_request(*calibration_request) ;
|
|
}
|
|
}
|
|
}
|