X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod_command.c;h=ca1bff5b807de5b75b833740bc5ac84c90345bb5;hp=27ef63caea22f9af45d9a951a5df39d1cb078210;hb=d97f7f0d98a83e7cd1f3a62b40d734d9ff5075b7;hpb=40de1dd2fdbb054444d585aa70e2d50166a66e07 diff --git a/audiod_command.c b/audiod_command.c index 27ef63ca..ca1bff5b 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Andre Noll + * Copyright (C) 2005-2009 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -46,20 +46,22 @@ __malloc static char *audiod_status_string(void) return make_message("%s: %s\n", status_item_list[SI_AUDIOD_STATUS], status); } -static struct timeval *wstime(void) +static int get_play_time_slot_num(void) { - int i; - struct timeval *max = NULL; + int i, oldest = -1; + FOR_EACH_SLOT(i) { struct slot_info *s = &slot[i]; if (!s->wng) continue; - if (max && tv_diff(&s->wstime, max, NULL) <= 0) + if (oldest >= 0 && tv_diff(&s->wstime, &slot[oldest].wstime, + NULL) > 0) continue; - max = &s->wstime; + oldest = i; } - return max; + return oldest; } + __malloc static char *decoder_flags(void) { int i; @@ -164,25 +166,26 @@ int com_kill(int fd, int argc, char **argv) return ret; } -int com_stat(int fd, __a_unused int argc, __a_unused char **argv) +int com_stat(int fd, int argc, char **argv) { int i, ret; char *buf = NULL; - long unsigned mask = ~0LU; + uint64_t mask = 0; + const uint64_t one = 1; if (argc > 1) { - mask = 0; for (i = 1; i < argc; i++) { ret = stat_item_valid(argv[i]); if (ret < 0) return ret; - mask |= (1 << ret); + mask |= (one << ret); } - } - PARA_INFO_LOG("mask: 0x%lx\n", mask); - if (mask & (1 << SI_PLAY_TIME)) { - struct timeval *t = wstime(); - char *ts = get_time_string(t); + } else + mask--; /* set all bits */ + PARA_INFO_LOG("mask: 0x%llx\n", (long long unsigned)mask); + if (mask & (one << SI_PLAY_TIME)) { + int slot_num = get_play_time_slot_num(); + char *ts = get_time_string(slot_num); if (ts) { ret = client_write(fd, ts); if (ret < 0) @@ -190,7 +193,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv) free(ts); } } - if (mask & (1 << SI_AUDIOD_UPTIME)) { + if (mask & (one << SI_AUDIOD_UPTIME)) { char *tmp, *us = uptime_str(); tmp = make_message("%s: %s\n", status_item_list[SI_AUDIOD_UPTIME], us); @@ -200,14 +203,14 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv) goto out; free(tmp); } - if (mask & (1 << SI_AUDIOD_STATUS)) { + if (mask & (one << SI_AUDIOD_STATUS)) { char *s = audiod_status_string(); ret = client_write(fd, s); if (ret < 0) goto out; free(s); } - if (mask & (1 << SI_DECODER_FLAGS)) { + if (mask & (one << SI_DECODER_FLAGS)) { char *df = decoder_flags(); ret = client_write(fd, df); if (ret < 0) @@ -216,7 +219,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv) } FOR_EACH_STATUS_ITEM(i) { char *tmp, *v; - if (!((1 << i) & mask)) + if (!((one << i) & mask)) continue; v = stat_item_values[i]; tmp = make_message("%s%s%s", buf? buf: "", @@ -379,7 +382,6 @@ int handle_connect(int accept_fd) ret = check_perms(uid); if (ret < 0) goto out; - ret = -E_INVALID_AUDIOD_CMD; cmd = para_strdup(buf); p = strchr(cmd, '\n'); if (!p) @@ -423,11 +425,11 @@ out: */ void audiod_status_dump(void) { - struct timeval *t = wstime(); + int slot_num = get_play_time_slot_num(); char *old, *new, *tmp; old = stat_item_values[SI_PLAY_TIME]; - new = get_time_string(t); + new = get_time_string(slot_num); if (new) { if (!old || strcmp(old, new)) { free(old);