[Aggregator] Write all messages to stderr

Since the aggregated requests can be written to stdout, we must not use
it for other messages. Therefore, we now use stderr for all messages.
This commit is contained in:
Matteo Cypriani 2011-03-24 09:02:34 +01:00
parent c87c2e2e93
commit ddd4e16b70
1 changed files with 58 additions and 55 deletions

View File

@ -121,7 +121,7 @@ int main(int argc, char **argv)
free_ap_list() ;
cfg_free(cfg) ; // Clean configuration
printf("%s: end.\n", program_name) ;
fprintf(stderr, "%s: end.\n", program_name) ;
return ret ;
}
@ -419,30 +419,31 @@ int read_loop(int sockfd)
owl_timestamp_to_string(request_time_str,
request.request_time) ;
owl_timestamp_to_string(start_time_str, request.start_time) ;
printf("\n"
"*** Request received from AP ***\n"
"\tAP MAC: %s\n"
"\tMobile MAC: %s\n"
"\tMobile IP: %s\n"
"\tSequence number (request timestamp): %s\n"
"\tRequest arrival time on the AP: %s\n"
"\tSignal: %d dBm\n"
"\tPosition X: %f\n"
"\tPosition Y: %f\n"
"\tPosition Z: %f\n"
"\tDirection: %hhd\n"
,
ap_mac_str,
mobile_mac_str,
mobile_ip_str,
request_time_str,
start_time_str,
request.antenna_signal_dbm - 0x100,
request.x_position,
request.y_position,
request.z_position,
request.direction
) ;
fprintf(stderr,
"\n"
"*** Request received from AP ***\n"
"\tAP MAC: %s\n"
"\tMobile MAC: %s\n"
"\tMobile IP: %s\n"
"\tSequence number (request timestamp): %s\n"
"\tRequest arrival time on the AP: %s\n"
"\tSignal: %d dBm\n"
"\tPosition X: %f\n"
"\tPosition Y: %f\n"
"\tPosition Z: %f\n"
"\tDirection: %hhd\n"
,
ap_mac_str,
mobile_mac_str,
mobile_ip_str,
request_time_str,
start_time_str,
request.antenna_signal_dbm - 0x100,
request.x_position,
request.y_position,
request.z_position,
request.direction
) ;
free(ap_mac_str) ;
free(mobile_mac_str) ;
}
@ -533,13 +534,13 @@ void* monitor_requests(void *NULL_value)
// If the timeout is reached
if (sub > aggregate_timeout)
{
printf("* Timeout reached.") ;
fprintf(stderr, "* Timeout reached.") ;
#ifdef DEBUG
printf(" sub=%"PRIuFAST32" >"
" aggregate_timeout=%"PRIuFAST32"\n",
sub, aggregate_timeout) ;
fprintf(stderr, " sub=%"PRIuFAST32" >"
" aggregate_timeout=%"PRIuFAST32"\n",
sub, aggregate_timeout) ;
#else // DEBUG
putchar('\n') ;
putc('\n', stderr) ;
#endif // DEBUG
// Print mobile MAC address to the output file
@ -619,13 +620,13 @@ void* monitor_requests(void *NULL_value)
{
request_list *request_tmp = request_ptr ;
printf("* Keep timeout reached.") ;
fprintf(stderr, "* Keep timeout reached.") ;
#ifdef DEBUG
printf(" sub=%"PRIuFAST32" >"
" keep_timeout=%"PRIuFAST32"\n",
sub, keep_timeout) ;
fprintf(stderr, " sub=%"PRIuFAST32" >"
" keep_timeout=%"PRIuFAST32"\n",
sub, keep_timeout) ;
#else // DEBUG
putchar('\n') ;
putc('\n', stderr) ;
#endif // DEBUG
request_ptr = request_ptr->next ;
@ -681,7 +682,7 @@ void got_request(owl_captured_request request)
tmp_request = requests ;
if (requests == NULL) // If the request list does not exist,
{
printf("Creating request list.\n") ;
fprintf(stderr, "Creating request list.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it.
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
@ -738,7 +739,7 @@ void got_request(owl_captured_request request)
if (tmp_request == NULL) // The request does not exist in the list
{
printf("Create new request.\n") ;
fprintf(stderr, "Create new request.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
@ -765,12 +766,12 @@ void got_request(owl_captured_request request)
{
if (tmp_request->info == NULL)
{ // We already sent to the server data for this request
printf("Request already treated.\n") ;
fprintf(stderr, "Request already treated.\n") ;
free(tmp_info) ;
}
else
{
printf("Add information to the request.\n") ;
fprintf(stderr, "Add information to the request.\n") ;
tmp_info->next = tmp_request->info ; // Add data
tmp_request->info = tmp_info ;
}
@ -1136,7 +1137,7 @@ void print_request_list()
if (requests == NULL) // Empty list
{
printf("No request.\n") ;
fprintf(stderr, "No request.\n") ;
return ;
}
@ -1150,25 +1151,26 @@ void print_request_list()
request_ptr->request_time) ;
owl_timestamp_to_string(start_time_str,
request_ptr->start_time) ;
printf("Mobile MAC: %s\n"
"Sequence number: %s\n"
"Reception timestamp: %s\n"
"\n",
mobile_mac_str,
request_time_str,
start_time_str
) ;
fprintf(stderr,
"Mobile MAC: %s\n"
"Sequence number: %s\n"
"Reception timestamp: %s\n"
"\n",
mobile_mac_str,
request_time_str,
start_time_str
) ;
free(mobile_mac_str) ;
// Parse information relative to the current request
while (info_ptr != NULL)
{
print_request_info(info_ptr) ;
putchar('\n') ;
putc('\n', stderr) ;
info_ptr = info_ptr->next ;
}
printf("\n\n") ;
fprintf(stderr, "\n\n") ;
request_ptr = request_ptr->next ;
}
@ -1186,11 +1188,12 @@ void print_request_info(request_info_list *info)
return ;
ap_mac_str = owl_mac_bytes_to_string(info->ap_mac_addr_bytes) ;
printf("\tAP MAC: %s\n"
"\tSignal strength: %d dBm\n",
ap_mac_str,
info->antenna_signal_dbm - 0x100
) ;
fprintf(stderr,
"\tAP MAC: %s\n"
"\tSignal strength: %d dBm\n",
ap_mac_str,
info->antenna_signal_dbm - 0x100
) ;
free(ap_mac_str) ;
}
#endif // DEBUG