[done] Managing ONLINE/OFFLINE status for planes deconnected
This commit is contained in:
parent
b96e89bddb
commit
e2fe1a7155
|
@ -26,6 +26,7 @@
|
||||||
int z;
|
int z;
|
||||||
int cap;
|
int cap;
|
||||||
int spd;
|
int spd;
|
||||||
|
char online;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct term_req{
|
struct term_req{
|
||||||
|
|
|
@ -24,8 +24,9 @@
|
||||||
* (2) Attente de requête
|
* (2) Attente de requête
|
||||||
* (3) Gestion de la requête
|
* (3) Gestion de la requête
|
||||||
* (4) Envoi de la réponse
|
* (4) Envoi de la réponse
|
||||||
* [5] On libère la mémoire
|
* [5] On notifie que l'avion est déconnecté (crash)
|
||||||
* [6] Fermeture de la connection (SOCKET)
|
* [6] On libère la mémoire
|
||||||
|
* [7] Fermeture de la connection (SOCKET)
|
||||||
* [n] Arrêt du THREAD
|
* [n] Arrêt du THREAD
|
||||||
* 1. On met à jour "activeManagers"
|
* 1. On met à jour "activeManagers"
|
||||||
* 2. On arrête le THREAD
|
* 2. On arrête le THREAD
|
||||||
|
@ -90,11 +91,12 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
memcpy(&data.cap, buffer+sizeof(char)*6+sizeof(int)*3, sizeof(int));
|
memcpy(&data.cap, buffer+sizeof(char)*6+sizeof(int)*3, sizeof(int));
|
||||||
|
|
||||||
/* 4. Gestion de l'indianness */
|
/* 4. Gestion de l'indianness */
|
||||||
data.x = ntohl(data.x);
|
data.x = ntohl(data.x);
|
||||||
data.y = ntohl(data.y);
|
data.y = ntohl(data.y);
|
||||||
data.z = ntohl(data.z);
|
data.z = ntohl(data.z);
|
||||||
data.cap = ntohl(data.cap);
|
data.cap = ntohl(data.cap);
|
||||||
data.spd = ntohl(data.spd);
|
data.spd = ntohl(data.spd);
|
||||||
|
data.online = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,12 +166,21 @@ void* managePlane(void* THREADABLE_ARGS){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* [5] On libère la mémoire
|
/* [5] On notifie que l'avoin est déconnecté (crash)
|
||||||
|
=========================================================*/
|
||||||
|
/* 1. On notifie le crash */
|
||||||
|
arg->sgca->data[pindex].online = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [6] On libère la mémoire
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [6] Fermeture de la connection (SOCKET)
|
/* [7] Fermeture de la connection (SOCKET)
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
printf("{tcp_com}(%d) Fermeture de la socket de communication!\n", index);
|
printf("{tcp_com}(%d) Fermeture de la socket de communication!\n", index);
|
||||||
close(SOCKET);
|
close(SOCKET);
|
||||||
|
@ -219,10 +230,10 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
struct sockaddr_in clientInfo;
|
struct sockaddr_in clientInfo;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
char loop = 1;
|
char loop = 1;
|
||||||
int count, last, sent; // compteurs d'envoi
|
int count, last, sent, nb; // compteurs d'envoi
|
||||||
int i, index = -1; // Compteurs globaux
|
int i, index = -1; // Compteurs globaux
|
||||||
char buffer[MAX_BUF_LEN]; // Buffer d'envoi
|
char buffer[MAX_BUF_LEN]; // Buffer d'envoi
|
||||||
struct term_res request; // Requête
|
struct term_res request; // Requête
|
||||||
|
|
||||||
/* 2. On récupère les arguments */
|
/* 2. On récupère les arguments */
|
||||||
struct handler_arg* arg = THREADABLE_ARGS;
|
struct handler_arg* arg = THREADABLE_ARGS;
|
||||||
|
@ -248,20 +259,25 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* 1. On initialise les variables utiles */
|
/* 1. On initialise les variables utiles */
|
||||||
request.flags = TERMREQ_FBK;
|
request.flags = TERMREQ_FBK;
|
||||||
request.n = arg->sgca->n;
|
nb = arg->sgca->n;
|
||||||
|
request.n = 0; // nombre d'avions online
|
||||||
|
|
||||||
free(request.data);
|
free(request.data);
|
||||||
request.data = malloc( request.n * sizeof(struct plane) + 1 );
|
request.data = malloc( nb * sizeof(struct plane) + 1 );
|
||||||
|
|
||||||
/* 2. On récupère la liste des avions (network byte order) */
|
/* 2. On récupère la liste des avions (network byte order) */
|
||||||
for( i = 0 ; i < request.n ; i++ ){
|
for( i = 0 ; i < nb ; i++ ){
|
||||||
|
|
||||||
memcpy(&request.data[i].code, &arg->sgca->data[i].code, sizeof(char)*6);
|
memcpy(&request.data[i].code, &arg->sgca->data[i].code, sizeof(char)*6);
|
||||||
request.data[i].x = htonl( arg->sgca->data[i].x );
|
request.data[i].x = htonl( arg->sgca->data[i].x );
|
||||||
request.data[i].y = htonl( arg->sgca->data[i].y );
|
request.data[i].y = htonl( arg->sgca->data[i].y );
|
||||||
request.data[i].z = htonl( arg->sgca->data[i].z );
|
request.data[i].z = htonl( arg->sgca->data[i].z );
|
||||||
request.data[i].cap = htonl( arg->sgca->data[i].cap );
|
request.data[i].cap = htonl( arg->sgca->data[i].cap );
|
||||||
request.data[i].spd = htonl( arg->sgca->data[i].spd );
|
request.data[i].spd = htonl( arg->sgca->data[i].spd );
|
||||||
|
request.data[i].online = arg->sgca->data[i].online;
|
||||||
|
|
||||||
|
// Incrément du compte si online
|
||||||
|
request.n += request.data[i].online;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +293,11 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
|
|
||||||
/* 3. Copie des données des avions */
|
/* 3. Copie des données des avions */
|
||||||
for( i = 0 ; i < request.n ; i++ ){
|
for( i = 0 ; i < request.n ; i++ ){
|
||||||
|
|
||||||
|
// Ignore les avions offline
|
||||||
|
if( !request.data[i].online )
|
||||||
|
continue;
|
||||||
|
|
||||||
count += last; last = sizeof(char)*6; memcpy(buffer+count, &request.data[i].code, last);
|
count += last; last = sizeof(char)*6; memcpy(buffer+count, &request.data[i].code, last);
|
||||||
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].x, last);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].x, last);
|
||||||
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].y, last);
|
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].y, last);
|
||||||
|
|
Loading…
Reference in New Issue