From 92e58686f8b091a1989acb17197d42321e5bd702 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 4 Mar 2010 17:51:44 +0100 Subject: [PATCH] [Positioning] Add class Positioning The new class Positioning is the interface between Input and Output, using positioning algorithms to compute results from requests. Update UserInterface to add option "positioning.algorithm"; update posexcept. --- owlps-positioning/Makefile | 7 +++ owlps-positioning/TODO | 1 + owlps-positioning/src/posexcept.cc | 26 ++++++++ owlps-positioning/src/posexcept.hh | 23 +++++++ owlps-positioning/src/positioning.cc | 67 +++++++++++++++++++++ owlps-positioning/src/positioning.hh | 29 +++++++++ owlps-positioning/src/userinterface.cc | 5 +- owlps-positioning/tests/positioning_test.hh | 15 +++++ 8 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 owlps-positioning/src/positioning.cc create mode 100644 owlps-positioning/src/positioning.hh create mode 100644 owlps-positioning/tests/positioning_test.hh diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index f0384ec..61a4cb1 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -57,6 +57,7 @@ OBJ_LIST = \ userinterface.o \ output.o \ outputterminal.o \ + positioning.o \ input.o \ inputcsv.o \ inputlogcsv.o @@ -153,6 +154,12 @@ realposition.o: \ $(OBJ_DIR)/result.o \ $(OBJ_DIR)/calibrationrequest.o \ $(OBJ_DIR)/referencepoint.o +positioning.o: \ + $(OBJ_DIR)/input.o \ + $(OBJ_DIR)/realposition.o \ + $(OBJ_DIR)/output.o \ + $(OBJ_DIR)/configuration.o \ + $(OBJ_DIR)/posexcept.o # Specific targets $(TARGET): $(OBJ) $(OBJ_NOTEST) $(OBJ_TARGET) diff --git a/owlps-positioning/TODO b/owlps-positioning/TODO index a138b9b..a964aba 100644 --- a/owlps-positioning/TODO +++ b/owlps-positioning/TODO @@ -4,6 +4,7 @@ tester operator!=() au lieu de !operator==(). ° Finir le test de Input. ° Finir le test de Output. + ° Finir le test de Positioning. - PosUtil ° Déplacer les #define des canaux Wi-Fi dans le .cc diff --git a/owlps-positioning/src/posexcept.cc b/owlps-positioning/src/posexcept.cc index dd6352a..44dbead 100644 --- a/owlps-positioning/src/posexcept.cc +++ b/owlps-positioning/src/posexcept.cc @@ -108,3 +108,29 @@ const char* output_medium_type_unknown::what() const throw() " » is unknown!" ; return message.c_str() ; } + + + +/* *** Algorithms *** */ + + +const char* no_positioning_algorithm::what() const throw() +{ + return "No positioning algorithm specified in configuration!" ; +} + + +/** + * @param _algo_name The algo that is unknown + */ +positioning_algorithm_unknown:: +positioning_algorithm_unknown(const string &_algo_name) throw(): + algo_name(_algo_name) {} + + +const char* positioning_algorithm_unknown::what() const throw() +{ + string message = "The specified positioning_algorithm « "+ algo_name + + " » is unknown!" ; + return message.c_str() ; +} diff --git a/owlps-positioning/src/posexcept.hh b/owlps-positioning/src/posexcept.hh index 2329217..7926b93 100644 --- a/owlps-positioning/src/posexcept.hh +++ b/owlps-positioning/src/posexcept.hh @@ -101,4 +101,27 @@ public: +/* *** Algorithms *** */ + + +class no_positioning_algorithm: public std::exception +{ +public: + const char* what() const throw() ; +} ; + + +class positioning_algorithm_unknown: public std::exception +{ +private: + std::string algo_name ; + +public: + positioning_algorithm_unknown(const std::string &_algo_name) throw() ; + ~positioning_algorithm_unknown(void) throw() {} + const char* what(void) const throw() ; +} ; + + + #endif // _OWLPS_POSITIONING_POSEXCEPT_HH_ diff --git a/owlps-positioning/src/positioning.cc b/owlps-positioning/src/positioning.cc new file mode 100644 index 0000000..b41e9ce --- /dev/null +++ b/owlps-positioning/src/positioning.cc @@ -0,0 +1,67 @@ +#include "positioning.hh" +#include "realposition.hh" +#include "configuration.hh" +#include "posexcept.hh" + +using namespace std ; + + + +/* *** Constructors *** */ + + +Positioning::Positioning() +{ + initialise_algorithms() ; + loop() ; +} + + +Positioning::~Positioning() +{ + for (vector::const_iterator i = + algorithms.begin() ; i != algorithms.end() ; ++i) + delete *i ; + algorithms.clear() ; +} + + + +/* *** Operations *** */ + + +void Positioning::initialise_algorithms() +{ + if (! Configuration::is_configured("positioning.algorithm")) + throw no_positioning_algorithm() ; + + const vector &algo_names = + Configuration::string_vector_value("positioning.algorithm") ; + + for (vector::const_iterator i = algo_names.begin() ; + i != algo_names.end() ; ++i) + { + if (*i == "Real") + algorithms.push_back(new RealPosition) ; + + else + throw positioning_algorithm_unknown(*i) ; + } +} + + +void Positioning::loop() +{ + vector::const_iterator algo ; + + while (! input.eof()) + { + const Request &request = input.get_next_request() ; + for (algo = algorithms.begin() ; algo != algorithms.end() ; + ++algo) + { + Result res = (*algo)->compute(request) ; + output.write(res) ; + } + } +} diff --git a/owlps-positioning/src/positioning.hh b/owlps-positioning/src/positioning.hh new file mode 100644 index 0000000..fc7b685 --- /dev/null +++ b/owlps-positioning/src/positioning.hh @@ -0,0 +1,29 @@ +#ifndef _OWLPS_POSITIONING_POSITIONING_HH_ +#define _OWLPS_POSITIONING_POSITIONING_HH_ + +class PositioningAlgorithm ; + +#include "input.hh" +#include "output.hh" + +#include + +/// \brief Computes \link Result results \endlink from \link Request +/// requests \endlink using one or more \link PositioningAlgorithm +/// positioning algorithms \endlink +class Positioning +{ +protected: + Input input ; + Output output ; + std::vector algorithms ; + + void initialise_algorithms(void) ; + void loop(void) ; + +public: + Positioning(void) ; + ~Positioning(void) ; +} ; + +#endif // _OWLPS_POSITIONING_POSITIONING_HH_ diff --git a/owlps-positioning/src/userinterface.cc b/owlps-positioning/src/userinterface.cc index 2b64731..cc45a97 100644 --- a/owlps-positioning/src/userinterface.cc +++ b/owlps-positioning/src/userinterface.cc @@ -37,7 +37,6 @@ UserInterface::UserInterface(const int argc, char **argv) } fill_options() ; - parse_options() ; } @@ -92,6 +91,10 @@ this option more than once. Allowed: none, CSV. The `none` value \ completely disables logging.") ("log.csv-file", po::value(), "CSV file to use for logging (when log.medium = CSV).") + // Positioning algorithm options + ("positioning.algorithm,A", po::value< vector >()->composing(), + "Algorithms used to compute positions. You can specify \ +this option more than once (but at least once). Allowed: Real.") // Output options ("output.medium,O", po::value< vector >()->composing(), "Medium to which the results will be wrote. You can specify \ diff --git a/owlps-positioning/tests/positioning_test.hh b/owlps-positioning/tests/positioning_test.hh new file mode 100644 index 0000000..22e68d1 --- /dev/null +++ b/owlps-positioning/tests/positioning_test.hh @@ -0,0 +1,15 @@ +#include + +#include "positioning.hh" + +class Positioning_test: public CxxTest::TestSuite +{ +public: + + void test_constructor(void) + { + // TODO: test with a mock Configuration + TS_ASSERT_THROWS_ANYTHING(Positioning positioning1) ; + } + +} ;