From 09bf3971a58fd1044c145b25429c4886966c7d2a Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 14 May 2009 08:34:06 +0200 Subject: [PATCH] struct writer_node: Store the number of the writer rather than a pointer. This makes it easier to get the name of the writer from the writer_node struct. --- audiod.c | 10 +++++----- write.c | 2 +- write.h | 4 ++-- write_common.c | 19 ++++++++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/audiod.c b/audiod.c index ce5bc551..eb3b200a 100644 --- a/audiod.c +++ b/audiod.c @@ -49,8 +49,8 @@ struct audio_format_info { void **filter_conf; /** the number of filters that should be activated for this audio format */ unsigned int num_writers; - /** pointer to the array of writers to be activated */ - struct writer **writers; + /** Array of writer numbers to be activated. */ + int *writer_nums; /** pointer to the array of writer configurations */ void **writer_conf; /** do not start receiver/filters/writer before this time */ @@ -434,7 +434,7 @@ static void open_writers(int slot_num) } for (i = 0; i < a->num_writers; i++) { s->wng->writer_nodes[i].conf = a->writer_conf[i]; - s->wng->writer_nodes[i].writer = a->writers[i]; + s->wng->writer_nodes[i].writer_num = a->writer_nums[i]; } ret = wng_open(s->wng); if (ret < 0) @@ -689,7 +689,7 @@ static int parse_writer_args(void) FOR_EACH_AUDIO_FORMAT(i) { a = &afi[i]; a->writer_conf = para_malloc(nw * sizeof(void *)); - a->writers = para_malloc(nw * sizeof(struct writer *)); + a->writer_nums = para_malloc(nw * sizeof(int)); a->num_writers = 0; } for (i = 0; i < conf.writer_given; i++) { @@ -705,7 +705,7 @@ static int parse_writer_args(void) ret = writer_num; goto out; } - a->writers[nw] = &writers[writer_num]; + a->writer_nums[nw] = writer_num; a->writer_conf[nw] = wconf; PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[ret], nw, writer_names[writer_num]); diff --git a/write.c b/write.c index cc1f716f..c12736a6 100644 --- a/write.c +++ b/write.c @@ -153,7 +153,7 @@ static struct writer_node_group *check_args(void) conf.writer_arg[i], &writer_num); if (!g->writer_nodes[i].conf) goto out; - g->writer_nodes[i].writer = &writers[writer_num]; + g->writer_nodes[i].writer_num = writer_num; } ret = 1; out: diff --git a/write.h b/write.h index 365c237b..1f316fc0 100644 --- a/write.h +++ b/write.h @@ -13,8 +13,8 @@ enum writer_enum {WRITER_ENUM}; * Describes one running instance of a writer. */ struct writer_node { - /** Points to the writer structure associated with this node. */ - struct writer *writer; /* FIXME: Should better be only the number. */ + /** The number of this writer. */ + int writer_num; /** Writer-specific data. */ void *private_data; /** Pointer to the group this node belongs to. */ diff --git a/write_common.c b/write_common.c index 316c87ef..476df8f0 100644 --- a/write_common.c +++ b/write_common.c @@ -27,9 +27,10 @@ static void wng_pre_select(__a_unused struct sched *s, struct task *t) FOR_EACH_WRITER_NODE(i, g) { struct writer_node *wn = &g->writer_nodes[i]; - if (!wn->writer->pre_select) + struct writer *w = writers + wn->writer_num; + if (!w->pre_select) continue; - t->error = wn->writer->pre_select(s, wn); + t->error = w->pre_select(s, wn); if (t->error < 0) return; } @@ -43,7 +44,8 @@ static void wng_post_select(struct sched *s, struct task *t) FOR_EACH_WRITER_NODE(i, g) { struct writer_node *wn = &g->writer_nodes[i]; - t->error = wn->writer->post_select(s, wn); + struct writer *w = writers + wn->writer_num; + t->error = w->post_select(s, wn); if (t->error < 0) return; if (!i) @@ -84,8 +86,9 @@ int wng_open(struct writer_node_group *g) PARA_NOTICE_LOG("opening wng %p with %d writer(s)\n", g, g->num_writers); FOR_EACH_WRITER_NODE(i, g) { struct writer_node *wn = &g->writer_nodes[i]; + struct writer *w = writers + wn->writer_num; wn->wng = g; - ret = wn->writer->open(wn); + ret = w->open(wn); if (ret < 0) goto err_out; } @@ -97,7 +100,8 @@ err_out: PARA_ERROR_LOG("%s\n", para_strerror(-ret)); while (i > 0) { struct writer_node *wn = &g->writer_nodes[--i]; - wn->writer->close(wn); + struct writer *w = writers + wn->writer_num; + w->close(wn); } free(g->writer_nodes); g->num_writers = 0; @@ -121,7 +125,8 @@ void wng_close(struct writer_node_group *g) PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers); FOR_EACH_WRITER_NODE(i, g) { struct writer_node *wn = &g->writer_nodes[i]; - wn->writer->close(wn); + struct writer *w = writers + wn->writer_num; + w->close(wn); } free(g->writer_nodes); free(g); @@ -207,7 +212,7 @@ void *check_writer_arg(const char *wa, int *writer_num) struct writer_node_group *setup_default_wng(void) { struct writer_node_group *wng = wng_new(1); - wng->writer_nodes[0].writer = &writers[DEFAULT_WRITER]; + wng->writer_nodes[0].writer_num = DEFAULT_WRITER; PARA_INFO_LOG("using default writer: %s %p\n", writer_names[DEFAULT_WRITER], writers[DEFAULT_WRITER].parse_config); wng->writer_nodes[0].conf = writers[DEFAULT_WRITER].parse_config(""); -- 2.39.2