Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
service mapping: remeber the mapping configuration, use hardcoded con…
…fig for bouquets
  • Loading branch information
perexg committed Nov 12, 2015
1 parent abad26e commit 71cfeb0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/bouquet.c
Expand Up @@ -268,6 +268,13 @@ bouquet_map_channel(bouquet_t *bq, service_t *t)
{
channel_t *ch = NULL;
idnode_list_mapping_t *ilm;
static service_mapper_conf_t sm_conf = {
.check_availability = 0,
.encrypted = 1,
.merge_same_name = 0,
.provider_tags = 0,
.network_tags = 0
};

if (!t->s_enabled)
return;
Expand All @@ -283,7 +290,7 @@ bouquet_map_channel(bouquet_t *bq, service_t *t)
if (((channel_t *)ilm->ilm_in2)->ch_bouquet == bq)
break;
if (!ilm)
ch = service_mapper_process(t, bq);
ch = service_mapper_process(&sm_conf, t, bq);
else
ch = (channel_t *)ilm->ilm_in2;
if (ch && bq->bq_chtag)
Expand Down
1 change: 0 additions & 1 deletion src/service.h
Expand Up @@ -346,7 +346,6 @@ typedef struct service {
* Service mapping, see service_mapper.c form details
*/
int s_sm_onqueue;
TAILQ_ENTRY(service) s_sm_link;

/**
* Pending save.
Expand Down
50 changes: 33 additions & 17 deletions src/service_mapper.c
Expand Up @@ -34,10 +34,15 @@
#include "bouquet.h"
#include "api.h"

typedef struct service_mapper_item {
TAILQ_ENTRY(service_mapper_item) link;
service_t *s;
service_mapper_conf_t conf;
} service_mapper_item_t;

static service_mapper_status_t service_mapper_stat;
static pthread_cond_t service_mapper_cond;
static struct service_queue service_mapper_queue;
static service_mapper_conf_t service_mapper_conf;
static TAILQ_HEAD(, service_mapper_item) service_mapper_queue;

static void *service_mapper_thread ( void *p );

Expand Down Expand Up @@ -77,15 +82,13 @@ void
service_mapper_start ( const service_mapper_conf_t *conf, htsmsg_t *uuids )
{
int e, tr, qd = 0;
service_mapper_item_t *smi;
service_t *s;

/* Reset stat counters */
if (TAILQ_EMPTY(&service_mapper_queue))
service_mapper_reset_stats();

/* Store config */
service_mapper_conf = *conf;

/* Check each service */
TAILQ_FOREACH(s, &service_all, s_all_link) {
if (uuids) {
Expand Down Expand Up @@ -130,13 +133,16 @@ service_mapper_start ( const service_mapper_conf_t *conf, htsmsg_t *uuids )
if (conf->check_availability) {
tvhtrace("service_mapper", " queue for checking");
qd = 1;
TAILQ_INSERT_TAIL(&service_mapper_queue, s, s_sm_link);
smi = malloc(sizeof(*smi));
smi->s = s;
smi->conf = *conf;
TAILQ_INSERT_TAIL(&service_mapper_queue, smi, link);
s->s_sm_onqueue = 1;

/* Process */
} else {
tvhtrace("service_mapper", " process");
service_mapper_process(s, NULL);
service_mapper_process(conf, s, NULL);
}
}

Expand All @@ -153,10 +159,11 @@ service_mapper_start ( const service_mapper_conf_t *conf, htsmsg_t *uuids )
void
service_mapper_stop ( void )
{
service_t *s;
while ((s = TAILQ_FIRST(&service_mapper_queue))) {
service_mapper_item_t *smi;
while ((smi = TAILQ_FIRST(&service_mapper_queue))) {
service_mapper_stat.total--;
service_mapper_remove(s);
TAILQ_REMOVE(&service_mapper_queue, smi, link);
free(smi);
}

/* Notify */
Expand All @@ -169,8 +176,14 @@ service_mapper_stop ( void )
void
service_mapper_remove ( service_t *s )
{
service_mapper_item_t *smi;

if (s->s_sm_onqueue) {
TAILQ_REMOVE(&service_mapper_queue, s, s_sm_link);
TAILQ_FOREACH(smi, &service_mapper_queue, link)
if (smi->s == s) break;
assert(smi);
TAILQ_REMOVE(&service_mapper_queue, smi, link);
free(smi);
s->s_sm_onqueue = 0;
}

Expand Down Expand Up @@ -206,7 +219,8 @@ service_mapper_create ( idnode_t *s, idnode_t *c, void *origin )
* Process a service
*/
channel_t *
service_mapper_process ( service_t *s, bouquet_t *bq )
service_mapper_process
( const service_mapper_conf_t *conf, service_t *s, bouquet_t *bq )
{
channel_t *chn = NULL;
const char *name, *tagname;
Expand All @@ -228,7 +242,7 @@ service_mapper_process ( service_t *s, bouquet_t *bq )

/* Find existing channel */
name = service_get_channel_name(s);
if (!bq && service_mapper_conf.merge_same_name && name && *name)
if (!bq && conf->merge_same_name && name && *name)
chn = channel_find_by_name(name);
if (!chn) {
chn = channel_create(NULL, NULL, NULL);
Expand Down Expand Up @@ -258,12 +272,12 @@ service_mapper_process ( service_t *s, bouquet_t *bq )
channel_tag_map(channel_tag_find_by_name(tagname, 1), chn, chn);

/* Provider */
if (service_mapper_conf.provider_tags)
if (conf->provider_tags)
if ((prov = s->s_provider_name(s)))
channel_tag_map(channel_tag_find_by_name(prov, 1), chn, chn);

/* Network */
if (service_mapper_conf.network_tags) {
if (conf->network_tags) {
source_info_t si;
s->s_setsourceinfo(s, &si);
channel_tag_map(channel_tag_find_by_name(si.si_network, 1), chn, chn);
Expand Down Expand Up @@ -293,6 +307,7 @@ static void *
service_mapper_thread ( void *aux )
{
service_t *s;
service_mapper_item_t *smi;
profile_chain_t prch;
th_subscription_t *sub;
int run, working = 0;
Expand All @@ -309,7 +324,7 @@ service_mapper_thread ( void *aux )
while (tvheadend_running) {

/* Wait for work */
while (!(s = TAILQ_FIRST(&service_mapper_queue))) {
while (!(smi = TAILQ_FIRST(&service_mapper_queue))) {
if (working) {
working = 0;
tvhinfo("service_mapper", "idle");
Expand All @@ -320,6 +335,7 @@ service_mapper_thread ( void *aux )
}
if (!tvheadend_running)
break;
s = smi->s;
service_mapper_remove(s);

if (!working) {
Expand Down Expand Up @@ -396,7 +412,7 @@ service_mapper_thread ( void *aux )
tvhinfo("service_mapper", "%s: failed [err %s]", s->s_nicename, err);
service_mapper_stat.fail++;
} else
service_mapper_process(s, NULL);
service_mapper_process(&smi->conf, s, NULL);

service_unref(s);
service_mapper_stat.active = NULL;
Expand Down
13 changes: 7 additions & 6 deletions src/service_mapper.h
Expand Up @@ -23,11 +23,11 @@ struct bouquet;

typedef struct service_mapper_conf
{
int check_availability; ///< Check service is receivable
int encrypted; ///< Include encrypted services
int merge_same_name; ///< Merge entries with the same name
int provider_tags; ///< Create tags based on provider name
int network_tags; ///< Create tags based on network name (useful for multi adapter equipments)
uint8_t check_availability; ///< Check service is receivable
uint8_t encrypted; ///< Include encrypted services
uint8_t merge_same_name; ///< Merge entries with the same name
uint8_t provider_tags; ///< Create tags based on provider name
uint8_t network_tags; ///< Create tags based on network name (useful for multi adapter equipments)
} service_mapper_conf_t;

typedef struct service_mapper_status
Expand Down Expand Up @@ -62,7 +62,8 @@ int service_mapper_link ( struct service *s, struct channel *c, void *origin
int service_mapper_create ( idnode_t *s, idnode_t *c, void *origin );

// Process one service
struct channel *service_mapper_process ( struct service *s, struct bouquet *bq );
struct channel *service_mapper_process
( const service_mapper_conf_t *conf, struct service *s, struct bouquet *bq );

// Resets the stat counters
void service_mapper_reset_stats ( void );
Expand Down

0 comments on commit 71cfeb0

Please sign in to comment.