Make struct signal_task generic and make afs use it.
authorAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 13:49:05 +0000 (15:49 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 13:49:05 +0000 (15:49 +0200)
16 files changed:
afs.c
audiod.c
command.c
configure.ac
gui.c
mood.c
mysql_selector.c
mysql_selector.cmd
playlist_selector.c
playlist_selector.cmd
random_selector.cmd
server.c
server.cmd
signal.h
user_list.c
user_list.h

diff --git a/afs.c b/afs.c
index 5ccb17f..71a9f1c 100644 (file)
--- a/afs.c
+++ b/afs.c
 #include "afs.h"
 #include "ipc.h"
 #include "string.h"
+#include "list.h"
+#include "sched.h"
+#include "signal.h"
+#include "fd.h"
 
 /** \file afs.c Paraslash's audio file selector. */
 
@@ -481,19 +485,78 @@ static void setup_command_socket(void)
                command_socket);
 }
 
-int server_socket;
+static int server_socket;
 
-void shed(void)
+void loop(void)
 {
        for (;;)
                sleep(1);
 }
 
+static void afs_shutdown(enum osl_close_flags flags)
+{
+       PARA_NOTICE_LOG("cleaning up\n");
+       score_shutdown(flags);
+       attribute_shutdown(flags);
+       mood_close();
+       playlist_close();
+       moods_shutdown(flags);
+       playlists_shutdown(flags);
+       lyrics_shutdown(flags);
+       images_shutdown(flags);
+       aft_shutdown(flags);
+}
+
+static void signal_pre_select(struct sched *s, struct task *t)
+{
+       struct signal_task *st = t->private_data;
+       t->ret = 1;
+       para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+}
+
+static void signal_post_select(struct sched *s, struct task *t)
+{
+       struct signal_task *st = t->private_data;
+       t->ret = 1;
+       if (!FD_ISSET(st->fd, &s->rfds))
+               return;
+       st->signum = para_next_signal();
+       PARA_NOTICE_LOG("caught signal %d\n", st->signum);
+       t->ret = 1;
+       if (st->signum == SIGUSR1)
+               return; /* ignore SIGUSR1 */
+       afs_shutdown(OSL_MARK_CLEAN);
+       t->ret = -E_SIGNAL_CAUGHT;
+}
+
+static void register_signal_task(void)
+{
+       static struct signal_task signal_task_struct;
+       struct signal_task *st = &signal_task_struct;
+       st->fd = para_signal_init();
+       PARA_INFO_LOG("signal pipe: fd %d\n", st->fd);
+       para_install_sighandler(SIGINT);
+       para_install_sighandler(SIGTERM);
+       para_install_sighandler(SIGPIPE);
+
+       st->task.pre_select = signal_pre_select;
+       st->task.post_select = signal_post_select;
+       st->task.private_data = st;
+       sprintf(st->task.status, "signal task");
+       register_task(&st->task);
+}
+
+void register_tasks(void)
+{
+       register_signal_task();
+}
+
 __noreturn int afs_init(uint32_t cookie, int socket_fd)
 {
        int ret;
 //     void *shm_area;
        enum play_mode current_play_mode;
+       struct sched s;
 
        server_socket = socket_fd;
        socket_cookie = cookie;
@@ -524,7 +587,10 @@ __noreturn int afs_init(uint32_t cookie, int socket_fd)
                goto aft_init_error;
 
        current_play_mode = init_admissible_files();
-       shed();
+       register_tasks();
+       s.default_timeout.tv_sec = 0;
+       s.default_timeout.tv_usec = 99 * 1000;
+       sched(&s);
 
 #if 0
        ret = shm_new(sizeof(struct callback_data));
@@ -788,19 +854,6 @@ out:
        mutex_unlock(result_mutex); /* wake up child */
 }
 
-static void afs_shutdown(enum osl_close_flags flags)
-{
-       score_shutdown(flags);
-       attribute_shutdown(flags);
-       mood_close();
-       playlist_close();
-       moods_shutdown(flags);
-       playlists_shutdown(flags);
-       lyrics_shutdown(flags);
-       images_shutdown(flags);
-       aft_shutdown(flags);
-}
-
 #if 0
 static int got_sigchld;
 static void server_loop(int child_pid)
index d4abb3b..ccb2331 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -104,18 +104,6 @@ struct command_task {
        struct task task;
 };
 
-/**
- * task for signal handling
- */
-struct signal_task {
-       /** the signal pipe */
-       int fd;
-       /** the number of the most recent signal */
-       int signum;
-       /** the associated task structure */
-       struct task task;
-};
-
 /** iterate over all supported audio formats */
 #define FOR_EACH_AUDIO_FORMAT(af) for (af = 0; af < NUM_AUDIO_FORMATS; af++)
 
index ecadfc4..9873fdd 100644 (file)
--- a/command.c
+++ b/command.c
@@ -22,6 +22,7 @@
 #include "daemon.h"
 #include "string.h"
 #include "fd.h"
+#include "list.h"
 #include "user_list.h"
 #include "server_command_list.h"
 
index 316adf1..7449cde 100644 (file)
@@ -110,7 +110,7 @@ server_cmdline_objs="server.cmdline server_command_list random_selector_command_
 server_errlist_objs="server mp3_afh vss command net string signal random_selector
        time daemon stat crypt http_send afs_common close_on_fork playlist_selector
        ipc dccp dccp_send fd user_list chunk_queue afs osl aft mood score attribute
-       blob playlist sha1 rbtree"
+       blob playlist sha1 rbtree sched"
 server_ldflags=""
 server_audio_formats=" mp3"
 
diff --git a/gui.c b/gui.c
index 37d0d8e..28291a8 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -14,6 +14,8 @@
 #include "gui_common.h"
 #include "fd.h"
 #include "error.h"
+#include "list.h"
+#include "sched.h"
 #include "signal.h"
 
 /** define the array of error lists needed by para_gui */
diff --git a/mood.c b/mood.c
index 996b71f..decc77f 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -273,10 +273,8 @@ static int compute_mood_score(const void *row, long *result)
        /* reject if there is no matching entry in the accept list */
        if (!match && !list_empty(&current_mood->accept_list))
                return -E_NOT_ADMISSIBLE;
-       list_for_each_entry(item, &current_mood->score_list, mood_item_node) {
-               PARA_INFO_LOG("random: %d\n", para_random(100));
+       list_for_each_entry(item, &current_mood->score_list, mood_item_node)
                add_item_score(row, item, &score, &score_arg_sum);
-       }
        if (score_arg_sum)
                score /= score_arg_sum;
        *result = score;
index 702e08d..0635f85 100644 (file)
@@ -23,6 +23,7 @@
 #include "error.h"
 #include "net.h"
 #include "string.h"
+#include "list.h"
 #include "user_list.h"
 #include "mysql_selector_command_list.h"
 #include "ipc.h"
index 652ac53..5bfcc95 100644 (file)
@@ -3,7 +3,7 @@ SF: mysql_selector.c
 HC: prototypes for the commands of the mysql audio file selector
 CC: array of commands for the mysql audio file selector
 AT: server_command
-IN: para afh server user_list
+IN: para afh server list user_list
 SN: list of mysql selector commands
 ---
 N: cam
index 9eb6305..0da63ad 100644 (file)
@@ -14,6 +14,7 @@
 #include "net.h"
 #include "string.h"
 #include "ipc.h"
+#include "list.h"
 #include "user_list.h"
 #include "playlist_selector_command_list.h"
 
index 2006647..188b16e 100644 (file)
@@ -3,7 +3,7 @@ SF: playlist_selector.c
 HC: prototypes for the commands of the playlist audio file selector
 CC: array of commands for the playlist audio file selector
 AT: server_command
-IN: para afh server user_list
+IN: para afh server list user_list
 SN: list of playlist selector commands
 ---
 N: ppl
index 578c447..ef68cff 100644 (file)
@@ -3,7 +3,7 @@ SF: random_selector.c
 HC: prototypes for the commands of the random audio file selector
 CC: array of commands for the random audio file selector
 AT: server_command
-IN: para afh server user_list
+IN: para afh server list user_list
 SN: list of random selector commands
 ---
 N: random_info
index 94e6564..a63aeef 100644 (file)
--- a/server.c
+++ b/server.c
@@ -31,6 +31,8 @@
 #include "string.h"
 #include "ipc.h"
 #include "fd.h"
+#include "list.h"
+#include "sched.h"
 #include "signal.h"
 #include "user_list.h"
 #include "afs.h"
index b375509..fe6328f 100644 (file)
@@ -3,7 +3,7 @@ SF: command.c
 HC: prototypes for the server command handlers
 CC: array of server commands
 AT: server_command
-IN: para afh server user_list
+IN: para afh server list user_list
 SN: list of server commands
 ---
 N: chs
index 50c5f63..9214483 100644 (file)
--- a/signal.h
+++ b/signal.h
@@ -6,6 +6,18 @@
 
 /** \file signal.h exported symbols from signal.c */
 
+/**
+ * Task for signal handling.
+ */
+struct signal_task {
+       /** The signal pipe. */
+       int fd;
+       /** The number of the most recent signal. */
+       int signum;
+       /** The associated task structure. */
+       struct task task;
+};
+
 int para_signal_init(void);
 int para_install_sighandler(int);
 void para_reap_children(void);
index be36981..18df94b 100644 (file)
@@ -10,6 +10,7 @@
 #include "error.h"
 #include "fd.h"
 #include "string.h"
+#include "list.h"
 #include "user_list.h"
 
 static struct list_head user_list;
index 7e9ac9f..fbe0799 100644 (file)
@@ -6,7 +6,6 @@
 
 /** \file user_list.h exported functions from user_list.c */
 
-#include "list.h"
 #include "crypt.h"
 
 /**