2010-02-11 17:24:21 +01:00
|
|
|
#include "input.hh"
|
|
|
|
#include "inputcsv.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
|
|
|
|
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"))
|
|
|
|
throw no_input_medium() ;
|
|
|
|
|
|
|
|
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"))
|
|
|
|
throw no_input_csv_file() ;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
throw input_medium_type_unknown(medium_name) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
throw input_medium_type_unknown(*i) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Input::initialise_log_csv()
|
|
|
|
{
|
|
|
|
if (! Configuration::is_configured("log.csv-file"))
|
|
|
|
throw no_log_csv_file() ;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2010-02-16 16:19:39 +01:00
|
|
|
if (! eof())
|
|
|
|
{
|
2010-02-19 11:42:04 +01:00
|
|
|
const Request &request = medium->get_next_request() ;
|
|
|
|
add_request_to_stock(request) ;
|
2010-02-16 16:19:39 +01:00
|
|
|
log_current_request() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2010-02-19 11:42:04 +01:00
|
|
|
void Input::add_request_to_stock(const Request &request) const
|
|
|
|
{
|
|
|
|
// For the moment we add only the CalibrationRequests to the Stock
|
|
|
|
const CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<const CalibrationRequest*>(&request) ;
|
|
|
|
if (calibration_request == NULL)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
// Add request to the Stock
|
|
|
|
const CalibrationRequest &stock_calibration_request =
|
|
|
|
Stock::find_create_calibration_request(*calibration_request) ;
|
|
|
|
|
|
|
|
// Add the request to the request list of its reference point
|
|
|
|
stock_calibration_request.reference_point_backward_link() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()) ;
|
|
|
|
}
|