[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.
This commit is contained in:
parent
9ed1000bb3
commit
92e58686f8
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() ;
|
||||
}
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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<PositioningAlgorithm*>::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<string> &algo_names =
|
||||
Configuration::string_vector_value("positioning.algorithm") ;
|
||||
|
||||
for (vector<string>::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<PositioningAlgorithm*>::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) ;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef _OWLPS_POSITIONING_POSITIONING_HH_
|
||||
#define _OWLPS_POSITIONING_POSITIONING_HH_
|
||||
|
||||
class PositioningAlgorithm ;
|
||||
|
||||
#include "input.hh"
|
||||
#include "output.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
/// \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<PositioningAlgorithm*> algorithms ;
|
||||
|
||||
void initialise_algorithms(void) ;
|
||||
void loop(void) ;
|
||||
|
||||
public:
|
||||
Positioning(void) ;
|
||||
~Positioning(void) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_POSITIONING_HH_
|
|
@ -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<string>(),
|
||||
"CSV file to use for logging (when log.medium = CSV).")
|
||||
// Positioning algorithm options
|
||||
("positioning.algorithm,A", po::value< vector<string> >()->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<string> >()->composing(),
|
||||
"Medium to which the results will be wrote. You can specify \
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#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) ;
|
||||
}
|
||||
|
||||
} ;
|
Loading…
Reference in New Issue