idnode prop: add ability to be more selective about what updates are sent in notify
This commit is contained in:
parent
b7f5b82b01
commit
f6eb21be9a
4 changed files with 32 additions and 19 deletions
20
src/idnode.c
20
src/idnode.c
|
@ -563,10 +563,12 @@ idnode_write0 ( idnode_t *self, htsmsg_t *c, int optmask, int dosave )
|
|||
{
|
||||
int save = 0;
|
||||
const idclass_t *idc = self->in_class;
|
||||
htsmsg_t *updated = htsmsg_create_map();
|
||||
for (; idc; idc = idc->ic_super)
|
||||
save |= prop_write_values(self, idc->ic_properties, c, optmask);
|
||||
save |= prop_write_values(self, idc->ic_properties, c, optmask, updated);
|
||||
if (save && dosave)
|
||||
idnode_notify(NULL, self, optmask);
|
||||
idnode_notify(NULL, self, optmask, updated);
|
||||
htsmsg_destroy(updated);
|
||||
return save;
|
||||
}
|
||||
|
||||
|
@ -582,7 +584,7 @@ idnode_read0 ( idnode_t *self, htsmsg_t *c, int optmask )
|
|||
{
|
||||
const idclass_t *idc = self->in_class;
|
||||
for (; idc; idc = idc->ic_super)
|
||||
prop_read_values(self, idc->ic_properties, c, optmask);
|
||||
prop_read_values(self, idc->ic_properties, c, optmask, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -590,11 +592,11 @@ idnode_read0 ( idnode_t *self, htsmsg_t *c, int optmask )
|
|||
*/
|
||||
static void
|
||||
add_params
|
||||
(struct idnode *self, const idclass_t *ic, htsmsg_t *p, int optmask)
|
||||
(struct idnode *self, const idclass_t *ic, htsmsg_t *p, int optmask, htsmsg_t *inc)
|
||||
{
|
||||
/* Parent first */
|
||||
if(ic->ic_super != NULL)
|
||||
add_params(self, ic->ic_super, p, optmask);
|
||||
add_params(self, ic->ic_super, p, optmask, inc);
|
||||
|
||||
/* Seperator (if not empty) */
|
||||
#if 0
|
||||
|
@ -607,14 +609,14 @@ add_params
|
|||
#endif
|
||||
|
||||
/* Properties */
|
||||
prop_serialize(self, ic->ic_properties, p, optmask);
|
||||
prop_serialize(self, ic->ic_properties, p, optmask, inc);
|
||||
}
|
||||
|
||||
static htsmsg_t *
|
||||
idnode_params (const idclass_t *idc, idnode_t *self, int optmask)
|
||||
{
|
||||
htsmsg_t *p = htsmsg_create_list();
|
||||
add_params(self, idc, p, optmask);
|
||||
add_params(self, idc, p, optmask, NULL);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -708,7 +710,7 @@ idnode_notify_title_changed(void *obj)
|
|||
*/
|
||||
void
|
||||
idnode_notify
|
||||
(const char *chn, idnode_t *in, int optmask)
|
||||
(const char *chn, idnode_t *in, int optmask, htsmsg_t *inc)
|
||||
{
|
||||
const idclass_t *ic = in->in_class;
|
||||
|
||||
|
@ -726,7 +728,7 @@ idnode_notify
|
|||
htsmsg_add_str(m, "id", idnode_uuid_as_str(in));
|
||||
|
||||
htsmsg_t *p = htsmsg_create_list();
|
||||
add_params(in, in->in_class, p, optmask);
|
||||
add_params(in, in->in_class, p, optmask, inc);
|
||||
htsmsg_add_msg(m, "params", p);
|
||||
|
||||
notify_by_msg(chn ?: "idnodeParamsChanged", m);
|
||||
|
|
|
@ -116,7 +116,7 @@ int idnode_is_instance (idnode_t *in, const idclass_t *idc);
|
|||
void *idnode_find (const char *uuid, const idclass_t *idc);
|
||||
idnode_set_t *idnode_find_all(const idclass_t *idc);
|
||||
|
||||
void idnode_notify(const char *chn, idnode_t *in, int optmask);
|
||||
void idnode_notify(const char *chn, idnode_t *in, int optmask, htsmsg_t *inc);
|
||||
void idnode_notify_title_changed(void *obj);
|
||||
|
||||
htsmsg_t *idclass_serialize0 (const idclass_t *idc, int optmask);
|
||||
|
|
23
src/prop.c
23
src/prop.c
|
@ -80,7 +80,7 @@ prop_find(const property_t *p, const char *id)
|
|||
*/
|
||||
int
|
||||
prop_write_values
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask)
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask, htsmsg_t *updated)
|
||||
{
|
||||
int save, save2 = 0;
|
||||
htsmsg_field_t *f;
|
||||
|
@ -170,6 +170,8 @@ prop_write_values
|
|||
save2 = 1;
|
||||
if (p->notify)
|
||||
p->notify(obj);
|
||||
if (updated)
|
||||
htsmsg_set_u32(updated, p->id, 1);
|
||||
}
|
||||
}
|
||||
return save2;
|
||||
|
@ -184,7 +186,7 @@ prop_write_values
|
|||
*/
|
||||
static void
|
||||
prop_read_value
|
||||
(void *obj, const property_t *p, htsmsg_t *m, const char *name, int optmask)
|
||||
(void *obj, const property_t *p, htsmsg_t *m, const char *name, int optmask, htsmsg_t *inc)
|
||||
{
|
||||
const char *s;
|
||||
const void *val = obj + p->off;
|
||||
|
@ -192,6 +194,10 @@ prop_read_value
|
|||
/* Ignore */
|
||||
if (p->opts & optmask) return;
|
||||
|
||||
/* Ignore */
|
||||
if (inc && !htsmsg_get_u32_or_default(inc, p->id, 0))
|
||||
return;
|
||||
|
||||
/* Get method */
|
||||
if (p->get)
|
||||
val = p->get(obj);
|
||||
|
@ -226,24 +232,29 @@ prop_read_value
|
|||
*
|
||||
*/
|
||||
void
|
||||
prop_read_values(void *obj, const property_t *pl, htsmsg_t *m, int optmask)
|
||||
prop_read_values(void *obj, const property_t *pl, htsmsg_t *m, int optmask, htsmsg_t *inc)
|
||||
{
|
||||
if(pl == NULL)
|
||||
return;
|
||||
for (; pl->id; pl++)
|
||||
prop_read_value(obj, pl, m, pl->id, optmask);
|
||||
prop_read_value(obj, pl, m, pl->id, optmask, inc);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
prop_serialize(void *obj, const property_t *pl, htsmsg_t *msg, int optmask)
|
||||
prop_serialize(void *obj, const property_t *pl, htsmsg_t *msg, int optmask, htsmsg_t *inc)
|
||||
{
|
||||
if(pl == NULL)
|
||||
return;
|
||||
|
||||
for(; pl->id; pl++) {
|
||||
|
||||
/* Ignore */
|
||||
if (inc && !htsmsg_get_u32_or_default(inc, pl->id, 0))
|
||||
continue;
|
||||
|
||||
htsmsg_t *m = htsmsg_create_map();
|
||||
|
||||
/* Metadata */
|
||||
|
@ -265,7 +276,7 @@ prop_serialize(void *obj, const property_t *pl, htsmsg_t *msg, int optmask)
|
|||
|
||||
/* Data */
|
||||
if (obj)
|
||||
prop_read_value(obj, pl, m, "value", optmask);
|
||||
prop_read_value(obj, pl, m, "value", optmask, NULL);
|
||||
|
||||
htsmsg_add_msg(msg, NULL, m);
|
||||
}
|
||||
|
|
|
@ -69,13 +69,13 @@ typedef struct property {
|
|||
const property_t *prop_find(const property_t *p, const char *name);
|
||||
|
||||
int prop_write_values
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask);
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask, htsmsg_t *updated);
|
||||
|
||||
void prop_read_values
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask);
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask, htsmsg_t *inc);
|
||||
|
||||
void prop_serialize
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask);
|
||||
(void *obj, const property_t *pl, htsmsg_t *m, int optmask, htsmsg_t *inc);
|
||||
|
||||
#endif /* __TVH_PROP_H__ */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue