[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
|
GXXFLAGS = $(DEBUG) -Wall -pedantic
|
||||||
LD = g++
|
LD = g++
|
||||||
LDFLAGS = -lm
|
LDFLAGS = -lm
|
||||||
LIBS = -lpq -lboost_program_options
|
LIBS = -lpq -lboost_program_options-mt
|
||||||
|
|
||||||
TARGET = owlps-positioning
|
TARGET = owlps-positioning
|
||||||
HEADER = owlps-positioning.hh
|
HEADER = owlps-positioning.hh
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[Server]
|
[server]
|
||||||
port = 9902
|
port = 9902
|
||||||
mobile-port = 9903
|
mobile-port = 9903
|
||||||
|
|
||||||
[BDD]
|
[db]
|
||||||
name = owlps_db
|
name = owlps_db
|
||||||
hostaddr = 127.0.0.1
|
host = 172.20.105.4
|
||||||
user = owlps
|
user = jgraeffly
|
||||||
passwd = owlps
|
passwd = owlps
|
|
@ -11,7 +11,6 @@ float round_float(float f, int n)
|
||||||
|
|
||||||
vector<string> explode(const string &input, const char &sep)
|
vector<string> explode(const string &input, const char &sep)
|
||||||
{
|
{
|
||||||
|
|
||||||
vector<string> vs;
|
vector<string> vs;
|
||||||
string tmp;
|
string tmp;
|
||||||
unsigned int i;
|
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 ;
|
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,60 +2,61 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
string config_filename = DEFAULT_CONFIG_FILE;
|
||||||
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;
|
|
||||||
int port, mport;
|
int port, mport;
|
||||||
|
|
||||||
desc.add_options()
|
|
||||||
("help", "\t: Affichage de l'aide")
|
/* Options spécifiques à la ligne de commandes */
|
||||||
("file-conf,F", po::value<string>(), "\t: Fichier de configuration")
|
po::options_description generic("Options générales ");
|
||||||
("input-topo,T", po::value<string>(), "\t: Input file topology")
|
generic.add_options()
|
||||||
("input-waypoint,W", po::value<string>(), "\t: Input file waypoint")
|
("help,h", "Affichage de l'aide")
|
||||||
("input-refpoint,R", po::value<string>(), "\t: Input file reference point")
|
("config-file,f", po::value<string>(), "Fichier de configuration")
|
||||||
("input-ap,A", po::value<string>(), "\t: Input file accesspoint")
|
("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()
|
/* Options ligne de commandes & fichier de configuration */
|
||||||
("Server.port", po::value<int>(&port) -> default_value(9902), "\t: Port du serveur")
|
po::options_description config("Paramètres ");
|
||||||
("Server.mobile-port", po::value<int>(&mport) -> default_value(9903), "\t: Port d'envoi vers le mobile")
|
config.add_options()
|
||||||
("BDD.name", po::value<string>(), "\t: Nom de la BdD")
|
("server.port,l", po::value<int>(&port) -> default_value(9902), "Port d'écoute du serveur")
|
||||||
("BDD.hostaddr", po::value<string>(), "\t: Adresse de l'hôte de la BdD")
|
("server.mobile-port,p", po::value<int>(&mport) -> default_value(9903), "Port d'envoi vers le mobile")
|
||||||
("BDD.user", po::value<string>(), "\t: Nom de l'utilisateur de la BdD")
|
("db.name,D", po::value<string>(), "Nom de la base de données à utiliser")
|
||||||
("BDD.passwd", po::value<string>(), "\t: Mot de passe de la BdD")
|
("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);
|
/* Total des options acceptées en ligne de commandes */
|
||||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
po::options_description cmd_line_options("Options acceptées ") ;
|
||||||
|
cmd_line_options.add(generic).add(config) ;
|
||||||
|
|
||||||
if (vm.count("file-conf"))
|
/* Parcours de la ligne de commandes */
|
||||||
file = vm["file-conf"].as<string>();
|
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
|
||||||
|
|
||||||
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;
|
cout << cmd_line_options << endl ;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
po::store(po::parse_config_file(ifs, conf), vm);
|
|
||||||
}
|
|
||||||
po::notify(vm);
|
|
||||||
|
|
||||||
if (vm.count("help"))
|
|
||||||
{
|
|
||||||
cout << opt << endl;
|
|
||||||
return 0 ;
|
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 << "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) ;
|
||||||
|
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
Server server(port, mport);
|
Server server(port, mport);
|
||||||
|
|
||||||
if (server.init(vm)) return 1;
|
if (server.init(vm))
|
||||||
|
return 1 ;
|
||||||
|
|
||||||
server.start();
|
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;
|
using namespace std;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
#endif
|
#endif // _OWLPS_HH_
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
class Positioning
|
class Positioning
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<ReferencePoint> reference_point_list; // Liste des points de référence (calibration).
|
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.
|
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).
|
map<string, Area> area_list ; // Liste des zones homogènes (pièces).
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
Positioning() {};
|
Positioning() {};
|
||||||
~Positioning() {};
|
~Positioning() {};
|
||||||
|
|
||||||
|
@ -72,4 +70,4 @@ class Positioning
|
||||||
void printAreatList();
|
void printAreatList();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _POSITIONING_HH_
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "server.hh"
|
#include "server.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T from_string(const string &s)
|
inline T from_string(const string &s)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +14,8 @@ inline T from_string(const string &s)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Server::init(const boost::program_options::variables_map vm)
|
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;
|
string buf;
|
||||||
|
|
||||||
oss << "hostaddr = '";
|
oss << "hostaddr = '";
|
||||||
if (vm.count("BDD.hostaddr"))
|
if (vm.count("db.host"))
|
||||||
oss << vm["BDD.hostaddr"].as<string>();
|
oss << vm["db.host"].as<string>();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
cerr << "Attention ! Hôte de la BDD non spécifié, utilisation de la valeur par défaut..." << endl ;
|
||||||
oss << DEFAULT_BDD_HOST;
|
oss << DEFAULT_BDD_HOST;
|
||||||
|
}
|
||||||
|
|
||||||
oss << "' dbname = '";
|
oss << "' dbname = '";
|
||||||
if (vm.count("BDD.name"))
|
if (vm.count("db.name"))
|
||||||
oss << vm["BDD.name"].as<string>();
|
oss << vm["db.name"].as<string>();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
cerr << "Attention ! Nom de la BDD non spécifié, utilisation de la valeur par défaut..." << endl ;
|
||||||
oss << DEFAULT_BDD_NAME;
|
oss << DEFAULT_BDD_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
oss << "' user = '";
|
oss << "' user = '";
|
||||||
if (vm.count("BDD.user"))
|
if (vm.count("db.user"))
|
||||||
oss << vm["BDD.user"].as<string>();
|
oss << vm["db.user"].as<string>();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
cerr << "Attention ! Utilisateur non spécifié pour la connexion à la BDD, utilisation de la valeur par défaut..." << endl ;
|
||||||
oss << DEFAULT_BDD_USER;
|
oss << DEFAULT_BDD_USER;
|
||||||
|
}
|
||||||
|
|
||||||
oss << "' password = '";
|
oss << "' password = '";
|
||||||
if (vm.count("BDD.passwd"))
|
if (vm.count("db.passwd"))
|
||||||
oss << vm["BDD.passwd"].as<string>() << "'";
|
oss << vm["db.passwd"].as<string>() << "'";
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
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 << "'";
|
oss << DEFAULT_BDD_PASS << "'";
|
||||||
|
}
|
||||||
|
|
||||||
buf = oss.str();
|
buf = oss.str();
|
||||||
|
|
||||||
|
@ -49,7 +65,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
|
|
||||||
if (PQstatus(conn) != CONNECTION_OK)
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,21 +80,22 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
|
|
||||||
if (!pos.checkTopology())
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.makeReferencePointDistances();
|
pos.makeReferencePointDistances();
|
||||||
|
|
||||||
if (vm.count("input-ap")) pos.makeApListFromFile(vm["input-ap"].as<string>());
|
if (vm.count("input-ap"))
|
||||||
else pos.makeApListFromDb(conn);
|
pos.makeApListFromFile(vm["input-ap"].as<string>()) ;
|
||||||
|
else
|
||||||
|
pos.makeApListFromDb(conn) ;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::start()
|
int Server::start()
|
||||||
{
|
{
|
||||||
|
|
||||||
struct sockaddr_in serv_addr;
|
struct sockaddr_in serv_addr;
|
||||||
struct sockaddr_in client;
|
struct sockaddr_in client;
|
||||||
socklen_t client_len = sizeof(client);
|
socklen_t client_len = sizeof(client);
|
||||||
|
@ -138,9 +155,10 @@ int Server::start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Server::treatment()
|
void Server::treatment()
|
||||||
{
|
{
|
||||||
|
|
||||||
Point solution;
|
Point solution;
|
||||||
|
|
||||||
int id_request;
|
int id_request;
|
||||||
|
@ -198,6 +216,8 @@ void Server::treatment()
|
||||||
free(mac);
|
free(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Server::createResult(Point solution, int id_request, string use_algo)
|
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);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Server::sendToClient(Point solution, char *mac)
|
void Server::sendToClient(Point solution, char *mac)
|
||||||
{
|
{
|
||||||
|
|
||||||
int sockfd ; // Descripteur de la socket
|
int sockfd ; // Descripteur de la socket
|
||||||
struct sockaddr_in serv;
|
struct sockaddr_in serv;
|
||||||
struct sockaddr_in mobile;
|
struct sockaddr_in mobile;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
class Treatment
|
class Treatment
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<AccessPoint> access_point_list;
|
vector<AccessPoint> access_point_list;
|
||||||
vector<ReferencePoint> reference_point_list;
|
vector<ReferencePoint> reference_point_list;
|
||||||
|
@ -43,4 +42,4 @@ class Treatment
|
||||||
Point getkWeightedInSs(const unsigned int &k, const Point *point_ignored)const ;
|
Point getkWeightedInSs(const unsigned int &k, const Point *point_ignored)const ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _TREATMENT_HH_
|
||||||
|
|
Loading…
Reference in New Issue