/*
- * Copyright (C) 1998-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2008 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
#include <stropts.h>
#include <ctype.h>
-#include <curses.h>
#include <stdlib.h> /* EXIT_SUCCESS */
#include <unistd.h>
#include <signal.h>
close(mixer_fd);
}
-static int client_cmd(const char *cmd,...)
+static void client_cmd(const char *cmd)
{
int ret, fds[3] = {0, 0, 0};
pid_t pid;
PARA_INFO_LOG("%s\n", cmdline);
ret = para_exec_cmdline_pid(&pid, cmdline, fds);
free(cmdline);
- return ret;
+ if (ret < 0)
+ exit(EXIT_FAILURE);
+ do
+ ret = wait(NULL);
+ while (ret != -1 && errno != ECHILD);
+}
+
+static void change_afs_mode_and_play(char *afs_mode)
+{
+ char *cmd;
+
+ client_cmd("stop");
+ if (!afs_mode)
+ return;
+ cmd = make_message("select %s\n", afs_mode);
+ client_cmd(cmd);
+ free(cmd);
+ client_cmd("play");
}
/*
unsigned int delay;
struct tm *tm;
int min = conf.wake_min_arg;
- char *fa_stream = conf.fa_stream_arg;
- char *wake_stream = conf.wake_stream_arg;
- //char *current_stream = stat_items[STREAM].content;
+ char *fa_mode = conf.fa_mode_arg;
+ char *wake_mode = conf.wake_mode_arg;
+ char *sleep_mode = conf.sleep_mode_arg;
int wf = conf.wake_fade_arg;
int sf = conf.fa_fade_arg;
int wv = conf.wake_vol_arg;
int sv = conf.fa_vol_arg;
int iv = conf.sleep_ivol_arg;
- char *cmd, *sleep_stream = conf.sleep_stream_given?
- conf.sleep_stream_arg : NULL;
/* calculate wake time */
time(&t1);
tm->tm_min = min;
tm->tm_sec = 0;
} else {
- t1 += 8 * 60 * 60;
+ t1 += 9 * 60 * 60; /* nine hours from now */
PARA_INFO_LOG("default wake time: %lu\n", t1);
tm = localtime(&t1);
}
wake_time_epoch = mktime(tm);
PARA_INFO_LOG("waketime: %s", asctime(tm));
+ client_cmd("stop");
+ sleep(1);
if (sf) {
PARA_INFO_LOG("initial volume: %d\n", iv);
set_vol(iv);
- cmd = make_message("csp %s\n", fa_stream);
- client_cmd(cmd);
- free(cmd);
+ change_afs_mode_and_play(fa_mode);
fade(sv, sf);
- }
- if (sleep_stream) {
- cmd = make_message("csp %s\n", sleep_stream);
- client_cmd(cmd);
- free(cmd);
} else
- client_cmd("stop");
+ set_vol(sf);
+ change_afs_mode_and_play(sleep_mode);
if (!wf)
return;
for (;;) {
break;
delay = wake_time_epoch - t1 - wf;
PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
- delay, delay / 3600,
+ delay, delay / 3600,
(delay % 3600) / 60);
sleep(delay);
}
- cmd = make_message("csp %s\n", wake_stream);
- client_cmd(cmd);
- free(cmd);
+ change_afs_mode_and_play(wake_mode);
fade(wv, wf);
- PARA_INFO_LOG("%s", "fade complete, returning\n");
+ PARA_INFO_LOG("fade complete, returning\n");
}
static void snooze(void)