From ce7bad8bba988538740c9ce314ce19ffc266d39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sun, 2 Dec 2007 16:32:12 +0000 Subject: [PATCH] Use TAILQ for channels in the per-group list --- channels.c | 22 ++++++---------------- htmlui.c | 4 ++-- tvhead.h | 8 +++----- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/channels.c b/channels.c index a4b3994c..4bda81c9 100644 --- a/channels.c +++ b/channels.c @@ -41,7 +41,6 @@ struct th_channel_list channels; struct th_transport_list all_transports; int nchannels; -int grouporder = 1000; struct th_channel_group_queue all_channel_groups; @@ -49,15 +48,6 @@ th_channel_group_t *defgroup; void scanner_init(void); -/** - * - */ -static int -ch_order_cmp(th_channel_t *a, th_channel_t *b) -{ - return a->ch_order - b->ch_order; -} - /** * */ @@ -77,7 +67,8 @@ channel_group_find(const char *name, int create) tcg->tcg_name = strdup(name); tcg->tcg_tag = tag_get(); - tcg->tcg_order = grouporder++; + TAILQ_INIT(&tcg->tcg_channels); + TAILQ_INSERT_HEAD(&all_channel_groups, tcg, tcg_global_link); return tcg; } @@ -92,10 +83,10 @@ void channel_set_group(th_channel_t *ch, th_channel_group_t *tcg) { if(ch->ch_group != NULL) - LIST_REMOVE(ch, ch_group_link); + TAILQ_REMOVE(&ch->ch_group->tcg_channels, ch, ch_group_link); ch->ch_group = tcg; - LIST_INSERT_SORTED(&tcg->tcg_channels, ch, ch_group_link, ch_order_cmp); + TAILQ_INSERT_TAIL(&tcg->tcg_channels, ch, ch_group_link); } /** @@ -109,7 +100,7 @@ channel_group_destroy(th_channel_group_t *tcg) if(defgroup == tcg) return; - while((ch = LIST_FIRST(&tcg->tcg_channels)) != NULL) { + while((ch = TAILQ_FIRST(&tcg->tcg_channels)) != NULL) { channel_set_group(ch, defgroup); } @@ -158,8 +149,7 @@ channel_find(const char *name, int create) ch->ch_index = nchannels; TAILQ_INIT(&ch->ch_epg_events); - ch->ch_order = nchannels + 1000; - LIST_INSERT_SORTED(&channels, ch, ch_global_link, ch_order_cmp); + LIST_INSERT_HEAD(&channels, ch, ch_global_link); channel_set_group(ch, defgroup); diff --git a/htmlui.c b/htmlui.c index b9a54da3..a7c35544 100644 --- a/htmlui.c +++ b/htmlui.c @@ -440,7 +440,7 @@ page_root(http_connection_t *hc, const char *remain, void *opaque) box_bottom(&tq); tcp_qprintf(&tq, "
"); - LIST_FOREACH(ch, &tcg->tcg_channels, ch_group_link) { + TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) { box_top(&tq, "box"); tcp_qprintf(&tq, "
"); @@ -1276,7 +1276,7 @@ page_chgroups(http_connection_t *hc, const char *remain, void *opaque) tcp_qprintf(&tq, "
"); cnt = 0; - LIST_FOREACH(ch, &tcg->tcg_channels, ch_group_link) + TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) cnt++; tcp_qprintf(&tq, "%s (%d channels)
", tcg->tcg_name, cnt); diff --git a/tvhead.h b/tvhead.h index 2aa15404..67aead27 100644 --- a/tvhead.h +++ b/tvhead.h @@ -69,6 +69,7 @@ typedef struct dtimer { LIST_HEAD(th_subscription_list, th_subscription); LIST_HEAD(th_channel_list, th_channel); +TAILQ_HEAD(th_channel_queue, th_channel); TAILQ_HEAD(th_channel_group_queue, th_channel_group); LIST_HEAD(th_dvb_adapter_list, th_dvb_adapter); LIST_HEAD(th_v4l_adapter_list, th_v4l_adapter); @@ -622,9 +623,8 @@ typedef struct th_channel_group { TAILQ_ENTRY(th_channel_group) tcg_global_link; const char *tcg_name; - struct th_channel_list tcg_channels; + struct th_channel_queue tcg_channels; int tcg_tag; - int tcg_order; int tcg_cant_delete_me; } th_channel_group_t; @@ -637,9 +637,7 @@ typedef struct th_channel { LIST_ENTRY(th_channel) ch_global_link; - int ch_order; - - LIST_ENTRY(th_channel) ch_group_link; + TAILQ_ENTRY(th_channel) ch_group_link; th_channel_group_t *ch_group; LIST_HEAD(, th_transport) ch_transports;