[Aggregator] Refactor got_request()
Create add_captured_request() out of got_request(). Now, add_captured_request() will need to be refactored.
This commit is contained in:
parent
068553ee49
commit
61aa4af3a3
2
TODO.t2t
2
TODO.t2t
|
@ -96,7 +96,7 @@ Work to do in OwlPS
|
|||
|
||||
- Allow a different aggregation timeout for each request type.
|
||||
|
||||
- Refactor got_request().
|
||||
- Refactor add_captured_request().
|
||||
|
||||
- got_request(): option for the maximal difference time
|
||||
|
||||
|
|
|
@ -110,6 +110,9 @@ int check_configuration(void) ;
|
|||
int read_loop(int sockfd) ;
|
||||
void print_captured_request(const owl_captured_request *const request) ;
|
||||
void got_request(const owl_captured_request *const request) ;
|
||||
void add_captured_request(const owl_timestamp *const reception_time,
|
||||
const owl_captured_request *const request,
|
||||
request_info_list *const request_info) ;
|
||||
|
||||
void* monitor_requests(void *NULL_value) ;
|
||||
void scan_request_list(FILE *const stream,
|
||||
|
|
|
@ -631,13 +631,12 @@ void print_captured_request(const owl_captured_request *const request)
|
|||
*/
|
||||
void got_request(const owl_captured_request *const request)
|
||||
{
|
||||
request_list *tmp_request = NULL ;
|
||||
request_info_list *tmp_info = NULL ;
|
||||
owl_timestamp start_time ; // Reception time on the aggregator
|
||||
owl_timestamp reception_time ; // Reception time on the aggregator
|
||||
|
||||
assert(request) ;
|
||||
|
||||
owl_timestamp_now(&start_time) ;
|
||||
owl_timestamp_now(&reception_time) ;
|
||||
|
||||
/* Create a new request */
|
||||
tmp_info = malloc(sizeof(request_info_list)) ;
|
||||
|
@ -657,15 +656,34 @@ void got_request(const owl_captured_request *const request)
|
|||
|
||||
/* Add it in the list */
|
||||
sem_wait(&lock_requests) ;
|
||||
|
||||
// Make sure we are still running once we've got the lock
|
||||
if (! owl_run)
|
||||
{
|
||||
free(tmp_info) ;
|
||||
goto end ;
|
||||
}
|
||||
if (owl_run)
|
||||
add_captured_request(&reception_time, request, tmp_info) ;
|
||||
else
|
||||
free(tmp_info) ;
|
||||
sem_post(&lock_requests) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Inserts a received request into the requests' list.
|
||||
*
|
||||
* Parameters:
|
||||
* - reception_time: the time at wich the request was received at the
|
||||
* Aggregator
|
||||
* - request: the request to insert
|
||||
* - request_info: the request's information
|
||||
*/
|
||||
void add_captured_request(const owl_timestamp *const reception_time,
|
||||
const owl_captured_request *const request,
|
||||
request_info_list *const request_info)
|
||||
{
|
||||
request_list *tmp_request = requests ;
|
||||
|
||||
assert(reception_time) ;
|
||||
assert(request) ;
|
||||
assert(request_info) ;
|
||||
|
||||
tmp_request = requests ;
|
||||
if (requests == NULL) // If the request list does not exist,
|
||||
{
|
||||
if (VERBOSE_INFO)
|
||||
|
@ -676,7 +694,7 @@ void got_request(const owl_captured_request *const request)
|
|||
{
|
||||
perror("Cannot allocate memory") ;
|
||||
owl_run = false ;
|
||||
goto end ;
|
||||
return ;
|
||||
}
|
||||
tmp_request->type = request->type ;
|
||||
tmp_request->nb_packets = request->nb_packets ;
|
||||
|
@ -694,13 +712,13 @@ void got_request(const owl_captured_request *const request)
|
|||
tmp_request->request_time = request->capture_time ;
|
||||
// Save locale time on the aggregator (not the reception time
|
||||
// on the AP):
|
||||
tmp_request->start_time = start_time ;
|
||||
tmp_request->start_time = *reception_time ;
|
||||
tmp_request->x_position = request->x_position ;
|
||||
tmp_request->y_position = request->y_position ;
|
||||
tmp_request->z_position = request->z_position ;
|
||||
tmp_request->direction = request->direction ;
|
||||
tmp_request->next = NULL ;
|
||||
tmp_request->info = tmp_info ;
|
||||
tmp_request->info = request_info ;
|
||||
requests = tmp_request ;
|
||||
}
|
||||
|
||||
|
@ -745,7 +763,7 @@ void got_request(const owl_captured_request *const request)
|
|||
{
|
||||
perror("Cannot allocate memory") ;
|
||||
owl_run = false ;
|
||||
goto end ;
|
||||
return ;
|
||||
}
|
||||
tmp_request->type = request->type ;
|
||||
tmp_request->nb_packets = request->nb_packets ;
|
||||
|
@ -763,13 +781,13 @@ void got_request(const owl_captured_request *const request)
|
|||
tmp_request->request_time = request->capture_time ;
|
||||
// Save the local time on the aggregator (not the reception
|
||||
// time on the AP):
|
||||
tmp_request->start_time = start_time ;
|
||||
tmp_request->start_time = *reception_time ;
|
||||
tmp_request->x_position = request->x_position ;
|
||||
tmp_request->y_position = request->y_position ;
|
||||
tmp_request->z_position = request->z_position ;
|
||||
tmp_request->direction = request->direction ;
|
||||
tmp_request->next = requests ;
|
||||
tmp_request->info = tmp_info ;
|
||||
tmp_request->info = request_info ;
|
||||
requests = tmp_request ;
|
||||
}
|
||||
else // If the request was found in the list
|
||||
|
@ -778,20 +796,17 @@ void got_request(const owl_captured_request *const request)
|
|||
{ // We already sent to the server data for this request
|
||||
if (VERBOSE_CHATTERBOX)
|
||||
fprintf(stderr, "Request already treated.\n") ;
|
||||
free(tmp_info) ;
|
||||
free(request_info) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (VERBOSE_CHATTERBOX)
|
||||
fprintf(stderr, "Add information to the request.\n") ;
|
||||
tmp_info->next = tmp_request->info ; // Add data
|
||||
tmp_request->info = tmp_info ;
|
||||
request_info->next = tmp_request->info ; // Add data
|
||||
tmp_request->info = request_info ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
sem_post(&lock_requests) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue