[lib-result] fprint_*(): const pointers & asserts

owl_fprint_*():
- Mark pointer arguments as const.
- Rename main argument "src".
- Use assertion to check the source.
This commit is contained in:
Matteo Cypriani 2011-08-19 17:10:05 +02:00
parent 084daed33f
commit c7ba92cef9
2 changed files with 25 additions and 19 deletions

View File

@ -4,6 +4,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#define CSV_DELIMITER ";"
@ -183,23 +185,25 @@ void owl_fill_result(owl_result **result, char *csv)
/*
* Prints an owl_result to the given stream.
*/
void owl_fprint_result(FILE *stream, owl_result *result)
void owl_fprint_result(FILE *stream, const owl_result *const src)
{
char timestamp_str[OWL_TIMESTAMP_STRLEN] ;
owl_timestamp_to_string(timestamp_str, result->mobile_timestamp) ;
assert(src) ;
owl_timestamp_to_string(timestamp_str, src->mobile_timestamp) ;
fprintf(stream,
"Mobile MAC: %s\n"
"Request type: %"PRIu8"\n"
"Mobile timestamp: %s\n"
"Results:\n"
,
result->mobile_mac_addr,
result->request_type,
src->mobile_mac_addr,
src->request_type,
timestamp_str
) ;
owl_algorithm_result *algo = result->results ;
owl_algorithm_result *algo = src->results ;
while (algo)
{
owl_fprint_algorithm_result(stream, algo) ;
@ -209,11 +213,13 @@ void owl_fprint_result(FILE *stream, owl_result *result)
/*
* Prints an owl_result to the given stream.
* Prints an owl_algorithm_result to the given stream.
*/
void owl_fprint_algorithm_result(FILE *stream,
owl_algorithm_result *algo)
const owl_algorithm_result *const src)
{
assert(src) ;
fprintf(stream,
"* Algorithm: %s\n"
" X: %f\n"
@ -222,12 +228,12 @@ void owl_fprint_algorithm_result(FILE *stream,
" Error: %f\n"
" Area: %s\n"
,
algo->algorithm,
algo->x,
algo->y,
algo->z,
algo->error,
algo->area ? algo->area : ""
src->algorithm,
src->x,
src->y,
src->z,
src->error,
src->area ? src->area : ""
) ;
}

View File

@ -55,13 +55,13 @@ typedef struct _owl_result
void owl_receive_position(int sockfd, owl_result **result) ;
void owl_fill_result(owl_result **result, char *csv) ;
void owl_fprint_result(FILE *stream, owl_result *result) ;
void owl_fprint_result(FILE *stream, const owl_result *const src) ;
void owl_fprint_algorithm_result(FILE *stream,
owl_algorithm_result *algo) ;
#define owl_print_result(RESULT) \
(owl_fprint_result(stdout, (RESULT)))
#define owl_print_algorithm_result(ALGO) \
(owl_fprint_algorithm_result(stdout, (ALGO)))
const owl_algorithm_result *const src) ;
#define owl_print_result(SRC) \
(owl_fprint_result(stdout, (SRC)))
#define owl_print_algorithm_result(SRC) \
(owl_fprint_algorithm_result(stdout, (SRC)))
void owl_free_result(owl_result *result) ;
void owl_free_algorithm_result(owl_algorithm_result *algo) ;