From 8ffd24c72720510269eb3eb91fd21e950daaedcd Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Fri, 11 Oct 2013 16:20:05 +0100 Subject: [PATCH] channel: make channel number like name This allows user configuration which in the event of no setting will fallback to information automatically determined from the services. I have also updated the name stuff and simplified it a bit (with one minor change to idnode to support). --- src/channels.c | 37 ++++++++++++++----------------------- src/channels.h | 4 ++++ src/htsp_server.c | 2 +- src/idnode.c | 9 +++++++-- src/service.c | 10 ++++++++++ src/service.h | 1 + src/webui/statedump.c | 2 +- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/channels.c b/src/channels.c index 5d801dc0..e9b76cb2 100644 --- a/src/channels.c +++ b/src/channels.c @@ -197,10 +197,12 @@ channel_class_get_name ( void *p ) return &s; } -static int -channel_class_set_name ( void *o, const void *p ) +static const void * +channel_class_get_number ( void *p ) { - return channel_set_name(o, p); + static int i; + i = channel_get_number(p); + return &i; } const idclass_t channel_class = { @@ -224,13 +226,13 @@ const idclass_t channel_class = { .name = "Name", .off = offsetof(channel_t, ch_name), .get = channel_class_get_name, - .set = channel_class_set_name, }, { .type = PT_INT, .id = "number", .name = "Number", .off = offsetof(channel_t, ch_number), + .get = channel_class_get_number, }, { .type = PT_STR, @@ -380,8 +382,7 @@ channel_get_name ( channel_t *ch ) static const char *blank = ""; const char *s; channel_service_mapping_t *csm; - - if (ch->ch_name) return ch->ch_name; + if (ch->ch_name && *ch->ch_name) return ch->ch_name; LIST_FOREACH(csm, &ch->ch_services, csm_chn_link) if ((s = service_get_channel_name(csm->csm_svc))) return s; @@ -389,24 +390,14 @@ channel_get_name ( channel_t *ch ) } int -channel_set_name ( channel_t *ch, const char *s ) +channel_get_number ( channel_t *ch ) { - if (!s || !*s) { - if (ch->ch_name) { - free(ch->ch_name); - ch->ch_name = NULL; - } - return 1; // NOTE: we always return this, else UI gets confused - // if user see's generated name clears to "" and tries to set - // and nosave is returned (so UI doesn't update) - } - - if (!ch->ch_name || strcmp(ch->ch_name, s)) { - free(ch->ch_name); - ch->ch_name = strdup(s); - return 1; - } - + int n; + channel_service_mapping_t *csm; + if (ch->ch_number) return ch->ch_number; + LIST_FOREACH(csm, &ch->ch_services, csm_chn_link) + if ((n = service_get_channel_number(csm->csm_svc))) + return n; return 0; } diff --git a/src/channels.h b/src/channels.h index f4426ee0..f22053d9 100644 --- a/src/channels.h +++ b/src/channels.h @@ -149,6 +149,10 @@ void channel_save(channel_t *ch); const char *channel_get_name ( channel_t *ch ); int channel_set_name ( channel_t *ch, const char *s ); +int channel_get_number ( channel_t *ch ); + +const char *channel_get_icon ( channel_t *ch ); + #define channel_get_uuid(ch) idnode_uuid_as_str(&ch->ch_id) #define channel_get_id(ch) idnode_get_short_uuid((&ch->ch_id)) diff --git a/src/htsp_server.c b/src/htsp_server.c index c4192fa8..ea074e5d 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -514,7 +514,7 @@ htsp_build_channel(channel_t *ch, const char *method, htsp_connection_t *htsp) htsmsg_t *services = htsmsg_create_list(); htsmsg_add_u32(out, "channelId", channel_get_id(ch)); - htsmsg_add_u32(out, "channelNumber", ch->ch_number); + htsmsg_add_u32(out, "channelNumber", channel_get_number(ch)); htsmsg_add_str(out, "channelName", channel_get_name(ch)); if(ch->ch_icon != NULL) { diff --git a/src/idnode.c b/src/idnode.c index f96e4da8..abe39042 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -711,10 +711,15 @@ idnode_write0 ( idnode_t *self, htsmsg_t *c, int optmask, int dosave ) int save = 0; const idclass_t *idc = self->in_class; save = idnode_class_write_values(self, idc, c, optmask); - if (save && dosave) { + if (save && dosave) idnode_savefn(self); + if (dosave) idnode_notify(self, NULL, 0, 0); - } + // Note: always output event if "dosave", reason is that UI updates on + // these, but there are some subtle cases where it will expect + // an update and not get one. This include fields being set for + // which there is user-configurable value and auto fallback so + // the UI state might not atually reflect the user config return save; } diff --git a/src/service.c b/src/service.c index d513ceb0..c10933af 100644 --- a/src/service.c +++ b/src/service.c @@ -1194,6 +1194,16 @@ service_get_channel_name ( service_t *s ) return r; } +/* + * Get number for service + */ +int +service_get_channel_number ( service_t *s ) +{ + if (s->s_channel_number) return s->s_channel_number(s); + return 0; +} + /** * Get the encryption CAID from a service * only the first CA stream in a service is returned diff --git a/src/service.h b/src/service.h index e353f564..7afc3ca1 100644 --- a/src/service.h +++ b/src/service.h @@ -526,5 +526,6 @@ void service_save ( service_t *s, htsmsg_t *c ); void sort_elementary_streams(service_t *t); const char *service_get_channel_name (service_t *s); +int service_get_channel_number (service_t *s); #endif // SERVICE_H__ diff --git a/src/webui/statedump.c b/src/webui/statedump.c index 4ecdf70c..79dfc0fd 100644 --- a/src/webui/statedump.c +++ b/src/webui/statedump.c @@ -65,7 +65,7 @@ dumpchannels(htsbuf_queue_t *hq) " icon = %s\n\n", ch->ch_refcount, ch->ch_zombie, - ch->ch_number, + channel_get_number(ch), ch->ch_icon ?: ""); } }