Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epggrab: module - fix the save/load procedure
  • Loading branch information
perexg committed Oct 25, 2015
1 parent af4d958 commit 3153614
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/epggrab.c
Expand Up @@ -401,6 +401,7 @@ void epggrab_done ( void )
pthread_mutex_lock(&global_lock);
epggrab_channel_flush(mod, 0);
free((void *)mod->id);
free((void *)mod->saveid);
free((void *)mod->name);
free(mod);
}
Expand Down
1 change: 1 addition & 0 deletions src/epggrab.h
Expand Up @@ -142,6 +142,7 @@ struct epggrab_module
EPGGRAB_EXT,
} type; ///< Grabber type
const char *id; ///< Module identifier
const char *saveid; ///< Module save identifier
const char *name; ///< Module name (for display)
int enabled; ///< Whether the module is enabled
int active; ///< Whether the module is active
Expand Down
28 changes: 25 additions & 3 deletions src/epggrab/channel.c
Expand Up @@ -286,7 +286,7 @@ void epggrab_channel_save( epggrab_channel_t *ec )
htsmsg_t *m = htsmsg_create_map();
idnode_save(&ec->idnode, m);
hts_settings_save(m, "epggrab/%s/channels/%s",
ec->mod->id, idnode_uuid_as_sstr(&ec->idnode));
ec->mod->saveid, idnode_uuid_as_sstr(&ec->idnode));
htsmsg_destroy(m);
}

Expand All @@ -302,7 +302,7 @@ void epggrab_channel_destroy( epggrab_channel_t *ec, int delconf )

if (delconf)
hts_settings_remove("epggrab/%s/channels/%s",
ec->mod->id, idnode_uuid_as_sstr(&ec->idnode));
ec->mod->saveid, idnode_uuid_as_sstr(&ec->idnode));

free(ec->comment);
free(ec->name);
Expand Down Expand Up @@ -386,7 +386,7 @@ epggrab_channel_class_get_title(idnode_t *self, const char *lang)
epggrab_channel_t *ec = (epggrab_channel_t*)self;

snprintf(prop_sbuf, PROP_SBUF_LEN, "%s: %s (%s)",
ec->mod->name, ec->name ?: ec->id, ec->id);
ec->name ?: ec->id, ec->id, ec->mod->name);
return prop_sbuf;
}

Expand All @@ -402,6 +402,20 @@ epggrab_channel_class_delete(idnode_t *self)
epggrab_channel_destroy((epggrab_channel_t *)self, 1);
}

static const void *
epggrab_channel_class_modid_get ( void *obj )
{
epggrab_channel_t *ec = obj;
snprintf(prop_sbuf, PROP_SBUF_LEN, "%s", ec->mod->id ?: "");
return &prop_sbuf_ptr;
}

static int
epggrab_channel_class_modid_set ( void *obj, const void *p )
{
return 0;
}

static const void *
epggrab_channel_class_module_get ( void *obj )
{
Expand Down Expand Up @@ -460,6 +474,14 @@ const idclass_t epggrab_channel_class = {
.name = N_("Enabled"),
.off = offsetof(epggrab_channel_t, enabled),
},
{
.type = PT_STR,
.id = "modid",
.name = N_("Module ID"),
.get = epggrab_channel_class_modid_get,
.set = epggrab_channel_class_modid_set,
.opts = PO_RDONLY | PO_HIDDEN,
},
{
.type = PT_STR,
.id = "module",
Expand Down
36 changes: 24 additions & 12 deletions src/epggrab/module.c
Expand Up @@ -202,12 +202,14 @@ const idclass_t epggrab_class_mod_ota = {

epggrab_module_t *epggrab_module_create
( epggrab_module_t *skel, const idclass_t *cls,
const char *id, const char *name, int priority )
const char *id, const char *saveid,
const char *name, int priority )
{
assert(skel);

/* Setup */
skel->id = strdup(id);
skel->saveid = strdup(saveid ?: id);
skel->name = strdup(name);
skel->priority = priority;
RB_INIT(&skel->channels);
Expand Down Expand Up @@ -262,15 +264,22 @@ void epggrab_module_parse( void *m, htsmsg_t *data )
* Module channel routines
* *************************************************************************/

void epggrab_module_channels_load ( epggrab_module_t *mod )
void epggrab_module_channels_load ( const char *modid )
{
epggrab_module_t *mod = NULL;
htsmsg_t *m, *e;
htsmsg_field_t *f;
if (!mod) return;
if ((m = hts_settings_load_r(1, "epggrab/%s/channels", mod->id))) {
const char *id;
if (!modid) return;
if ((m = hts_settings_load_r(1, "epggrab/%s/channels", modid))) {
HTSMSG_FOREACH(f, m) {
if ((e = htsmsg_get_map_by_field(f)))
epggrab_channel_create(mod, e, f->hmf_name);
if ((e = htsmsg_get_map_by_field(f))) {
id = htsmsg_get_str(e, "modid") ?: modid;
if (mod == NULL || strcmp(mod->id, id))
mod = epggrab_module_find_by_id(id);
if (mod)
epggrab_channel_create(mod, e, f->hmf_name);
}
}
htsmsg_destroy(m);
}
Expand All @@ -291,7 +300,8 @@ epggrab_module_int_done( void *m )

epggrab_module_int_t *epggrab_module_int_create
( epggrab_module_int_t *skel, const idclass_t *cls,
const char *id, const char *name, int priority,
const char *id, const char *saveid,
const char *name, int priority,
const char *path,
char* (*grab) (void*m),
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
Expand All @@ -303,7 +313,7 @@ epggrab_module_int_t *epggrab_module_int_create
/* Pass through */
epggrab_module_create((epggrab_module_t*)skel,
cls ?: &epggrab_class_mod_int,
id, name, priority);
id, saveid, name, priority);

/* Int data */
skel->type = EPGGRAB_INT;
Expand Down Expand Up @@ -508,7 +518,8 @@ epggrab_module_activate_socket ( void *m, int a )
*/
epggrab_module_ext_t *epggrab_module_ext_create
( epggrab_module_ext_t *skel,
const char *id, const char *name, int priority, const char *sockid,
const char *id, const char *saveid,
const char *name, int priority, const char *sockid,
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
htsmsg_t* (*trans) (void *mod, char *data) )
{
Expand All @@ -521,7 +532,7 @@ epggrab_module_ext_t *epggrab_module_ext_create
hts_settings_buildpath(path, sizeof(path), "epggrab/%s.sock", sockid);
epggrab_module_int_create((epggrab_module_int_t*)skel,
&epggrab_class_mod_ext,
id, name, priority, path,
id, saveid, name, priority, path,
NULL, parse, trans);

/* Local */
Expand All @@ -538,15 +549,16 @@ epggrab_module_ext_t *epggrab_module_ext_create

epggrab_module_ota_t *epggrab_module_ota_create
( epggrab_module_ota_t *skel,
const char *id, const char *name, int priority,
const char *id, const char *saveid,
const char *name, int priority,
epggrab_ota_module_ops_t *ops )
{
if (!skel) skel = calloc(1, sizeof(epggrab_module_ota_t));

/* Pass through */
epggrab_module_create((epggrab_module_t*)skel,
&epggrab_class_mod_ota,
id, name, priority);
id, saveid, name, priority);

/* Setup */
skel->type = EPGGRAB_OTA;
Expand Down
10 changes: 5 additions & 5 deletions src/epggrab/module/eit.c
Expand Up @@ -789,11 +789,11 @@ void eit_init ( void )
.tune = _eit_tune,
};

epggrab_module_ota_create(NULL, "eit", "EIT: DVB Grabber", 1, &ops);
epggrab_module_ota_create(NULL, "uk_freesat", "UK: Freesat", 5, &ops);
epggrab_module_ota_create(NULL, "uk_freeview", "UK: Freeview", 5, &ops);
epggrab_module_ota_create(NULL, "viasat_baltic", "VIASAT: Baltic", 5, &ops);
epggrab_module_ota_create(NULL, "Bulsatcom_39E", "Bulsatcom: Bula 39E", 5, &ops);
epggrab_module_ota_create(NULL, "eit", NULL, "EIT: DVB Grabber", 1, &ops);
epggrab_module_ota_create(NULL, "uk_freesat", NULL, "UK: Freesat", 5, &ops);
epggrab_module_ota_create(NULL, "uk_freeview", NULL, "UK: Freeview", 5, &ops);
epggrab_module_ota_create(NULL, "viasat_baltic", NULL, "VIASAT: Baltic", 5, &ops);
epggrab_module_ota_create(NULL, "Bulsatcom_39E", NULL, "Bulsatcom: Bula 39E", 5, &ops);
}

void eit_done ( void )
Expand Down
2 changes: 1 addition & 1 deletion src/epggrab/module/opentv.c
Expand Up @@ -944,7 +944,7 @@ static int _opentv_prov_load_one ( const char *id, htsmsg_t *m )
sprintf(nbuf, "OpenTV: %s", name);
mod = (opentv_module_t *)
epggrab_module_ota_create(calloc(1, sizeof(opentv_module_t)),
ibuf, nbuf, 2, &ops);
ibuf, NULL, nbuf, 2, &ops);

/* Add provider details */
mod->dict = dict;
Expand Down
2 changes: 1 addition & 1 deletion src/epggrab/module/psip.c
Expand Up @@ -405,7 +405,7 @@ void psip_init ( void )
.tune = _psip_tune,
};

epggrab_module_ota_create(NULL, "psip", "PSIP: ATSC Grabber", 1, &ops);
epggrab_module_ota_create(NULL, "psip", NULL, "PSIP: ATSC Grabber", 1, &ops);
}

void psip_done ( void )
Expand Down
6 changes: 3 additions & 3 deletions src/epggrab/module/pyepg.c
Expand Up @@ -431,11 +431,11 @@ void pyepg_init ( void )
/* Internal module */
if (find_exec("pyepg", buf, sizeof(buf)-1))
epggrab_module_int_create(NULL, NULL,
"pyepg-internal", "PyEPG", 4, buf,
"pyepg-internal", "pyepg", "PyEPG", 4, buf,
NULL, _pyepg_parse, NULL);

/* External module */
epggrab_module_ext_create(NULL, "pyepg", "PyEPG", 4, "pyepg",
epggrab_module_ext_create(NULL, "pyepg", "pyepg", "PyEPG", 4, "pyepg",
_pyepg_parse, NULL);
}

Expand All @@ -445,5 +445,5 @@ void pyepg_done ( void )

void pyepg_load ( void )
{
epggrab_module_channels_load(epggrab_module_find_by_id("pyepg"));
epggrab_module_channels_load("pyepg");
}
10 changes: 6 additions & 4 deletions src/epggrab/module/xmltv.c
Expand Up @@ -707,7 +707,8 @@ static void _xmltv_load_grabbers ( void )
if ( outbuf[i] == '\n' || outbuf[i] == '\0' ) {
outbuf[i] = '\0';
sprintf(name, "XMLTV: %s", &outbuf[n]);
epggrab_module_int_create(NULL, NULL, &outbuf[p], name, 3, &outbuf[p],
epggrab_module_int_create(NULL, NULL, &outbuf[p], "xmltv",
name, 3, &outbuf[p],
NULL, _xmltv_parse, NULL);
p = n = i + 1;
} else if ( outbuf[i] == '\\') {
Expand Down Expand Up @@ -753,7 +754,7 @@ static void _xmltv_load_grabbers ( void )
close(rd);
if (outbuf[outlen-1] == '\n') outbuf[outlen-1] = '\0';
snprintf(name, sizeof(name), "XMLTV: %s", outbuf);
epggrab_module_int_create(NULL, NULL, bin, name, 3, bin,
epggrab_module_int_create(NULL, NULL, bin, "xmltv", name, 3, bin,
NULL, _xmltv_parse, NULL);
free(outbuf);
} else {
Expand All @@ -772,7 +773,8 @@ static void _xmltv_load_grabbers ( void )
void xmltv_init ( void )
{
/* External module */
epggrab_module_ext_create(NULL, "xmltv", "XMLTV", 3, "xmltv",
epggrab_module_ext_create(NULL, "xmltv", "xmltv",
"XMLTV", 3, "xmltv",
_xmltv_parse, NULL);

/* Standard modules */
Expand All @@ -785,5 +787,5 @@ void xmltv_done ( void )

void xmltv_load ( void )
{
epggrab_module_channels_load(epggrab_module_find_by_id("xmltv"));
epggrab_module_channels_load("xmltv");
}
14 changes: 9 additions & 5 deletions src/epggrab/private.h
Expand Up @@ -27,7 +27,8 @@ struct mpegts_mux;

epggrab_module_t *epggrab_module_create
( epggrab_module_t *skel, const idclass_t *cls,
const char *id, const char *name, int priority );
const char *id, const char *saveid,
const char *name, int priority );

char *epggrab_module_grab_spawn ( void *m );
htsmsg_t *epggrab_module_trans_xml ( void *m, char *data );
Expand All @@ -39,7 +40,7 @@ void epggrab_module_ch_save ( void *m, epggrab_channel_t *ec );

void epggrab_module_parse ( void *m, htsmsg_t *data );

void epggrab_module_channels_load ( epggrab_module_t *m );
void epggrab_module_channels_load ( const char *modid );

/* **************************************************************************
* Channel processing
Expand Down Expand Up @@ -70,7 +71,8 @@ void epggrab_channel_done(void);

epggrab_module_int_t *epggrab_module_int_create
( epggrab_module_int_t *skel, const idclass_t *cls,
const char *id, const char *name, int priority,
const char *id, const char *saveid,
const char *name, int priority,
const char *path,
char* (*grab) (void*m),
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
Expand All @@ -82,7 +84,8 @@ epggrab_module_int_t *epggrab_module_int_create

epggrab_module_ext_t *epggrab_module_ext_create
( epggrab_module_ext_t *skel,
const char *id, const char *name, int priority,
const char *id, const char *saveid,
const char *name, int priority,
const char *sockid,
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
htsmsg_t* (*trans) (void *mod, char *data) );
Expand All @@ -101,7 +104,8 @@ typedef struct epggrab_ota_module_ops {

epggrab_module_ota_t *epggrab_module_ota_create
( epggrab_module_ota_t *skel,
const char *id, const char *name, int priority,
const char *id, const char *saveid,
const char *name, int priority,
epggrab_ota_module_ops_t *ops );

/* **************************************************************************
Expand Down

0 comments on commit 3153614

Please sign in to comment.