Kill fields buf, loaded and output_error of struct receiver node.
[paraslash.git] / write.c
diff --git a/write.c b/write.c
index c76b6c46e65a453fcd579d7cee2cb4408de45639..c64ecb636220c275a244162990c1756949387b1f 100644 (file)
--- a/write.c
+++ b/write.c
@@ -176,28 +176,25 @@ static void check_wav_post_select_btr(__a_unused struct sched *s, struct task *t
                PARA_NOTICE_LOG("wav header not found\n");
                cwt->state = CWS_NO_HEADER;
                sprintf(t->status, "check wav: no header");
-               goto consume;
+               goto out;
        }
        PARA_INFO_LOG("found wav header\n");
        cwt->state = CWS_HAVE_HEADER;
        sprintf(t->status, "check wav: have header");
        cwt->channels = (unsigned) a[22];
        cwt->samplerate = a[24] + (a[25] << 8) + (a[26] << 16) + (a[27] << 24);
-consume:
        PARA_INFO_LOG("channels: %d, sample rate: %d\n", cwt->channels, cwt->samplerate);
        btr_consume(cwt->btrn, WAV_HEADER_LEN);
 out:
-       if (sz) {
+       if (sz)
                btr_pushdown(cwt->btrn);
-               s->timeout.tv_sec = 0;
-               s->timeout.tv_usec = 1;
-       } else {
+       else {
                if (btr_no_parent(cwt->btrn))
                        t->error = -E_WRITE_EOF;
        }
 err:
        if (t->error < 0)
-               btr_del_node(cwt->btrn);
+               btr_remove_node(cwt->btrn);
 }
 
 static void initial_delay_pre_select(struct sched *s, struct task *t)
@@ -285,8 +282,9 @@ static int main_btr(struct sched *s)
 {
        int i, ret;
        struct check_wav_task_btr _cwt, *cwt = &_cwt;
-       struct writer_node **wns;
+       struct writer_node *wns;
 
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        sit.btrn = btr_new_node("stdin", NULL /* stdin has no parent */, NULL, NULL);
        stdin_set_defaults(&sit);
        register_task(&sit.task);
@@ -299,40 +297,39 @@ static int main_btr(struct sched *s)
        cwt->task.error = 0;
        register_task(&cwt->task);
 
-       wns = para_malloc(conf.writer_given * sizeof(*wns));
-
-       for (i = 0; i < conf.writer_given; i++) {
-               struct writer_node *wn = para_calloc(sizeof(*wn));
-               struct writer *w;
-               const char *name;
-
-               ret = -E_WRITE_SYNTAX;
-               wn->conf = check_writer_arg(conf.writer_arg[i],
-                       &wn->writer_num);
-               if (!wn->conf)
+       ret = -E_WRITE_SYNTAX;
+       if (!conf.writer_given) {
+               i = 0;
+               wns = para_calloc(sizeof(*wns));
+               ret = setup_writer_node(NULL, cwt->btrn, wns);
+               if (ret < 0)
                        goto out;
-               w = writers + wn->writer_num;
-               name = writer_names[wn->writer_num];
-               wn->btrn = btr_new_node(name, cwt->btrn, w->execute, wn);
-               sprintf(wn->task.status, "%s", name);
-               w->open(wn);
-               wn->task.post_select = w->post_select_btr;
-               wn->task.pre_select = w->pre_select_btr;
-               register_task(&wn->task);
-               wns[i] = wn;
+               i = 1;
+       } else {
+               wns = para_calloc(conf.writer_given * sizeof(*wns));
+               for (i = 0; i < conf.writer_given; i++) {
+                       ret = setup_writer_node(conf.writer_arg[i],
+                               cwt->btrn, wns + i);
+                       if (ret < 0)
+                               goto out;
+               }
        }
-       i--;
 
        s->default_timeout.tv_sec = 10;
        s->default_timeout.tv_usec = 50000;
        ret = schedule(s);
 out:
-       for (; i >= 0; i--) {
-               struct writer_node *wn = wns[i];
+       for (i--; i >= 0; i--) {
+               struct writer_node *wn = wns + i;
+               struct writer *w = writers + wn->writer_num;
+
+               w->close(wn);
+               btr_free_node(wn->btrn);
                free(wn->conf);
                free(wn);
        }
        free(wns);
+       btr_free_node(cwt->btrn);
        return ret;
 }