Convert receivers to lopsub.
[paraslash.git] / play.c
diff --git a/play.c b/play.c
index 1ab4010..4dab1ca 100644 (file)
--- a/play.c
+++ b/play.c
@@ -11,6 +11,7 @@
 #include <inttypes.h>
 #include <lopsub.h>
 
 #include <inttypes.h>
 #include <lopsub.h>
 
+#include "recv_cmd.lsg.h"
 #include "para.h"
 #include "list.h"
 #include "play.cmdline.h"
 #include "para.h"
 #include "list.h"
 #include "play.cmdline.h"
@@ -110,14 +111,6 @@ struct play_command_info {
                .handler = com_ ## _cmd \
        };
 
                .handler = com_ ## _cmd \
        };
 
-/* Activate the afh receiver. */
-extern void afh_recv_init(struct receiver *r);
-#undef AFH_RECEIVER
-/** Initialization code for a receiver struct. */
-#define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
-/** This expands to the array of all receivers. */
-DEFINE_RECEIVER_ARRAY;
-
 static int loglevel = LL_WARNING;
 
 /** The log function which writes log messages to stderr. */
 static int loglevel = LL_WARNING;
 
 /** The log function which writes log messages to stderr. */
@@ -131,22 +124,9 @@ static struct play_args_info conf;
 
 static struct sched sched = {.max_fileno = 0};
 static struct play_task play_task;
 
 static struct sched sched = {.max_fileno = 0};
 static struct play_task play_task;
-static struct receiver *afh_recv;
 
 
-static void check_afh_receiver_or_die(void)
-{
-       int i;
-
-       FOR_EACH_RECEIVER(i) {
-               struct receiver *r = receivers + i;
-               if (strcmp(r->name, "afh"))
-                       continue;
-               afh_recv = r;
-               return;
-       }
-       PARA_EMERG_LOG("fatal: afh receiver not found\n");
-       exit(EXIT_FAILURE);
-}
+#define AFH_RECV_CMD (lls_cmd(LSG_RECV_CMD_CMD_AFH, recv_cmd_suite))
+#define AFH_RECV ((struct receiver *)lls_user_data(AFH_RECV_CMD))
 
 __noreturn static void print_help_and_die(void)
 {
 
 __noreturn static void print_help_and_die(void)
 {
@@ -242,12 +222,13 @@ static long unsigned get_play_time(struct play_task *pt)
        return result;
 }
 
        return result;
 }
 
+
 static void wipe_receiver_node(struct play_task *pt)
 {
        PARA_NOTICE_LOG("cleaning up receiver node\n");
        btr_remove_node(&pt->rn.btrn);
 static void wipe_receiver_node(struct play_task *pt)
 {
        PARA_NOTICE_LOG("cleaning up receiver node\n");
        btr_remove_node(&pt->rn.btrn);
-       afh_recv->close(&pt->rn);
-       afh_recv->free_config(pt->rn.conf);
+       AFH_RECV->close(&pt->rn);
+       lls_free_parse_result(pt->rn.lpr, AFH_RECV_CMD);
        memset(&pt->rn, 0, sizeof(struct receiver_node));
 }
 
        memset(&pt->rn, 0, sizeof(struct receiver_node));
 }
 
@@ -320,25 +301,26 @@ static void shuffle(char **base, size_t num)
 static struct btr_node *new_recv_btrn(struct receiver_node *rn)
 {
        return btr_new_node(&(struct btr_node_description)
 static struct btr_node *new_recv_btrn(struct receiver_node *rn)
 {
        return btr_new_node(&(struct btr_node_description)
-               EMBRACE(.name = afh_recv->name, .context = rn,
-                       .handler = afh_recv->execute));
+               EMBRACE(.name = lls_command_name(AFH_RECV_CMD), .context = rn,
+                       .handler = AFH_RECV->execute));
 }
 
 static int open_new_file(struct play_task *pt)
 {
        int ret;
 }
 
 static int open_new_file(struct play_task *pt)
 {
        int ret;
-       char *tmp, *path = conf.inputs[pt->next_file], *afh_recv_conf[] =
-               {"play", "-f", path, "-b", "0", NULL};
+       char *tmp, *path = conf.inputs[pt->next_file], *errctx = NULL,
+               *argv[] = {"play", "-f", path, "-b", "0", NULL};
 
        PARA_NOTICE_LOG("next file: %s\n", path);
        wipe_receiver_node(pt);
        pt->start_chunk = 0;
        pt->rn.btrn = new_recv_btrn(&pt->rn);
 
        PARA_NOTICE_LOG("next file: %s\n", path);
        wipe_receiver_node(pt);
        pt->start_chunk = 0;
        pt->rn.btrn = new_recv_btrn(&pt->rn);
-       pt->rn.conf = afh_recv->parse_config(ARRAY_SIZE(afh_recv_conf) - 1,
-               afh_recv_conf);
-       assert(pt->rn.conf);
-       pt->rn.receiver = afh_recv;
-       ret = afh_recv->open(&pt->rn);
+       ret = lls(lls_parse(ARRAY_SIZE(argv) - 1, argv, AFH_RECV_CMD,
+               &pt->rn.lpr, &errctx));
+       free(tmp);
+       assert(ret >= 0);
+       pt->rn.receiver = AFH_RECV;
+       ret = AFH_RECV->open(&pt->rn);
        if (ret < 0) {
                PARA_ERROR_LOG("could not open %s\n", path);
                goto fail;
        if (ret < 0) {
                PARA_ERROR_LOG("could not open %s\n", path);
                goto fail;
@@ -420,9 +402,9 @@ static int load_file(struct play_task *pt)
        /* success, register tasks */
        pt->rn.task = task_register(
                &(struct task_info) {
        /* success, register tasks */
        pt->rn.task = task_register(
                &(struct task_info) {
-                       .name = afh_recv->name,
-                       .pre_select = afh_recv->pre_select,
-                       .post_select = afh_recv->post_select,
+                       .name = lls_command_name(AFH_RECV_CMD),
+                       .pre_select = AFH_RECV->pre_select,
+                       .post_select = AFH_RECV->post_select,
                        .context = &pt->rn
                }, &sched);
        sprintf(buf, "%s decoder", af);
                        .context = &pt->rn
                }, &sched);
        sprintf(buf, "%s decoder", af);
@@ -1287,8 +1269,7 @@ int main(int argc, char *argv[])
        parse_config_or_die(argc, argv);
        if (conf.inputs_num == 0)
                print_help_and_die();
        parse_config_or_die(argc, argv);
        if (conf.inputs_num == 0)
                print_help_and_die();
-       check_afh_receiver_or_die();
-
+       AFH_RECV->init();
        session_open(pt);
        if (conf.randomize_given)
                shuffle(conf.inputs, conf.inputs_num);
        session_open(pt);
        if (conf.randomize_given)
                shuffle(conf.inputs, conf.inputs_num);