#include "filter.h"
#include "grab_client.cmdline.h"
#include "grab_client.h"
-#include "ringbuffer.h"
#include "error.h"
#include "audiod.h"
sa_time_diff_sign = 1, audiod_socket = -1;
static char *af_status, /* the audio format announced in server status */
*socket_name, *hostname;
-/** how many status items to remember */
-#define RINGBUFFER_SIZE 32
-static void *stat_item_ringbuf;
+static char *stat_item_values[NUM_STAT_ITEMS];
static FILE *logfile;
static const struct timeval restart_delay = {0, 300 * 1000};
struct timeval now, diff, adj_stream_start, tmp;
int total = 0, use_server_time = 1;
- if (!playing)
- return make_message("%s:", length_seconds?
- "" : status_item_list[SI_PLAY_TIME]);
+ if (!playing) {
+ if (length_seconds)
+ return NULL;
+ return make_message("%s:", status_item_list[SI_PLAY_TIME]);
+ }
if (audiod_status == AUDIOD_OFF)
goto out;
if (sa_time_diff_sign > 0)
decoder_flags[MAX_STREAM_SLOTS] = '\0';
time_string = get_time_string(newest_stime);
uptime_string = uptime_str();
- ret = make_message("%s:%s\n%s:%s\n%s:%s\n%s",
+ ret = make_message("%s:%s\n%s:%s\n%s:%s",
status_item_list[SI_AUDIOD_UPTIME], uptime_string,
status_item_list[SI_DECODER_FLAGS], decoder_flags,
status_item_list[SI_AUDIOD_STATUS], audiod_status == AUDIOD_ON?
- "on" : (audiod_status == AUDIOD_OFF? "off": "sb"),
- time_string);
+ "on" : (audiod_status == AUDIOD_OFF? "off": "sb"));
+ if (time_string)
+ ret = make_message("%s\n%s", ret, time_string);
free(uptime_string);
free(decoder_flags);
free(time_string);
static void close_stat_pipe(void)
{
- char *msg;
int i;
if (stat_pipe < 0)
del_close_on_fork_list(stat_pipe);
stat_pipe = -1;
kill_all_decoders();
- for (i = 0; i < RINGBUFFER_SIZE; i++)
- free(ringbuffer_add(stat_item_ringbuf, para_strdup(NULL)));
+ for (i = 0; i < NUM_STAT_ITEMS; i++) {
+ free(stat_item_values[i]);
+ stat_item_values[i] = NULL;
+ }
dump_empty_status();
length_seconds = 0;
offset_seconds = 0;
audiod_status_dump();
playing = 0;
- msg = make_message("%s:no connection to para_server\n",
+ stat_item_values[SI_STATUS_BAR] = make_message("%s:no connection to para_server\n",
status_item_list[SI_STATUS_BAR]);
- free(ringbuffer_add(stat_item_ringbuf, msg));
- stat_client_write(msg);
+ stat_client_write(stat_item_values[SI_STATUS_BAR]);
}
static void __noreturn clean_exit(int status, const char *msg)
if (!line)
return;
- free(ringbuffer_add(stat_item_ringbuf, para_strdup(line)));
- stat_client_write(line);
itemnum = stat_line_valid(line);
- if (itemnum < 0)
+ if (itemnum < 0) {
+ PARA_WARNING_LOG("invalid status line: %s\n", line);
return;
+ }
+ stat_client_write(line);
+ free(stat_item_values[itemnum]);
+ stat_item_values[itemnum] = para_strdup(line);
ilen = strlen(status_item_list[itemnum]);
switch (itemnum) {
case SI_STATUS:
/*
* command handlers don't close their fd on errors (ret < 0) so that
* its caller can send an error message. Otherwise (ret >= 0) it's up
- * to each individual command to close the fd if necessary.
+ * to each individual command to close the fd if necessary.
*/
static int com_help(int fd, int argc, char **argv)
static int com_stat(int fd, __unused int argc, __unused char **argv)
{
int i, ret;
- char *buf = audiod_status_string();
+ char *buf = make_message("%s\n", audiod_status_string());
- buf = para_strcat(buf, "\n");
- for (i = RINGBUFFER_SIZE - 1; i >= 0; i--) {
- char *tmp, *line = ringbuffer_get(stat_item_ringbuf, i);
- if (!line)
- continue;
- tmp = make_message("%s\n", line);
- buf = para_strcat(buf, tmp);
- free(tmp);
+ for (i = 0; i < NUM_STAT_ITEMS; i++) {
+ char *tmp, *v = stat_item_values[i];
+ tmp = make_message("%s%s%s", buf, v? v : "", v? "\n" : "");
+ free(buf);
+ buf = tmp;
}
ret = client_write(fd, buf);
if (ret > 0)
set_initial_status();
FOR_EACH_SLOT(i)
clear_slot(i);
- stat_item_ringbuf = ringbuffer_new(RINGBUFFER_SIZE);
init_grabbing();
setup_signal_handling();
if (conf.daemon_given)