[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 <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
#define CSV_DELIMITER ";" #define CSV_DELIMITER ";"
@ -183,23 +185,25 @@ void owl_fill_result(owl_result **result, char *csv)
/* /*
* Prints an owl_result to the given stream. * 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] ; 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, fprintf(stream,
"Mobile MAC: %s\n" "Mobile MAC: %s\n"
"Request type: %"PRIu8"\n" "Request type: %"PRIu8"\n"
"Mobile timestamp: %s\n" "Mobile timestamp: %s\n"
"Results:\n" "Results:\n"
, ,
result->mobile_mac_addr, src->mobile_mac_addr,
result->request_type, src->request_type,
timestamp_str timestamp_str
) ; ) ;
owl_algorithm_result *algo = result->results ; owl_algorithm_result *algo = src->results ;
while (algo) while (algo)
{ {
owl_fprint_algorithm_result(stream, 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, void owl_fprint_algorithm_result(FILE *stream,
owl_algorithm_result *algo) const owl_algorithm_result *const src)
{ {
assert(src) ;
fprintf(stream, fprintf(stream,
"* Algorithm: %s\n" "* Algorithm: %s\n"
" X: %f\n" " X: %f\n"
@ -222,12 +228,12 @@ void owl_fprint_algorithm_result(FILE *stream,
" Error: %f\n" " Error: %f\n"
" Area: %s\n" " Area: %s\n"
, ,
algo->algorithm, src->algorithm,
algo->x, src->x,
algo->y, src->y,
algo->z, src->z,
algo->error, src->error,
algo->area ? algo->area : "" 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_receive_position(int sockfd, owl_result **result) ;
void owl_fill_result(owl_result **result, char *csv) ; 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, void owl_fprint_algorithm_result(FILE *stream,
owl_algorithm_result *algo) ; const owl_algorithm_result *const src) ;
#define owl_print_result(RESULT) \ #define owl_print_result(SRC) \
(owl_fprint_result(stdout, (RESULT))) (owl_fprint_result(stdout, (SRC)))
#define owl_print_algorithm_result(ALGO) \ #define owl_print_algorithm_result(SRC) \
(owl_fprint_algorithm_result(stdout, (ALGO))) (owl_fprint_algorithm_result(stdout, (SRC)))
void owl_free_result(owl_result *result) ; void owl_free_result(owl_result *result) ;
void owl_free_algorithm_result(owl_algorithm_result *algo) ; void owl_free_algorithm_result(owl_algorithm_result *algo) ;