prop: added some extra sized types for clarity

In particular I wanted to be able to use u16, as this is commonly
used within the mpegts code for various fields.
This commit is contained in:
Adam Sutton 2013-05-31 20:43:17 +01:00
parent cfbba3891d
commit dc773b0380
2 changed files with 36 additions and 8 deletions

View file

@ -68,6 +68,12 @@ prop_write_values(void *obj, const property_t *pl, htsmsg_t *m)
case TO_FROM(PT_INT, HMF_S64):
*(int *)val = f->hmf_s64;
break;
case TO_FROM(PT_U16, HMF_S64):
*(uint16_t *)val = f->hmf_s64;
break;
case TO_FROM(PT_U32, HMF_S64):
*(uint32_t *)val = f->hmf_s64;
break;
case TO_FROM(PT_STR, HMF_STR):
if(p->str_set != NULL)
p->str_set(obj, f->hmf_str);
@ -94,7 +100,12 @@ prop_read_value(void *obj, const property_t *p, htsmsg_t *m, const char *name)
htsmsg_add_bool(m, name, *(int *)val);
break;
case PT_INT:
htsmsg_add_s32(m, name, *(int *)val);
htsmsg_add_s64(m, name, *(int *)val);
case PT_U32:
htsmsg_add_u32(m, name, *(uint32_t *)val);
break;
case PT_U16:
htsmsg_add_u32(m, name, *(uint16_t *)val);
break;
case PT_STR:
if(p->str_get != NULL)
@ -129,6 +140,8 @@ const static struct strtab typetab[] = {
{ "bool", PT_BOOL },
{ "int", PT_INT },
{ "str", PT_STR },
{ "u16", PT_U16 },
{ "u32", PT_U32 },
};
@ -162,7 +175,9 @@ prop_add_params_to_msg(void *obj, const property_t *p, htsmsg_t *msg)
static int
prop_seti(void *obj, const property_t *p, const char *value)
{
int i32;
int i;
uint32_t u32;
uint16_t u16;
const char *s;
if (p->rdonly) return 0;
@ -171,15 +186,26 @@ prop_seti(void *obj, const property_t *p, const char *value)
switch(p->type) {
case PT_BOOL:
i32 = str_to_bool(value);
i = str_to_bool(value);
if(0)
case PT_INT:
i32 = value ? atoi(value) : 0;
if(*(int *)val == i32)
i = value ? atoi(value) : 0;
if(*(int *)val == i)
return 0; // Already set
*(int *)val = i32;
*(int *)val = i;
break;
case PT_U16:
u16 = value ? atoi(value) : 0;
if(*(uint16_t *)val == u16)
return 0;
*(uint16_t *)val = u16;
break;
case PT_U32:
u32 = value ? atoi(value) : 0;
if(*(uint32_t *)val == u32)
return 0;
*(uint32_t *)val = u32;
break;
case PT_STR:
if(p->str_get != NULL)
s = p->str_get(obj);

View file

@ -5,8 +5,10 @@
typedef enum {
PT_BOOL,
PT_INT,
PT_STR,
PT_INT,
PT_U16,
PT_U32,
} prop_type_t;
typedef struct property {