idnode prop: changed to use generic get/set/list methods for properties
This will allow for addition of other type methods without having to add lots of callbacks, the real prototype can be infered from the property type
This commit is contained in:
parent
e37352fc2d
commit
a55b7b9bd0
9 changed files with 107 additions and 82 deletions
22
src/idnode.c
22
src/idnode.c
|
@ -253,15 +253,12 @@ idnode_get_str
|
|||
{
|
||||
const property_t *p = idnode_find_prop(self, key);
|
||||
if (p && p->type == PT_STR) {
|
||||
const char *s;
|
||||
if (p->str_get)
|
||||
s = p->str_get(self);
|
||||
else {
|
||||
void *ptr = self;
|
||||
ptr += p->off;
|
||||
s = *(const char**)ptr;
|
||||
}
|
||||
return s;
|
||||
const void *ptr;
|
||||
if (p->get)
|
||||
ptr = p->get(self);
|
||||
else
|
||||
ptr = ((void*)self) + p->off;
|
||||
return *(const char**)ptr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -276,8 +273,11 @@ idnode_get_u32
|
|||
{
|
||||
const property_t *p = idnode_find_prop(self, key);
|
||||
if (p) {
|
||||
void *ptr = self;
|
||||
ptr += p->off;
|
||||
const void *ptr;
|
||||
if (p->get)
|
||||
ptr = p->get(self);
|
||||
else
|
||||
ptr = ((void*)self) + p->off;
|
||||
switch (p->type) {
|
||||
case PT_INT:
|
||||
*u32 = *(int*)ptr;
|
||||
|
|
|
@ -61,22 +61,26 @@ linuxdvb_frontend_class_save ( idnode_t *in )
|
|||
linuxdvb_device_save((linuxdvb_device_t*)lfe->lh_parent->lh_parent);
|
||||
}
|
||||
|
||||
static const char*
|
||||
static const void*
|
||||
linuxdvb_frontend_class_network_get(void *o)
|
||||
{
|
||||
static const char *s;
|
||||
linuxdvb_frontend_t *lfe = o;
|
||||
if (lfe->mi_network)
|
||||
return idnode_uuid_as_str(&lfe->mi_network->mn_id);
|
||||
return NULL;
|
||||
s = idnode_uuid_as_str(&lfe->mi_network->mn_id);
|
||||
else
|
||||
s = NULL;
|
||||
return &s;
|
||||
}
|
||||
|
||||
static int
|
||||
linuxdvb_frontend_class_network_set(void *o, const char *s)
|
||||
linuxdvb_frontend_class_network_set(void *o, const void *v)
|
||||
{
|
||||
mpegts_input_t *mi = o;
|
||||
mpegts_network_t *mn = mi->mi_network;
|
||||
linuxdvb_network_t *ln = (linuxdvb_network_t*)mn;
|
||||
linuxdvb_frontend_t *lfe = o;
|
||||
const char *s = v;
|
||||
|
||||
if (lfe->lfe_info.type == FE_QPSK) {
|
||||
tvherror("linuxdvb", "cannot set network on DVB-S FE");
|
||||
|
@ -173,9 +177,9 @@ const idclass_t linuxdvb_frontend_dvbt_class =
|
|||
.type = PT_STR,
|
||||
.id = "network",
|
||||
.name = "Network",
|
||||
.str_get = linuxdvb_frontend_class_network_get,
|
||||
.str_set = linuxdvb_frontend_class_network_set,
|
||||
.str_enum = linuxdvb_frontend_class_network_enum
|
||||
.get = linuxdvb_frontend_class_network_get,
|
||||
.set = linuxdvb_frontend_class_network_set,
|
||||
.list = linuxdvb_frontend_class_network_enum
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
@ -201,9 +205,9 @@ const idclass_t linuxdvb_frontend_dvbc_class =
|
|||
.type = PT_STR,
|
||||
.id = "network",
|
||||
.name = "Network",
|
||||
.str_get = linuxdvb_frontend_class_network_get,
|
||||
.str_set = linuxdvb_frontend_class_network_set,
|
||||
.str_enum = linuxdvb_frontend_class_network_enum
|
||||
.get = linuxdvb_frontend_class_network_get,
|
||||
.set = linuxdvb_frontend_class_network_set,
|
||||
.list = linuxdvb_frontend_class_network_enum
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
@ -219,9 +223,9 @@ const idclass_t linuxdvb_frontend_atsc_class =
|
|||
.type = PT_STR,
|
||||
.id = "network",
|
||||
.name = "Network",
|
||||
.str_get = linuxdvb_frontend_class_network_get,
|
||||
.str_set = linuxdvb_frontend_class_network_set,
|
||||
.str_enum = linuxdvb_frontend_class_network_enum
|
||||
.get = linuxdvb_frontend_class_network_get,
|
||||
.set = linuxdvb_frontend_class_network_set,
|
||||
.list = linuxdvb_frontend_class_network_enum
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,19 @@ extern const idclass_t mpegts_mux_class;
|
|||
|
||||
/* Macro to defien mux class str get/set */
|
||||
#define linuxdvb_mux_class_X(c, f, p, l, ...)\
|
||||
static const char * \
|
||||
static const void * \
|
||||
linuxdvb_mux_##c##_class_##l##_get (void *o)\
|
||||
{\
|
||||
static const char *s;\
|
||||
linuxdvb_mux_t *lm = o;\
|
||||
return dvb_##l##2str(lm->lm_tuning.dmc_fe_params.u.f.p);\
|
||||
s = dvb_##l##2str(lm->lm_tuning.dmc_fe_params.u.f.p);\
|
||||
return &s;\
|
||||
}\
|
||||
static int \
|
||||
linuxdvb_mux_##c##_class_##l##_set (void *o, const char *s)\
|
||||
linuxdvb_mux_##c##_class_##l##_set (void *o, const void *v)\
|
||||
{\
|
||||
linuxdvb_mux_t *lm = o;\
|
||||
lm->lm_tuning.dmc_fe_params.u.f.p = dvb_str2##l (s);\
|
||||
lm->lm_tuning.dmc_fe_params.u.f.p = dvb_str2##l ((const char*)v);\
|
||||
return 1;\
|
||||
}\
|
||||
static htsmsg_t *\
|
||||
|
@ -69,19 +71,22 @@ linuxdvb_mux_##c##_class_##l##_enum (void *o)\
|
|||
.type = PT_STR,\
|
||||
.id = _id,\
|
||||
.name = _name,\
|
||||
.str_get = linuxdvb_mux_##t##_class_##l##_get,\
|
||||
.str_set = linuxdvb_mux_##t##_class_##l##_set,\
|
||||
.str_enum = linuxdvb_mux_##t##_class_##l##_enum
|
||||
.get = linuxdvb_mux_##t##_class_##l##_get,\
|
||||
.set = linuxdvb_mux_##t##_class_##l##_set,\
|
||||
.list = linuxdvb_mux_##t##_class_##l##_enum
|
||||
|
||||
static const char *
|
||||
static const void *
|
||||
linuxdvb_mux_class_delsys_get (void *o)
|
||||
{
|
||||
static const char *s;
|
||||
linuxdvb_mux_t *lm = o;
|
||||
return dvb_delsys2str(lm->lm_tuning.dmc_fe_delsys);
|
||||
s = dvb_delsys2str(lm->lm_tuning.dmc_fe_delsys);
|
||||
return &s;
|
||||
}
|
||||
static int
|
||||
linuxdvb_mux_class_delsys_set (void *o, const char *s)
|
||||
linuxdvb_mux_class_delsys_set (void *o, const void *v)
|
||||
{
|
||||
const char *s = v;
|
||||
linuxdvb_mux_t *lm = o;
|
||||
lm->lm_tuning.dmc_fe_delsys = dvb_str2delsys(s);
|
||||
return 1;
|
||||
|
@ -275,17 +280,19 @@ linuxdvb_mux_class_X(dvbs, qam, fec_inner, fec,
|
|||
, FEC_3_5, FEC_9_10
|
||||
#endif
|
||||
);
|
||||
static const char *
|
||||
static const void *
|
||||
linuxdvb_mux_dvbs_class_polarity_get (void *o)
|
||||
{
|
||||
static const char *s;
|
||||
linuxdvb_mux_t *lm = o;
|
||||
return dvb_pol2str(lm->lm_tuning.dmc_fe_polarisation);
|
||||
s = dvb_pol2str(lm->lm_tuning.dmc_fe_polarisation);
|
||||
return &s;
|
||||
}
|
||||
static int
|
||||
linuxdvb_mux_dvbs_class_polarity_set (void *o, const char *s)
|
||||
linuxdvb_mux_dvbs_class_polarity_set (void *o, const void *s)
|
||||
{
|
||||
linuxdvb_mux_t *lm = o;
|
||||
lm->lm_tuning.dmc_fe_polarisation = dvb_str2pol(s);
|
||||
lm->lm_tuning.dmc_fe_polarisation = dvb_str2pol((const char*)s);
|
||||
return 1;
|
||||
}
|
||||
static htsmsg_t *
|
||||
|
|
|
@ -36,17 +36,20 @@
|
|||
|
||||
extern const idclass_t mpegts_network_class;
|
||||
|
||||
static const char *
|
||||
static const void *
|
||||
mpegts_network_class_get_lntype
|
||||
( void * ptr )
|
||||
{
|
||||
return dvb_type2str(((linuxdvb_network_t*)ptr)->ln_type);
|
||||
static const char *s;
|
||||
s = dvb_type2str(((linuxdvb_network_t*)ptr)->ln_type);
|
||||
return &s;
|
||||
}
|
||||
|
||||
static int
|
||||
mpegts_network_class_set_lntype
|
||||
( void *ptr, const char *str )
|
||||
( void *ptr, const void *v )
|
||||
{
|
||||
const char *str = v;
|
||||
((linuxdvb_network_t*)ptr)->ln_type = dvb_str2type(str);
|
||||
return 1;
|
||||
}
|
||||
|
@ -62,8 +65,8 @@ const idclass_t linuxdvb_network_class =
|
|||
.id = "type",
|
||||
.name = "Network Type",
|
||||
.opts = PO_RDONLY,
|
||||
.str_get = mpegts_network_class_get_lntype,
|
||||
.str_set = mpegts_network_class_set_lntype,
|
||||
.get = mpegts_network_class_get_lntype,
|
||||
.set = mpegts_network_class_set_lntype,
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
|
|
@ -37,21 +37,25 @@
|
|||
|
||||
extern const idclass_t mpegts_input_class;
|
||||
|
||||
static const char*
|
||||
static const void*
|
||||
linuxdvb_satconf_class_network_get(void *o)
|
||||
{
|
||||
static const char *s;
|
||||
linuxdvb_satconf_t *ls = o;
|
||||
if (ls->mi_network)
|
||||
return idnode_uuid_as_str(&ls->mi_network->mn_id);
|
||||
return NULL;
|
||||
s = idnode_uuid_as_str(&ls->mi_network->mn_id);
|
||||
else
|
||||
s = NULL;
|
||||
return &s;
|
||||
}
|
||||
|
||||
static int
|
||||
linuxdvb_satconf_class_network_set(void *o, const char *s)
|
||||
linuxdvb_satconf_class_network_set(void *o, const void *v)
|
||||
{
|
||||
extern const idclass_t linuxdvb_network_class;
|
||||
mpegts_input_t *mi = o;
|
||||
mpegts_network_t *mn = mi->mi_network;
|
||||
const char *s = v;
|
||||
|
||||
if (mi->mi_network && !strcmp(idnode_uuid_as_str(&mn->mn_id), s ?: ""))
|
||||
return 0;
|
||||
|
@ -88,20 +92,24 @@ linuxdvb_satconf_class_network_enum(void *o)
|
|||
return m;
|
||||
}
|
||||
|
||||
static const char *
|
||||
static const void *
|
||||
linuxdvb_satconf_class_frontend_get ( void *o )
|
||||
{
|
||||
static const char *s;
|
||||
linuxdvb_satconf_t *ls = o;
|
||||
if (ls->ls_frontend)
|
||||
return idnode_uuid_as_str(&ls->ls_frontend->mi_id);
|
||||
return NULL;
|
||||
s = idnode_uuid_as_str(&ls->ls_frontend->mi_id);
|
||||
else
|
||||
s = NULL;
|
||||
return &s;
|
||||
}
|
||||
|
||||
static int
|
||||
linuxdvb_satconf_class_frontend_set ( void *o, const char *u )
|
||||
linuxdvb_satconf_class_frontend_set ( void *o, const void *v )
|
||||
{
|
||||
extern const idclass_t linuxdvb_frontend_dvbs_class;
|
||||
linuxdvb_satconf_t *ls = o;
|
||||
const char *u = v;
|
||||
mpegts_input_t *lfe = idnode_find(u, &linuxdvb_frontend_dvbs_class);
|
||||
if (lfe && ls->ls_frontend != lfe) {
|
||||
// TODO: I probably need to clean up the existing linkages
|
||||
|
@ -154,17 +162,17 @@ const idclass_t linuxdvb_satconf_class =
|
|||
.type = PT_STR,
|
||||
.id = "frontend",
|
||||
.name = "Frontend",
|
||||
.str_get = linuxdvb_satconf_class_frontend_get,
|
||||
.str_set = linuxdvb_satconf_class_frontend_set,
|
||||
.str_enum = linuxdvb_satconf_class_frontend_enum
|
||||
.get = linuxdvb_satconf_class_frontend_get,
|
||||
.set = linuxdvb_satconf_class_frontend_set,
|
||||
.list = linuxdvb_satconf_class_frontend_enum
|
||||
},
|
||||
{
|
||||
.type = PT_STR,
|
||||
.id = "network",
|
||||
.name = "Network",
|
||||
.str_get = linuxdvb_satconf_class_network_get,
|
||||
.str_set = linuxdvb_satconf_class_network_set,
|
||||
.str_enum = linuxdvb_satconf_class_network_enum
|
||||
.get = linuxdvb_satconf_class_network_get,
|
||||
.set = linuxdvb_satconf_class_network_set,
|
||||
.list = linuxdvb_satconf_class_network_enum
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
|
|
@ -30,16 +30,15 @@
|
|||
* Class definition
|
||||
* *************************************************************************/
|
||||
|
||||
static const char *
|
||||
static const void *
|
||||
mpegts_input_class_get_name ( void *in )
|
||||
{
|
||||
static char buf[256];
|
||||
static char buf[256], *s = buf;
|
||||
mpegts_input_t *mi = in;
|
||||
*buf = 0;
|
||||
if (mi->mi_display_name)
|
||||
mi->mi_display_name(mi, buf, sizeof(buf));
|
||||
else
|
||||
*buf = 0;
|
||||
return buf;
|
||||
return &s;
|
||||
}
|
||||
|
||||
const idclass_t mpegts_input_class =
|
||||
|
@ -58,7 +57,7 @@ const idclass_t mpegts_input_class =
|
|||
.id = "displayname",
|
||||
.name = "Name",
|
||||
.opts = PO_NOSAVE | PO_RDONLY,
|
||||
.str_get = mpegts_input_class_get_name,
|
||||
.get = mpegts_input_class_get_name,
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
|
17
src/prop.c
17
src/prop.c
|
@ -141,8 +141,8 @@ prop_write_values(void *obj, const property_t *pl, htsmsg_t *m, int optmask)
|
|||
}
|
||||
case TO_FROM(PT_STR, HMF_STR): {
|
||||
char **val = v;
|
||||
if(p->str_set != NULL)
|
||||
save |= p->str_set(obj, f->hmf_str);
|
||||
if(p->set != NULL)
|
||||
save |= p->set(obj, f->hmf_str);
|
||||
else if (strcmp(*val ?: "", f->hmf_str)) {
|
||||
free(*val);
|
||||
*val = strdup(f->hmf_str);
|
||||
|
@ -172,6 +172,10 @@ prop_read_value
|
|||
/* Ignore */
|
||||
if (p->opts & optmask) return;
|
||||
|
||||
/* Get method */
|
||||
if (p->get)
|
||||
val = p->get(obj);
|
||||
|
||||
/* Read */
|
||||
switch(p->type) {
|
||||
case PT_BOOL:
|
||||
|
@ -187,10 +191,7 @@ prop_read_value
|
|||
htsmsg_add_u32(m, name, *(uint16_t *)val);
|
||||
break;
|
||||
case PT_STR:
|
||||
if(p->str_get != NULL)
|
||||
s = p->str_get(obj);
|
||||
else
|
||||
s = *(const char **)val;
|
||||
s = *(const char **)val;
|
||||
if(s != NULL) {
|
||||
htsmsg_add_str(m, name, s);
|
||||
}
|
||||
|
@ -236,8 +237,8 @@ prop_serialize(void *obj, const property_t *pl, htsmsg_t *msg, int optmask)
|
|||
htsmsg_add_u32(m, "wronce", 1);
|
||||
|
||||
/* Enum list */
|
||||
if (pl->str_enum)
|
||||
htsmsg_add_msg(m, "enum", pl->str_enum(obj));
|
||||
if (pl->list)
|
||||
htsmsg_add_msg(m, "enum", pl->list(obj));
|
||||
|
||||
/* Data */
|
||||
if (obj)
|
||||
|
|
|
@ -54,9 +54,9 @@ typedef struct property {
|
|||
int opts; ///< Options
|
||||
|
||||
/* String based processing */
|
||||
const char *(*str_get) (void *ptr);
|
||||
int (*str_set) (void *ptr, const char *str);
|
||||
htsmsg_t *(*str_enum) (void *ptr);
|
||||
const void *(*get) (void *ptr);
|
||||
int (*set) (void *ptr, const void *v);
|
||||
htsmsg_t *(*list) (void *ptr);
|
||||
// Note: htsmsg_t can either be a string list or object list
|
||||
// where the object has "key" and "val" fields
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
#include "descrambler.h"
|
||||
|
||||
static void service_data_timeout(void *aux);
|
||||
static const char *service_class_channel_get(void *obj);
|
||||
static int service_class_channel_set(void *obj, const char *str);
|
||||
static const void *service_class_channel_get(void *obj);
|
||||
static int service_class_channel_set(void *obj, const void *str);
|
||||
static void service_class_save(struct idnode *self);
|
||||
|
||||
static htsmsg_t *service_class_channel_enum(void *p)
|
||||
|
@ -74,9 +74,9 @@ const idclass_t service_class = {
|
|||
.type = PT_STR,
|
||||
.id = "channel",
|
||||
.name = "Channel",
|
||||
.str_get = service_class_channel_get,
|
||||
.str_set = service_class_channel_set,
|
||||
.str_enum = service_class_channel_enum
|
||||
.get = service_class_channel_get,
|
||||
.set = service_class_channel_set,
|
||||
.list = service_class_channel_enum
|
||||
},
|
||||
{}
|
||||
}
|
||||
|
@ -686,11 +686,13 @@ service_map_channel(service_t *t, channel_t *ch, int save)
|
|||
/**
|
||||
*
|
||||
*/
|
||||
static const char *
|
||||
static const void *
|
||||
service_class_channel_get(void *obj)
|
||||
{
|
||||
static const char *r;
|
||||
service_t *s = obj;
|
||||
return s->s_ch ? s->s_ch->ch_name : NULL;
|
||||
r = s->s_ch ? s->s_ch->ch_name : NULL;
|
||||
return &r;
|
||||
}
|
||||
|
||||
|
||||
|
@ -698,8 +700,9 @@ service_class_channel_get(void *obj)
|
|||
*
|
||||
*/
|
||||
static int
|
||||
service_class_channel_set(void *obj, const char *str)
|
||||
service_class_channel_set(void *obj, const void *v)
|
||||
{
|
||||
const char *str = v;
|
||||
service_map_channel(obj, str ? channel_find_by_name(str, 1, 0) : NULL, 0);
|
||||
return 1; // TODO: sort this!
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue