[Positioning] Add Input & posexcept.{hh,cc}
- Add files posexcept.{hh,cc} that contains exception classes. - Add class Input, that handles InputMedium (and InputLogMedium, in the future). Note that for the moment, the unit test is *very* minimal. - UserInterface: Add options for the input medium and the CSV file.
This commit is contained in:
parent
0ddef4c747
commit
fc1ceb25c7
|
@ -35,7 +35,8 @@ TARGET = owlps-positioning
|
||||||
OBJ = posutil.o stock.o timestamp.o point3d.o referencepoint.o \
|
OBJ = posutil.o stock.o timestamp.o point3d.o referencepoint.o \
|
||||||
waypoint.o building.o area.o wifidevice.o accesspoint.o \
|
waypoint.o building.o area.o wifidevice.o accesspoint.o \
|
||||||
mobile.o measurement.o calibrationmeasurement.o request.o \
|
mobile.o measurement.o calibrationmeasurement.o request.o \
|
||||||
inputcsv.o configuration.o userinterface.o
|
inputcsv.o configuration.o userinterface.o input.o
|
||||||
|
OBJ_NOTEST = posexcept.o
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
@ -61,9 +62,10 @@ measurement.o: accesspoint.o
|
||||||
calibrationmeasurement.o: measurement.o referencepoint.o
|
calibrationmeasurement.o: measurement.o referencepoint.o
|
||||||
request.o: timestamp.o measurement.o
|
request.o: timestamp.o measurement.o
|
||||||
inputcsv.o: inputmedium.hh request.o stock.o
|
inputcsv.o: inputmedium.hh request.o stock.o
|
||||||
|
input.o: posexcept.o
|
||||||
|
|
||||||
# Specific targets
|
# Specific targets
|
||||||
$(TARGET): $(OBJ)
|
$(TARGET): $(OBJ) $(OBJ_NOTEST)
|
||||||
|
|
||||||
$(TEST_XX): $(OBJ:%.o=$(TEST_DIR)/%_test.hh)
|
$(TEST_XX): $(OBJ:%.o=$(TEST_DIR)/%_test.hh)
|
||||||
$(TEST_DIR)/cxxtestgen.pl --error-printer \
|
$(TEST_DIR)/cxxtestgen.pl --error-printer \
|
||||||
|
@ -78,7 +80,7 @@ $(TESTUTIL_OBJ): $(TESTUTIL_OBJ:.o=.cc) $(TESTUTIL_OBJ:.o=.hh)
|
||||||
$(GXX) $(GXXFLAGS) $(TESTSGXXFLAGS) -o $@ -c $<
|
$(GXX) $(GXXFLAGS) $(TESTSGXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
$(TEST_TARGET): $(TEST_OBJ) $(TESTUTIL_OBJ)
|
$(TEST_TARGET): $(TEST_OBJ) $(TESTUTIL_OBJ)
|
||||||
$(LD) $(LDFLAGS) -o $@ $^ $(OBJ)
|
$(LD) $(LDFLAGS) -o $@ $^ $(OBJ) $(OBJ_NOTEST)
|
||||||
|
|
||||||
test: $(TEST_TARGET)
|
test: $(TEST_TARGET)
|
||||||
@$(TEST_TARGET)
|
@$(TEST_TARGET)
|
||||||
|
@ -108,8 +110,13 @@ style:
|
||||||
@$(STYLE) \
|
@$(STYLE) \
|
||||||
$(OBJ:.o=.hh) \
|
$(OBJ:.o=.hh) \
|
||||||
$(OBJ:.o=.cc) \
|
$(OBJ:.o=.cc) \
|
||||||
|
$(OBJ_NOTEST:.o=.hh) \
|
||||||
|
$(OBJ_NOTEST:.o=.cc) \
|
||||||
inputmedium.hh \
|
inputmedium.hh \
|
||||||
$(OBJ:%.o=$(TEST_DIR)/%_test.hh)
|
$(OBJ:%.o=$(TEST_DIR)/%_test.hh)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
@$(CPPCHECK) $(OBJ:.o=.hh) $(OBJ:.o=.cc) inputmedium.hh
|
@$(CPPCHECK) \
|
||||||
|
$(OBJ:.o=.hh) $(OBJ:.o=.cc) \
|
||||||
|
$(OBJ_NOTEST:.o=.hh) $(OBJ_NOTEST:.o=.cc) \
|
||||||
|
inputmedium.hh
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
utilisant les champs de direction.
|
utilisant les champs de direction.
|
||||||
° Lire la direction en tant qu'entier plutôt que float ?
|
° Lire la direction en tant qu'entier plutôt que float ?
|
||||||
|
|
||||||
|
- Input
|
||||||
|
° Finir le test unitaire.
|
||||||
|
|
||||||
- Réorganisation du dépôt ?
|
- Réorganisation du dépôt ?
|
||||||
owlps-positioning/src
|
owlps-positioning/src
|
||||||
owlps-positioning/include
|
owlps-positioning/include
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include "input.hh"
|
||||||
|
#include "inputcsv.hh"
|
||||||
|
#include "request.hh"
|
||||||
|
#include "configuration.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
|
|
||||||
|
using namespace std ;
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Constructors *** */
|
||||||
|
|
||||||
|
|
||||||
|
Input::Input()
|
||||||
|
{
|
||||||
|
medium = NULL ;
|
||||||
|
initialise_input_medium() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Input::~Input()
|
||||||
|
{
|
||||||
|
delete medium ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Operations *** */
|
||||||
|
|
||||||
|
|
||||||
|
void Input::initialise_input_medium()
|
||||||
|
{
|
||||||
|
if (! Configuration::is_configured("input.medium"))
|
||||||
|
throw no_input_medium() ;
|
||||||
|
|
||||||
|
const string &medium_name =
|
||||||
|
Configuration::get_string_value("input.medium") ;
|
||||||
|
|
||||||
|
if (medium_name == "CSV")
|
||||||
|
{
|
||||||
|
if (! Configuration::is_configured("input.csv-file"))
|
||||||
|
throw no_input_csv_file() ;
|
||||||
|
medium = new
|
||||||
|
InputCSV(Configuration::get_string_value("input.csv-file")) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
throw input_medium_type_unknown(medium_name) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Request& Input::get_next_request() const
|
||||||
|
{
|
||||||
|
if (medium == NULL)
|
||||||
|
throw null_input_medium() ;
|
||||||
|
return medium->get_next_request() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Input::eof() const
|
||||||
|
{
|
||||||
|
if (medium == NULL)
|
||||||
|
throw null_input_medium() ;
|
||||||
|
return medium->eof() ;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef _OWLPS_POSITIONING_INPUT_HH_
|
||||||
|
#define _OWLPS_POSITIONING_INPUT_HH_
|
||||||
|
|
||||||
|
class InputMedium ;
|
||||||
|
class Request ;
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/// Handles the inputs
|
||||||
|
class Input
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
InputMedium *medium ; ///< Input medium used
|
||||||
|
|
||||||
|
void initialise_input_medium(void) ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Input(void) ;
|
||||||
|
|
||||||
|
~Input(void) ;
|
||||||
|
|
||||||
|
/** @name Operations */
|
||||||
|
//@{
|
||||||
|
const Request& get_next_request(void) const ;
|
||||||
|
bool eof(void) const ;
|
||||||
|
//@}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#endif // _OWLPS_POSITIONING_INPUT_HH_
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include "posexcept.hh"
|
||||||
|
|
||||||
|
using namespace std ;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param _medium_name The medium that is unknown
|
||||||
|
*/
|
||||||
|
input_medium_type_unknown::
|
||||||
|
input_medium_type_unknown(const string &_medium_name) throw()
|
||||||
|
{
|
||||||
|
medium_name = _medium_name ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* input_medium_type_unknown::what() const throw()
|
||||||
|
{
|
||||||
|
string message = "The specified input medium « "+ medium_name +
|
||||||
|
" » is unknown!" ;
|
||||||
|
return message.c_str() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* no_input_medium::what() const throw()
|
||||||
|
{
|
||||||
|
return "No input medium specified in configuration!" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* null_input_medium::what() const throw()
|
||||||
|
{
|
||||||
|
return "The input medium is not initialised!" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* no_input_csv_file::what() const throw()
|
||||||
|
{
|
||||||
|
return "No input CSV file specified in the configuration!" ;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef _OWLPS_POSITIONING_POSEXCEPT_HH_
|
||||||
|
#define _OWLPS_POSITIONING_POSEXCEPT_HH_
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
class input_medium_type_unknown: public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::string medium_name ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
input_medium_type_unknown(const std::string &_medium_name) throw() ;
|
||||||
|
~input_medium_type_unknown(void) throw() {}
|
||||||
|
const char* what(void) const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
class no_input_medium: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const char* what() const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
class null_input_medium: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const char* what() const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
class no_input_csv_file: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const char* what() const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#endif // _OWLPS_POSITIONING_POSEXCEPT_HH_
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include <cxxtest/TestSuite.h>
|
||||||
|
|
||||||
|
#include "input.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
|
|
||||||
|
class Input_test: public CxxTest::TestSuite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
void test_constructor(void)
|
||||||
|
{
|
||||||
|
// TODO: test with a mock Configuration?
|
||||||
|
TS_ASSERT_THROWS(Input input1, no_input_medium) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
} ;
|
|
@ -68,9 +68,15 @@ void UserInterface::fill_cli_options()
|
||||||
void UserInterface::fill_file_options()
|
void UserInterface::fill_file_options()
|
||||||
{
|
{
|
||||||
file_options->add_options()
|
file_options->add_options()
|
||||||
|
// Server options
|
||||||
("server.port,l", po::value<int>()
|
("server.port,l", po::value<int>()
|
||||||
->default_value(DEFAULT_LISTENING_PORT),
|
->default_value(DEFAULT_LISTENING_PORT),
|
||||||
"Server listening port")
|
"Server listening port")
|
||||||
|
// Input options
|
||||||
|
("input.medium,I", po::value<string>(),
|
||||||
|
"Medium from which requests are read")
|
||||||
|
("input.csv-file,C", po::value<string>(),
|
||||||
|
"CSV file to use for input (when input.medium = CSV)")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue