Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epggrab: fix the socket based module activation, fixes #3089
  • Loading branch information
perexg committed Sep 18, 2015
1 parent 990fe21 commit 9abbe4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
18 changes: 11 additions & 7 deletions src/epggrab.c
Expand Up @@ -140,8 +140,10 @@ static void _epggrab_load ( void )
HTSMSG_FOREACH(f, a) {
mod = epggrab_module_find_by_id(f->hmf_name);
map = htsmsg_field_get_map(f);
if (mod && map)
if (mod && map) {
idnode_load(&mod->idnode, map);
epggrab_activate_module(mod, mod->enabled);
}
}
}
htsmsg_destroy(m);
Expand All @@ -151,8 +153,10 @@ static void _epggrab_load ( void )
epggrab_conf.cron = strdup("# Default config (00:04 and 12:04 everyday)\n4 */12 * * *");
LIST_FOREACH(mod, &epggrab_modules, link) // enable all OTA by default
if (mod->type == EPGGRAB_OTA)
epggrab_enable_module(mod, 1);
epggrab_activate_module(mod, 1);
}

idnode_notify_changed(&epggrab_conf.idnode);

/* Load module config (channels) */
#if 0
Expand Down Expand Up @@ -306,14 +310,14 @@ const idclass_t epggrab_class = {
* Initialisation
* *************************************************************************/

int epggrab_enable_module ( epggrab_module_t *mod, int e )
int epggrab_activate_module ( epggrab_module_t *mod, int a )
{
int save = 0;
if (!mod) return 0;
if (mod->enable) {
save = mod->enable(mod, e);
} else if (e != mod->enabled) {
mod->enabled = e;
if (mod->activate) {
save = mod->activate(mod, a);
} else if (a != mod->active) {
mod->active = a;
save = 1;
}
return save;
Expand Down
7 changes: 4 additions & 3 deletions src/epggrab.h
Expand Up @@ -146,11 +146,12 @@ struct epggrab_module
const char *id; ///< Module identifier
const char *name; ///< Module name (for display)
int enabled; ///< Whether the module is enabled
int active; ///< Whether the module is active
int priority; ///< Priority of the module
epggrab_channel_tree_t *channels; ///< Channel list

/* Enable/Disable */
int (*enable) ( void *m, uint8_t e );
/* Activate */
int (*activate) ( void *m, int activate );

/* Free */
void (*done) ( void *m );
Expand Down Expand Up @@ -300,7 +301,7 @@ extern int epggrab_ota_running;
/*
* Set configuration
*/
int epggrab_enable_module ( epggrab_module_t *mod, int e );
int epggrab_activate_module ( epggrab_module_t *mod, int activate );
void epggrab_ota_set_cron ( void );
void epggrab_ota_trigger ( int secs );

Expand Down
37 changes: 20 additions & 17 deletions src/epggrab/module.c
Expand Up @@ -87,7 +87,7 @@ static const char *epggrab_mod_class_title(idnode_t *self, const char *lang)
static void epggrab_mod_class_save(idnode_t *self)
{
epggrab_module_t *mod = (epggrab_module_t *)self;
epggrab_enable_module(mod, mod->enabled);
epggrab_activate_module(mod, mod->enabled);
epggrab_save();
}

Expand Down Expand Up @@ -367,6 +367,7 @@ static void
epggrab_module_int_done( void *m )
{
epggrab_module_int_t *mod = m;
mod->active = 0;
free((char *)mod->path);
mod->path = NULL;
}
Expand Down Expand Up @@ -518,7 +519,7 @@ epggrab_module_done_socket( void *m )
int sock;

assert(mod->type == EPGGRAB_EXT);
mod->enabled = 0;
mod->active = 0;
sock = mod->sock;
mod->sock = 0;
shutdown(sock, SHUT_RDWR);
Expand All @@ -534,23 +535,25 @@ epggrab_module_done_socket( void *m )
}

/*
* Enable socket module
* Activate socket module
*/
static int
epggrab_module_enable_socket ( void *m, uint8_t e )
epggrab_module_activate_socket ( void *m, int a )
{
pthread_attr_t tattr;
struct sockaddr_un addr;
epggrab_module_ext_t *mod = (epggrab_module_ext_t*)m;
const char *path;
assert(mod->type == EPGGRAB_EXT);

/* Ignore */
if ( mod->enabled == e ) return 0;
if ( mod->active == a ) return 0;

/* Disable */
if (!e) {
if (!a) {
path = strdup(mod->path);
epggrab_module_done_socket(m);

mod->path = path;
/* Enable */
} else {
unlink(mod->path); // just in case!
Expand Down Expand Up @@ -579,7 +582,7 @@ epggrab_module_enable_socket ( void *m, uint8_t e )

tvhlog(LOG_DEBUG, mod->id, "starting socket thread");
pthread_attr_init(&tattr);
mod->enabled = 1;
mod->active = 1;
tvhthread_create(&mod->tid, &tattr, _epggrab_socket_thread, mod);
}
return 1;
Expand Down Expand Up @@ -609,9 +612,9 @@ epggrab_module_ext_t *epggrab_module_ext_create
channels);

/* Local */
skel->type = EPGGRAB_EXT;
skel->enable = epggrab_module_enable_socket;
skel->done = epggrab_module_done_socket;
skel->type = EPGGRAB_EXT;
skel->activate = epggrab_module_activate_socket;
skel->done = epggrab_module_done_socket;

return skel;
}
Expand All @@ -634,11 +637,11 @@ epggrab_module_ota_t *epggrab_module_ota_create
id, name, priority, channels);

/* Setup */
skel->type = EPGGRAB_OTA;
skel->enable = ops->enable;
skel->start = ops->start;
skel->done = ops->done;
skel->tune = ops->tune;
skel->type = EPGGRAB_OTA;
skel->activate = ops->activate;
skel->start = ops->start;
skel->done = ops->done;
skel->tune = ops->tune;
//TAILQ_INIT(&skel->muxes);

return skel;
Expand Down
10 changes: 5 additions & 5 deletions src/epggrab/private.h
Expand Up @@ -91,11 +91,11 @@ epggrab_module_ext_t *epggrab_module_ext_create
* *************************************************************************/

typedef struct epggrab_ota_module_ops {
int (*start) (epggrab_ota_map_t *map, struct mpegts_mux *mm);
int (*enable) (void *m, uint8_t e );
void (*done) (void *m);
int (*tune) (epggrab_ota_map_t *map, epggrab_ota_mux_t *om,
struct mpegts_mux *mm);
int (*start) (epggrab_ota_map_t *map, struct mpegts_mux *mm);
int (*activate) (void *m, int e);
void (*done) (void *m);
int (*tune) (epggrab_ota_map_t *map, epggrab_ota_mux_t *om,
struct mpegts_mux *mm);
} epggrab_ota_module_ops_t;

epggrab_module_ota_t *epggrab_module_ota_create
Expand Down

0 comments on commit 9abbe4c

Please sign in to comment.