[Positioning] Revue code Julien
Début de revue du code de Julien sur owlps-positioning : * Cosmétique. * owlps-positioning.cc, server.cc : correction/amélioration de la gestion des arguments. * Fichiers de config : suppression de cfg/config.cfg et déplacement-renommage de ./owlps-positioning.cfg dans cfg/owlps-positioning.conf. * Makefile : passage de Boost 1.35 à 1.38, l'option -lboost_program_options devient -lboost_program_options-mt. git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@101 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
e0d3e07e11
commit
d619b621ff
|
@ -16,7 +16,7 @@ DEBUG = -g
|
|||
GXXFLAGS = $(DEBUG) -Wall -pedantic
|
||||
LD = g++
|
||||
LDFLAGS = -lm
|
||||
LIBS = -lpq -lboost_program_options
|
||||
LIBS = -lpq -lboost_program_options-mt
|
||||
|
||||
TARGET = owlps-positioning
|
||||
HEADER = owlps-positioning.hh
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[Server]
|
||||
[server]
|
||||
port = 9902
|
||||
mobile-port = 9903
|
||||
|
||||
[BDD]
|
||||
[db]
|
||||
name = owlps_db
|
||||
hostaddr = 127.0.0.1
|
||||
user = owlps
|
||||
host = 172.20.105.4
|
||||
user = jgraeffly
|
||||
passwd = owlps
|
|
@ -11,7 +11,6 @@ float round_float(float f, int n)
|
|||
|
||||
vector<string> explode(const string &input, const char &sep)
|
||||
{
|
||||
|
||||
vector<string> vs;
|
||||
string tmp;
|
||||
unsigned int i;
|
||||
|
@ -95,4 +94,3 @@ uint64_t timeval_to_ms(const struct timeval &d)
|
|||
{
|
||||
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,60 +2,61 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
po::options_description desc("Options");
|
||||
po::options_description conf("Configuration Positioner");
|
||||
po::options_description opt("Aide");
|
||||
po::variables_map vm;
|
||||
|
||||
string file = DEFAULT_CONFIG_FILE;
|
||||
string config_filename = DEFAULT_CONFIG_FILE;
|
||||
int port, mport;
|
||||
|
||||
desc.add_options()
|
||||
("help", "\t: Affichage de l'aide")
|
||||
("file-conf,F", po::value<string>(), "\t: Fichier de configuration")
|
||||
("input-topo,T", po::value<string>(), "\t: Input file topology")
|
||||
("input-waypoint,W", po::value<string>(), "\t: Input file waypoint")
|
||||
("input-refpoint,R", po::value<string>(), "\t: Input file reference point")
|
||||
("input-ap,A", po::value<string>(), "\t: Input file accesspoint")
|
||||
|
||||
/* Options spécifiques à la ligne de commandes */
|
||||
po::options_description generic("Options générales ");
|
||||
generic.add_options()
|
||||
("help,h", "Affichage de l'aide")
|
||||
("config-file,f", po::value<string>(), "Fichier de configuration")
|
||||
("input-topo,T", po::value<string>(), "Input file topology")
|
||||
("input-waypoint,W", po::value<string>(), "Input file waypoint")
|
||||
("input-refpoint,R", po::value<string>(), "Input file reference point")
|
||||
("input-ap,A", po::value<string>(), "Input file accesspoint")
|
||||
;
|
||||
|
||||
conf.add_options()
|
||||
("Server.port", po::value<int>(&port) -> default_value(9902), "\t: Port du serveur")
|
||||
("Server.mobile-port", po::value<int>(&mport) -> default_value(9903), "\t: Port d'envoi vers le mobile")
|
||||
("BDD.name", po::value<string>(), "\t: Nom de la BdD")
|
||||
("BDD.hostaddr", po::value<string>(), "\t: Adresse de l'hôte de la BdD")
|
||||
("BDD.user", po::value<string>(), "\t: Nom de l'utilisateur de la BdD")
|
||||
("BDD.passwd", po::value<string>(), "\t: Mot de passe de la BdD")
|
||||
/* Options ligne de commandes & fichier de configuration */
|
||||
po::options_description config("Paramètres ");
|
||||
config.add_options()
|
||||
("server.port,l", po::value<int>(&port) -> default_value(9902), "Port d'écoute du serveur")
|
||||
("server.mobile-port,p", po::value<int>(&mport) -> default_value(9903), "Port d'envoi vers le mobile")
|
||||
("db.name,D", po::value<string>(), "Nom de la base de données à utiliser")
|
||||
("db.host,H", po::value<string>(), "Adresse de l'hôte hébergeant la base de données")
|
||||
("db.user,U", po::value<string>(), "Nom de l'utilisateur pour la connexion à la base de données")
|
||||
("db.passwd,P", po::value<string>(), "Mot de passe pour la connexion à la base de données")
|
||||
;
|
||||
|
||||
opt.add(desc).add(conf);
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
/* Total des options acceptées en ligne de commandes */
|
||||
po::options_description cmd_line_options("Options acceptées ") ;
|
||||
cmd_line_options.add(generic).add(config) ;
|
||||
|
||||
if (vm.count("file-conf"))
|
||||
file = vm["file-conf"].as<string>();
|
||||
/* Parcours de la ligne de commandes */
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, cmd_line_options), vm) ;
|
||||
|
||||
ifstream ifs(file.c_str());
|
||||
if (vm.count("help")) // L'utilisateur a demandé l'aide
|
||||
{
|
||||
cout << cmd_line_options << endl ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
if (vm.count("config-file")) // L'utilisateur a spécifié un fichier de config
|
||||
config_filename = vm["file-conf"].as<string>() ;
|
||||
|
||||
ifstream ifs(config_filename.c_str());
|
||||
if (!ifs.is_open())
|
||||
{
|
||||
cerr << "Erreur lors de la lecture du fichier ! Le fichier n'existe pas ou ne peut être lu.\nUtilisation des valeurs par défaut..." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
po::store(po::parse_config_file(ifs, conf), vm);
|
||||
}
|
||||
po::notify(vm);
|
||||
cerr << "Attention ! Erreur lors de l'ouverture du fichier de configuration « " << config_filename << " » : le fichier n'existe pas ou ne peut être lu.\nUtilisation des valeurs par défaut..." << endl ;
|
||||
else // Parcours du fichier de config
|
||||
po::store(po::parse_config_file(ifs, config), vm) ;
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
cout << opt << endl;
|
||||
return 0;
|
||||
}
|
||||
po::notify(vm);
|
||||
|
||||
Server server(port, mport);
|
||||
|
||||
if (server.init(vm)) return 1;
|
||||
if (server.init(vm))
|
||||
return 1 ;
|
||||
|
||||
server.start();
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
[Server]
|
||||
port = 9902
|
||||
mobile-port = 9903
|
||||
|
||||
[BDD]
|
||||
name = owlps_db
|
||||
hostaddr = 127.0.0.1
|
||||
user = julien
|
||||
passwd = 10,mamci
|
|
@ -11,4 +11,4 @@
|
|||
using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
|
||||
#endif
|
||||
#endif // _OWLPS_HH_
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
class Positioning
|
||||
{
|
||||
|
||||
private:
|
||||
vector<ReferencePoint> reference_point_list; // Liste des points de référence (calibration).
|
||||
float** reference_point_matrix; // Matrice des distances entre les points de référence.
|
||||
|
@ -20,7 +19,6 @@ class Positioning
|
|||
map<string, Area> area_list ; // Liste des zones homogènes (pièces).
|
||||
|
||||
public :
|
||||
|
||||
Positioning() {};
|
||||
~Positioning() {};
|
||||
|
||||
|
@ -72,4 +70,4 @@ class Positioning
|
|||
void printAreatList();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _POSITIONING_HH_
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "server.hh"
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T from_string(const string &s)
|
||||
{
|
||||
|
@ -12,6 +14,8 @@ inline T from_string(const string &s)
|
|||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Server::init(const boost::program_options::variables_map vm)
|
||||
{
|
||||
|
||||
|
@ -19,28 +23,40 @@ int Server::init(const boost::program_options::variables_map vm)
|
|||
string buf;
|
||||
|
||||
oss << "hostaddr = '";
|
||||
if (vm.count("BDD.hostaddr"))
|
||||
oss << vm["BDD.hostaddr"].as<string>();
|
||||
if (vm.count("db.host"))
|
||||
oss << vm["db.host"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_HOST;
|
||||
{
|
||||
cerr << "Attention ! Hôte de la BDD non spécifié, utilisation de la valeur par défaut..." << endl ;
|
||||
oss << DEFAULT_BDD_HOST;
|
||||
}
|
||||
|
||||
oss << "' dbname = '";
|
||||
if (vm.count("BDD.name"))
|
||||
oss << vm["BDD.name"].as<string>();
|
||||
if (vm.count("db.name"))
|
||||
oss << vm["db.name"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_NAME;
|
||||
{
|
||||
cerr << "Attention ! Nom de la BDD non spécifié, utilisation de la valeur par défaut..." << endl ;
|
||||
oss << DEFAULT_BDD_NAME;
|
||||
}
|
||||
|
||||
oss << "' user = '";
|
||||
if (vm.count("BDD.user"))
|
||||
oss << vm["BDD.user"].as<string>();
|
||||
if (vm.count("db.user"))
|
||||
oss << vm["db.user"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_USER;
|
||||
{
|
||||
cerr << "Attention ! Utilisateur non spécifié pour la connexion à la BDD, utilisation de la valeur par défaut..." << endl ;
|
||||
oss << DEFAULT_BDD_USER;
|
||||
}
|
||||
|
||||
oss << "' password = '";
|
||||
if (vm.count("BDD.passwd"))
|
||||
oss << vm["BDD.passwd"].as<string>() << "'";
|
||||
if (vm.count("db.passwd"))
|
||||
oss << vm["db.passwd"].as<string>() << "'";
|
||||
else
|
||||
oss << DEFAULT_BDD_PASS << "'";
|
||||
{
|
||||
cerr << "Attention ! Mot de passe non spécifié pour la connexion à la BDD, utilisation de la valeur par défaut..." << endl ;
|
||||
oss << DEFAULT_BDD_PASS << "'";
|
||||
}
|
||||
|
||||
buf = oss.str();
|
||||
|
||||
|
@ -49,7 +65,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
|||
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
{
|
||||
cout << "Connection à la base de donnée échouée: " << PQerrorMessage(conn) << endl;
|
||||
cout << "Erreur ! Connexion à la base de donnée échouée : " << PQerrorMessage(conn) << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -64,21 +80,22 @@ int Server::init(const boost::program_options::variables_map vm)
|
|||
|
||||
if (!pos.checkTopology())
|
||||
{
|
||||
cerr << "Erreur lors de la création de la topology" << endl;
|
||||
cerr << "Erreur lors de la création de la topologie !" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
pos.makeReferencePointDistances();
|
||||
|
||||
if (vm.count("input-ap")) pos.makeApListFromFile(vm["input-ap"].as<string>());
|
||||
else pos.makeApListFromDb(conn);
|
||||
if (vm.count("input-ap"))
|
||||
pos.makeApListFromFile(vm["input-ap"].as<string>()) ;
|
||||
else
|
||||
pos.makeApListFromDb(conn) ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Server::start()
|
||||
{
|
||||
|
||||
struct sockaddr_in serv_addr;
|
||||
struct sockaddr_in client;
|
||||
socklen_t client_len = sizeof(client);
|
||||
|
@ -138,9 +155,10 @@ int Server::start()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Server::treatment()
|
||||
{
|
||||
|
||||
Point solution;
|
||||
|
||||
int id_request;
|
||||
|
@ -198,6 +216,8 @@ void Server::treatment()
|
|||
free(mac);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Server::createResult(Point solution, int id_request, string use_algo)
|
||||
{
|
||||
|
||||
|
@ -228,9 +248,10 @@ void Server::createResult(Point solution, int id_request, string use_algo)
|
|||
PQclear(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Server::sendToClient(Point solution, char *mac)
|
||||
{
|
||||
|
||||
int sockfd ; // Descripteur de la socket
|
||||
struct sockaddr_in serv;
|
||||
struct sockaddr_in mobile;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
class Treatment
|
||||
{
|
||||
|
||||
private:
|
||||
vector<AccessPoint> access_point_list;
|
||||
vector<ReferencePoint> reference_point_list;
|
||||
|
@ -43,4 +42,4 @@ class Treatment
|
|||
Point getkWeightedInSs(const unsigned int &k, const Point *point_ignored)const ;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _TREATMENT_HH_
|
||||
|
|
Loading…
Reference in New Issue