]> git.tue.mpg.de Git - paraslash.git/commitdiff
simplify sched: nuke PRE_EOF_IS_ERROR
authorAndre <maan@p133.(none)>
Tue, 23 May 2006 21:45:42 +0000 (23:45 +0200)
committerAndre <maan@p133.(none)>
Tue, 23 May 2006 21:45:42 +0000 (23:45 +0200)
Much too simple to get it wrong. Instead, treat zero as success and
make all tasks return negative if they wish to have their error handler
called. A subsequent patch will rename error_handler to event_handler.

error.h
sched.c
sched.h
stdin.c
write.c
write_common.c

diff --git a/error.h b/error.h
index 84f427986006265a39fba96e34dce00c49ac738f..a53531b7fbf4f29bbd67474b17e2d1778b410b9a 100644 (file)
--- a/error.h
+++ b/error.h
@@ -88,6 +88,7 @@ extern const char **para_errlist[];
 
 #define STDIN_ERRORS \
        PARA_ERROR(STDIN_READ, "failed to read from stdin"), \
+       PARA_ERROR(STDIN_EOF, "end of file"), \
 
 
 #define SCHED_ERRORS \
@@ -351,7 +352,9 @@ extern const char **para_errlist[];
        PARA_ERROR(WRITE_OVERRUN, "buffer overrun"), \
        PARA_ERROR(PREMATURE_END, "premature end of audio file"), \
        PARA_ERROR(NO_WAV_HEADER, "wave header not found"), \
+       PARA_ERROR(WAV_HEADER_SUCCESS, "successfully read wave header"), \
        PARA_ERROR(NO_DELAY, "no initial delay"), \
+       PARA_ERROR(DELAY_TIMEOUT, "initial delay timeout"), \
 
 
 #define ALSA_WRITER_ERRORS \
@@ -383,6 +386,7 @@ extern const char **para_errlist[];
 
 #define WRITE_COMMON_ERRORS \
        PARA_ERROR(WRITE_COMMON_SYNTAX, "syntax error in write option"), \
+       PARA_ERROR(WNG_EOF, "wng: end of file"), \
 
 
 #define AACDEC_ERRORS \
diff --git a/sched.c b/sched.c
index fad70132232268a2c9aade01c12b29e68f8987dc..6233e40b950b3916c581882479461050cdd10551 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -18,13 +18,6 @@ again:
                t->pre_select(s, t);
                if (t->ret > 0 || !t->error_handler)
                        continue;
-               if (t->ret < 0) {
-                       t->error_handler(t);
-                       goto again;
-               }
-               if (!(t->flags & PRE_EOF_IS_ERROR))
-                       continue;
-               t->ret = -E_PRE_EOF;
                t->error_handler(t);
                goto again;
        }
@@ -38,13 +31,6 @@ static void sched_post_select(struct sched *s)
                t->post_select(s, t);
                if (t->ret > 0 || !t->error_handler)
                        continue;
-               if (t->ret < 0) {
-                       t->error_handler(t);
-                       continue;
-               }
-               if (!(t->flags & POST_EOF_IS_ERROR))
-                       continue;
-               t->ret = -E_POST_EOF;
                t->error_handler(t);
        }
 }
@@ -72,7 +58,7 @@ again:
 
 void *register_task(struct task *t)
 {
-       PARA_INFO_LOG("registering task %p\n", t);
+       PARA_INFO_LOG("registering %s (%p)\n", t->status, t);
        if (t->pre_select) {
                PARA_DEBUG_LOG("pre_select: %p\n", &t->pre_select);
                if (t->flags & PRE_ADD_TAIL)
@@ -92,7 +78,7 @@ void *register_task(struct task *t)
 
 void unregister_task(struct task *t)
 {
-       PARA_INFO_LOG("unregistering task %p\n", t);
+       PARA_INFO_LOG("unregistering %s (%p)\n", t->status, t);
        if (t->pre_select)
                list_del(&t->pre_select_node);
        if (t->post_select)
diff --git a/sched.h b/sched.h
index 3de5e1cc9ef89f39ed02588d55270c918d097476..8ed4cd126f73e87cfb2aefc5385856200eedbedd 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -21,8 +21,6 @@ struct task {
 enum task_flags {
        PRE_ADD_TAIL = 1,
        POST_ADD_TAIL = 2,
-       PRE_EOF_IS_ERROR = 4,
-       POST_EOF_IS_ERROR = 8,
 };
 
 void *register_task(struct task *t);
diff --git a/stdin.c b/stdin.c
index 6b9c80988b365c76fe77e8a470004e2398739d5f..299c326e589ef5e00cc7d8279cacce2db5ef6d33 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -31,10 +31,7 @@ void stdin_post_select(struct sched *s, struct task *t)
                sit->loaded += ret;
                t->ret = ret;
        } else
-               t->ret = 0;
-       if (ret <= 0)
+               t->ret = -E_STDIN_EOF;
+       if (t->ret < 0)
                sit->eof = 1;
-       sprintf(t->status,
-               "%p stdin reader: loaded = %d, ret = %d",
-               sit, sit->loaded, t->ret);
 }
diff --git a/write.c b/write.c
index 7e6d47a56beb5e827ebbaa7d31cf2560f6b8f49f..3e5a97e8076e9a3d70bbb0d5386ee9b605a4cae7 100644 (file)
--- a/write.c
+++ b/write.c
@@ -74,7 +74,7 @@ static void check_wav_pre_select(struct sched *s, struct task *t)
        cwt->sample_rate = a[24] + (a[25] << 8) + (a[26] << 16) + (a[27] << 24);
        *cwt->loaded -= WAV_HEADER_LEN;
        memmove(cwt->buf, cwt->buf + WAV_HEADER_LEN, *cwt->loaded);
-       t->ret = 0;
+       t->ret = -E_WAV_HEADER_SUCCESS;
        PARA_INFO_LOG("channels: %d, sample_rate: %d\n", cwt->channels, cwt->sample_rate);
 }
 
@@ -83,11 +83,10 @@ static void initial_delay_pre_select(struct sched *s, struct task *t)
        struct initial_delay_task *idt = t->private_data;
        struct timeval diff;
 
-       PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret);
        t->ret = -E_NO_DELAY;
        if (!idt->start_time.tv_sec && !idt->start_time.tv_usec)
                return;
-       t->ret = 0; /* timeout */
+       t->ret = -E_DELAY_TIMEOUT;
        if (tv_diff(&s->now, &idt->start_time, &diff) > 0)
                return;
        t->ret = 1;
@@ -146,6 +145,8 @@ static struct writer_node_group *check_args(void)
                if (ret < 0)
                        goto out;
                wng->writer_nodes[i].writer = &writers[ret];
+               sprintf(wng->writer_nodes[i].task.status, "%s",
+                       writer_names[ret]);
        }
        ret = 1;
 out:
@@ -158,12 +159,14 @@ out:
 
 static void idt_error_handler(struct task *t)
 {
-       PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret);
        int ret;
+
+       PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
        wng->buf = sit.buf;
        wng->loaded = &sit.loaded;
        wng->eof = &sit.eof;
+       sprintf(wng->task.status, "%s", "writer node group");
        ret = wng_open(wng);
        if (ret < 0) {
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
@@ -173,29 +176,29 @@ static void idt_error_handler(struct task *t)
 
 static void cwt_error_handler(struct task *t)
 {
-       PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret);
-       if (t->ret < 0) {
+       if (t->ret != -E_NO_WAV_HEADER && t->ret != -E_WAV_HEADER_SUCCESS) {
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
-               if (t->ret != -E_NO_WAV_HEADER && t->ret != -E_PRE_EOF)
-                       exit(EXIT_FAILURE);
-               if (t->ret == -E_PRE_EOF) {
-                       conf.channels_arg = cwt.channels;
-                       conf.sample_rate_arg = cwt.sample_rate;
-               }
+               exit(EXIT_FAILURE);
        }
+       PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
+       if (t->ret == -E_WAV_HEADER_SUCCESS) {
+               conf.channels_arg = cwt.channels;
+               conf.sample_rate_arg = cwt.sample_rate;
+       }
        idt.task.pre_select = initial_delay_pre_select;
        idt.task.private_data = &idt;
        idt.task.error_handler = idt_error_handler;
-       idt.task.flags = PRE_EOF_IS_ERROR;
+       sprintf(idt.task.status, "initial_delay");
        register_task(&idt.task);
 }
 
 static void stdin_error_handler(struct task *t)
 {
        unregister_task(t);
-       PARA_INFO_LOG("task %p, ret: %d\n", t, t->ret);
-       if (t->ret < 0)
+       if (t->ret != -E_STDIN_EOF)
+               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
+       else
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
 }
 
@@ -217,8 +220,8 @@ int main(int argc, char *argv[])
        sit.task.pre_select = stdin_pre_select;
        sit.task.post_select = stdin_post_select;
        sit.task.error_handler = stdin_error_handler;
-       sit.task.flags = POST_EOF_IS_ERROR;
        sit.task.private_data = &sit;
+       sprintf(sit.task.status, "stdin reader");
        register_task(&sit.task);
 
        cwt.task.pre_select = check_wav_pre_select;
@@ -227,7 +230,7 @@ int main(int argc, char *argv[])
        cwt.buf = sit.buf;
        cwt.loaded = &sit.loaded;
        cwt.eof = &sit.eof;
-       cwt.task.flags = PRE_EOF_IS_ERROR;
+       sprintf(cwt.task.status, "check wav");
        register_task(&cwt.task);
 
        s.default_timeout.tv_sec = 1;
index 2cb0eafd45437d58fd79f988a6757fd41a69d7eb..7622c020024b7545353616f6acdc2431b1e742a5 100644 (file)
@@ -46,7 +46,7 @@ static void wng_post_select(struct sched *s, struct task *t)
        }
        *g->loaded -= min_written;
        if (!*g->loaded && *g->eof)
-               t->ret = 0;
+               t->ret = -E_WNG_EOF;
        else
                t->ret = 1;
        if (*g->loaded && min_written)
@@ -70,7 +70,6 @@ int wng_open(struct writer_node_group *g)
                wn->task.pre_select = wn->writer->pre_select;
                wn->task.post_select = wn->writer->post_select;
                wn->task.private_data = wn;
-               wn->task.flags = POST_EOF_IS_ERROR;
                register_task(&wn->task);
        }
        register_task(&g->task);
@@ -102,7 +101,7 @@ static void wng_error_handler(struct task *t)
 {
        struct writer_node_group *g = t->private_data;
 
-       PARA_INFO_LOG("%p: ret = %d\n", t, t->ret);
+       PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
        wng_close(g);
        wng_destroy(g);
@@ -118,7 +117,7 @@ struct writer_node_group *wng_new(unsigned num_writers)
        g->task.private_data = g;
        g->task.post_select = wng_post_select;
        g->task.error_handler = wng_error_handler;
-       g->task.flags = POST_ADD_TAIL | POST_EOF_IS_ERROR;
+       g->task.flags = POST_ADD_TAIL;
        return g;
 }
 
@@ -158,6 +157,8 @@ struct writer_node_group *setup_default_wng(void)
        else
                default_writer = 1;
        wng->writer_nodes[0].writer = &writers[default_writer];
+       sprintf(wng->writer_nodes[0].task.status, "%s",
+               writer_names[default_writer]);
        PARA_INFO_LOG("using default writer: %s\n",
                writer_names[default_writer]);
        return wng;