[Aggregator] Fix autocalibration scheduler

The list of knowns APs is now handled as a double-linked token ring
instead of a double-linked list.
The scheduler for autocalibration transmissions is now operational!

Delete the now-useless function move_ap_front(), which was not used
before anyway.
This commit is contained in:
Matteo Cypriani 2010-10-26 14:53:24 +02:00
parent 97a1e7c72a
commit 8319ca112a
2 changed files with 52 additions and 33 deletions

View File

@ -108,7 +108,6 @@ void delete_old_aps(void) ;
void delete_ap(ap_list *ap) ;
void unlink_ap(ap_list *ap) ;
void order_send(ap_list *ap) ;
void move_ap_front(ap_list *ap) ;
void free_ap_list(void) ;
char* ip_bytes_to_string(unsigned char *ip_binary) ;

View File

@ -12,7 +12,7 @@
char *program_name = NULL ;
cfg_t *cfg = NULL ; // Configuration structure
couple_list *couples = NULL ; // Computed data list
ap_list *aps = NULL ;
ap_list *token_aps = NULL ; // Token ring of the APs
unsigned int nb_aps = 0 ;
@ -733,14 +733,19 @@ void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16])
*/
ap_list* find_ap(unsigned char mac_addr_bytes[6])
{
ap_list *found = aps ;
ap_list *found ;
while (found != NULL)
if (token_aps == NULL)
return NULL ;
found = token_aps ;
do
{
if (mac_cmp(found->mac_addr_bytes, mac_addr_bytes))
return found ;
found = found->next ;
}
while (found != token_aps) ;
return NULL ;
}
@ -786,11 +791,20 @@ void update_ap_seen(ap_list *ap)
void push_ap(ap_list *ap)
{
assert(ap) ;
ap->previous = NULL ;
ap->next = aps ;
if (aps != NULL)
aps->previous = ap ;
aps = ap ;
if (token_aps == NULL) // List does not exist yet
{
token_aps = ap ;
ap->next = ap ;
ap->previous = ap ;
return ;
}
ap->previous = token_aps->previous ;
ap->previous->next = ap ;
ap->next = token_aps ;
token_aps->previous = ap ;
token_aps = ap ;
}
@ -810,7 +824,10 @@ void monitor_aps()
delete_old_aps() ;
if (nb_aps > 1)
order_send(aps) ;
{
order_send(token_aps) ;
token_aps = token_aps->next ;
}
usleep(cfg_getint(cfg, "ap_check_interval") * 1000) ;
}
@ -824,12 +841,16 @@ void monitor_aps()
void delete_old_aps()
{
struct timeval now ;
if (token_aps == NULL)
return ;
gettimeofday(&now, NULL) ;
while (aps != NULL)
if (sub_date(aps->last_seen, now) >
while (token_aps != token_aps->next)
if (sub_date(token_aps->last_seen, now) >
(unsigned long) cfg_getint(cfg, "ap_keep_timeout") * 1000)
delete_ap(aps) ;
delete_ap(token_aps) ;
else
return ;
}
@ -857,14 +878,14 @@ void unlink_ap(ap_list *ap)
*ap_previous = ap->previous,
*ap_next = ap->next ;
if (ap_previous != NULL)
ap_previous->next = ap_next ;
assert(ap_previous) ;
assert(ap_next) ;
if (ap_next != NULL)
ap_next->previous = ap_previous ;
ap_previous->next = ap_next ;
ap_next->previous = ap_previous ;
if (ap == aps)
aps = ap_next ;
if (ap == token_aps)
token_aps = ap_next ;
}
@ -902,29 +923,28 @@ void order_send(ap_list *ap)
}
/*
* Moves the given AP, existing in the AP list, in front of the list.
*/
void move_ap_front(ap_list *ap)
{
unlink_ap(ap) ;
push_ap(ap) ;
}
/*
* Empties the AP list.
*/
void free_ap_list()
{
ap_list *ap_ptr = aps ;
ap_list *ap_ptr ;
while (ap_ptr != NULL)
if (token_aps == NULL)
return ;
ap_ptr = token_aps->next ;
assert(ap_ptr) ;
while (ap_ptr != token_aps)
{
ap_list *ap_tmp = ap_ptr ;
ap_ptr = ap_ptr->next ;
free(aps) ;
aps = ap_ptr ;
free(ap_tmp) ;
}
free(token_aps) ;
token_aps = NULL ;
}