audiod: fix enum of supported audio formats
[paraslash.git] / audiod_command.c
index 4d7afd2f2b37d2a4b67ec9d5d738839b13522153..312cfee1027f21f48291d520c7ee746e7671292d 100644 (file)
@@ -261,7 +261,7 @@ static struct timeval *wstime(void)
 __malloc static char *decoder_flags(void)
 {
        int i;
 __malloc static char *decoder_flags(void)
 {
        int i;
-       char decoder_flags[MAX_STREAM_SLOTS + 1];
+       char flags[MAX_STREAM_SLOTS + 1];
 
        FOR_EACH_SLOT(i) {
                struct slot_info *s = &slot[i];
 
        FOR_EACH_SLOT(i) {
                struct slot_info *s = &slot[i];
@@ -270,11 +270,11 @@ __malloc static char *decoder_flags(void)
                        flag += 1;
                if (s->wng)
                        flag += 2;
                        flag += 1;
                if (s->wng)
                        flag += 2;
-               decoder_flags[i] = flag;
+               flags[i] = flag;
        }
        }
-       decoder_flags[MAX_STREAM_SLOTS] = '\0';
+       flags[MAX_STREAM_SLOTS] = '\0';
        return make_message("%s:%s\n", status_item_list[SI_DECODER_FLAGS],
        return make_message("%s:%s\n", status_item_list[SI_DECODER_FLAGS],
-               decoder_flags);
+               flags);
 }
 
 static int dump_commands(int fd)
 }
 
 static int dump_commands(int fd)
@@ -608,33 +608,65 @@ out:
 
 void audiod_status_dump(void)
 {
 
 void audiod_status_dump(void)
 {
-       static char *p_ts, *p_us, *p_as, *p_df;
        struct timeval *t = wstime();
        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);
                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;
+       }
+}