idnode: some additions to help getting individual values from idnode's
This commit is contained in:
parent
dce7902664
commit
f9b765fcc4
4 changed files with 70 additions and 2 deletions
64
src/idnode.c
64
src/idnode.c
|
@ -358,7 +358,8 @@ idnode_save ( idnode_t *self, htsmsg_t *c )
|
|||
/*
|
||||
* Load
|
||||
*/
|
||||
void idnode_load ( idnode_t *self, htsmsg_t *c )
|
||||
void
|
||||
idnode_load ( idnode_t *self, htsmsg_t *c )
|
||||
{
|
||||
const idclass_t *idc = self->in_class;
|
||||
while (idc) {
|
||||
|
@ -366,3 +367,64 @@ void idnode_load ( idnode_t *self, htsmsg_t *c )
|
|||
idc = idc->ic_super;
|
||||
}
|
||||
}
|
||||
|
||||
static const property_t *
|
||||
idnode_find_prop
|
||||
( idnode_t *self, const char *key )
|
||||
{
|
||||
const idclass_t *idc = self->in_class;
|
||||
const property_t *p;
|
||||
while (idc) {
|
||||
if ((p = prop_find(idc->ic_properties, key))) return p;
|
||||
idc = idc->ic_super;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get field as string
|
||||
*/
|
||||
const char *
|
||||
idnode_get_str
|
||||
( idnode_t *self, const char *key )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
idnode_get_u32
|
||||
( idnode_t *self, const char *key, uint32_t *u32 )
|
||||
{
|
||||
const property_t *p = idnode_find_prop(self, key);
|
||||
if (p) {
|
||||
void *ptr = self;
|
||||
ptr += p->off;
|
||||
switch (p->type) {
|
||||
case PT_INT:
|
||||
*u32 = *(int*)ptr;
|
||||
return 0;
|
||||
case PT_U16:
|
||||
*u32 = *(uint32_t*)ptr;
|
||||
return 0;
|
||||
case PT_U32:
|
||||
*u32 = *(uint16_t*)ptr;
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ htsmsg_t *idnode_serialize(struct idnode *self);
|
|||
|
||||
void idnode_set_prop(idnode_t *in, const char *key, const char *value);
|
||||
|
||||
const property_t* idnode_get_prop(idnode_t *in, const char *key);
|
||||
|
||||
void idnode_update_all_props(idnode_t *in,
|
||||
const char *(*getvalue)(void *opaque,
|
||||
const char *key),
|
||||
|
@ -52,3 +54,6 @@ void idnode_notify_title_changed(void *obj);
|
|||
|
||||
void idnode_save ( idnode_t *self, htsmsg_t *m );
|
||||
void idnode_load ( idnode_t *self, htsmsg_t *m );
|
||||
|
||||
const char *idnode_get_str ( idnode_t *self, const char *key );
|
||||
int idnode_get_u32(idnode_t *self, const char *key, uint32_t *u32);
|
||||
|
|
|
@ -27,7 +27,7 @@ str_to_bool(const char *s)
|
|||
}
|
||||
|
||||
|
||||
static const property_t *
|
||||
const property_t *
|
||||
prop_find(const property_t *p, const char *id)
|
||||
{
|
||||
int i = 0;
|
||||
|
|
|
@ -25,6 +25,7 @@ typedef struct property {
|
|||
|
||||
} property_t;
|
||||
|
||||
const property_t *prop_find(const property_t *p, const char *name);
|
||||
|
||||
void prop_add_params_to_msg(void *obj, const property_t *p, htsmsg_t *msg);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue