diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index 58cdd0c..81c7845 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -35,7 +35,8 @@ TARGET = owlps-positioning OBJ = posutil.o stock.o timestamp.o point3d.o referencepoint.o \ waypoint.o building.o area.o wifidevice.o accesspoint.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) @@ -61,9 +62,10 @@ measurement.o: accesspoint.o calibrationmeasurement.o: measurement.o referencepoint.o request.o: timestamp.o measurement.o inputcsv.o: inputmedium.hh request.o stock.o +input.o: posexcept.o # Specific targets -$(TARGET): $(OBJ) +$(TARGET): $(OBJ) $(OBJ_NOTEST) $(TEST_XX): $(OBJ:%.o=$(TEST_DIR)/%_test.hh) $(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 $< $(TEST_TARGET): $(TEST_OBJ) $(TESTUTIL_OBJ) - $(LD) $(LDFLAGS) -o $@ $^ $(OBJ) + $(LD) $(LDFLAGS) -o $@ $^ $(OBJ) $(OBJ_NOTEST) test: $(TEST_TARGET) @$(TEST_TARGET) @@ -108,8 +110,13 @@ style: @$(STYLE) \ $(OBJ:.o=.hh) \ $(OBJ:.o=.cc) \ + $(OBJ_NOTEST:.o=.hh) \ + $(OBJ_NOTEST:.o=.cc) \ inputmedium.hh \ $(OBJ:%.o=$(TEST_DIR)/%_test.hh) 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 diff --git a/owlps-positioning/TODO b/owlps-positioning/TODO index b4d4516..16ceec1 100644 --- a/owlps-positioning/TODO +++ b/owlps-positioning/TODO @@ -4,6 +4,9 @@ utilisant les champs de direction. ° Lire la direction en tant qu'entier plutôt que float ? +- Input + ° Finir le test unitaire. + - Réorganisation du dépôt ? owlps-positioning/src owlps-positioning/include diff --git a/owlps-positioning/input.cc b/owlps-positioning/input.cc new file mode 100644 index 0000000..a74cb9c --- /dev/null +++ b/owlps-positioning/input.cc @@ -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() ; +} diff --git a/owlps-positioning/input.hh b/owlps-positioning/input.hh new file mode 100644 index 0000000..a43b77a --- /dev/null +++ b/owlps-positioning/input.hh @@ -0,0 +1,29 @@ +#ifndef _OWLPS_POSITIONING_INPUT_HH_ +#define _OWLPS_POSITIONING_INPUT_HH_ + +class InputMedium ; +class Request ; + +#include + +/// 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_ diff --git a/owlps-positioning/posexcept.cc b/owlps-positioning/posexcept.cc new file mode 100644 index 0000000..5f59240 --- /dev/null +++ b/owlps-positioning/posexcept.cc @@ -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!" ; +} diff --git a/owlps-positioning/posexcept.hh b/owlps-positioning/posexcept.hh new file mode 100644 index 0000000..3cd5dce --- /dev/null +++ b/owlps-positioning/posexcept.hh @@ -0,0 +1,40 @@ +#ifndef _OWLPS_POSITIONING_POSEXCEPT_HH_ +#define _OWLPS_POSITIONING_POSEXCEPT_HH_ + +#include +#include + + +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_ diff --git a/owlps-positioning/tests/input_test.hh b/owlps-positioning/tests/input_test.hh new file mode 100644 index 0000000..c361b7e --- /dev/null +++ b/owlps-positioning/tests/input_test.hh @@ -0,0 +1,16 @@ +#include + +#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) ; + } + +} ; diff --git a/owlps-positioning/userinterface.cc b/owlps-positioning/userinterface.cc index 1ec4a68..c58bd33 100644 --- a/owlps-positioning/userinterface.cc +++ b/owlps-positioning/userinterface.cc @@ -68,9 +68,15 @@ void UserInterface::fill_cli_options() void UserInterface::fill_file_options() { file_options->add_options() + // Server options ("server.port,l", po::value() ->default_value(DEFAULT_LISTENING_PORT), "Server listening port") + // Input options + ("input.medium,I", po::value(), + "Medium from which requests are read") + ("input.csv-file,C", po::value(), + "CSV file to use for input (when input.medium = CSV)") ; }