From: Andre Date: Mon, 3 Jul 2006 01:33:47 +0000 (+0200) Subject: improve and clean up audiod_status_dump() X-Git-Tag: v0.2.14~59^2~8 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=c60eb263adee5ba7dc6f9c1373c0a18afb50fec1;p=paraslash.git improve and clean up audiod_status_dump() Currently, no status is printed if audiod is off. This is suboptimal as the _audiod_ status items should be sent in any case. This patch also - gets rid of some static variables in audiod_status_dump() - improves readability of audiod_status_dump() - moves dump_empty_status() from stat.c to audiod_command.c --- diff --git a/audiod.h b/audiod.h index c8d5fc2e..e4faea4e 100644 --- a/audiod.h +++ b/audiod.h @@ -86,6 +86,7 @@ extern const char *status_item_list[NUM_STAT_ITEMS]; void __noreturn clean_exit(int status, const char *msg); int handle_connect(int accept_fd); void audiod_status_dump(void); +void dump_empty_status(void); /** iterate over all slots */ #define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++) diff --git a/audiod_command.c b/audiod_command.c index fe26b663..312cfee1 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -608,33 +608,65 @@ out: void audiod_status_dump(void) { - static char *p_ts, *p_us, *p_as, *p_df; struct timeval *t = wstime(); - char *us, *tmp = get_time_string(t); - - if (tmp && (!p_ts || strcmp(tmp, p_ts))) - stat_client_write(tmp, SI_PLAY_TIME); - free(p_ts); - p_ts = tmp; + char *old, *new, *tmp; + + old = stat_task->stat_item_values[SI_PLAY_TIME]; + new = get_time_string(t); + if (new) { + if (!old || strcmp(old, new)) { + free(old); + stat_client_write(new, SI_PLAY_TIME); + stat_task->stat_item_values[SI_PLAY_TIME] = new; + } else + free(new); + } - us = uptime_str(); - tmp = make_message("%s:%s\n", status_item_list[SI_AUDIOD_UPTIME], us); - free(us); - if (!p_us || strcmp(p_us, tmp)) + new = uptime_str(); + old = stat_task->stat_item_values[SI_AUDIOD_UPTIME]; + if (!old || strcmp(old, new)) { + free(old); + tmp = make_message("%s:%s\n", + status_item_list[SI_AUDIOD_UPTIME], new); stat_client_write(tmp, SI_AUDIOD_UPTIME); - free(p_us); - p_us = tmp; - - tmp = audiod_status_string(); - if (!p_as || strcmp(p_as, tmp)) - stat_client_write(tmp, SI_AUDIOD_STATUS); - free(p_as); - p_as = tmp; - - tmp = decoder_flags(); - if (!p_df || strcmp(p_df, tmp)) - stat_client_write(tmp, SI_DECODER_FLAGS); - free(p_df); - p_df = tmp; + free(tmp); + stat_task->stat_item_values[SI_AUDIOD_UPTIME] = new; + } else + free(new); + + old = stat_task->stat_item_values[SI_AUDIOD_STATUS]; + new = audiod_status_string(); + if (!old || strcmp(old, new)) { + free(old); + stat_client_write(new, SI_AUDIOD_STATUS); + stat_task->stat_item_values[SI_AUDIOD_STATUS] = new; + } else + free(new); + + old = stat_task->stat_item_values[SI_DECODER_FLAGS]; + new = decoder_flags(); + if (!old || strcmp(old, new)) { + stat_client_write(new, SI_DECODER_FLAGS); + stat_task->stat_item_values[SI_DECODER_FLAGS] = new; + } else + free(new); } +/** + * send empty status list + * + * Send to each connected client the full status item list + * with empty values. + */ +void dump_empty_status(void) +{ + int i; + + FOR_EACH_STAT_ITEM(i) { + char *tmp = make_message("%s:\n", status_item_list[i]); + stat_client_write(tmp, i); + free(tmp); + free(stat_task->stat_item_values[i]); + stat_task->stat_item_values[i] = NULL; + } +} diff --git a/para.h b/para.h index 26e04c6c..b5a8f7bb 100644 --- a/para.h +++ b/para.h @@ -155,8 +155,8 @@ int stat_item_valid(const char *item); int stat_line_valid(const char *); void stat_client_write(char *msg, int itemnum); int stat_client_add(int fd, long unsigned mask); -void dump_empty_status(void); unsigned for_each_line(char *, int, void (*)(char *)); +#define FOR_EACH_STAT_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) struct stat_item_data { const char *prefix, *postfix; diff --git a/stat.c b/stat.c index 33fdb8c1..8220fd27 100644 --- a/stat.c +++ b/stat.c @@ -90,7 +90,6 @@ const char *status_item_list[NUM_STAT_ITEMS] = { [SI_AUDIOD_UPTIME] = "audiod_uptime", [SI_SELECTOR] = "dbtool" }; -#define FOR_EACH_STAT_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) static void dump_stat_client_list(void) { @@ -174,24 +173,6 @@ void stat_client_write(char *msg, int itemnum) PARA_DEBUG_LOG("%d client(s)\n", num_clients); } -/** - * send empty status list - * - * Send to each connected client the full status item list - * with empty values. - */ -void dump_empty_status(void) -{ - int i; - - if (!initialized) - return; - FOR_EACH_STAT_ITEM(i) { - char *tmp = make_message("%s:\n", status_item_list[i]); - stat_client_write(tmp, i); - free(tmp); - } -} /** * check if string is a known status item.