From 701316a010c958d1f91f375d9927cc873177fd91 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 17 Mar 2014 23:43:45 +0000 Subject: [PATCH] idnode prop: make it possible for child classes to override parent props --- src/idnode.c | 1 + src/prop.c | 36 ++++++++++++++++++++++++++++++++++-- src/prop.h | 1 + 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/idnode.c b/src/idnode.c index 64ac2c5b..b06756e8 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -539,6 +539,7 @@ idnode_cmp_sort break; case PT_DBL: // TODO + case PT_NONE: break; } return 0; diff --git a/src/prop.c b/src/prop.c index 2aa94d75..37084d0d 100644 --- a/src/prop.c +++ b/src/prop.c @@ -80,6 +80,8 @@ prop_write_values if (!pl) return 0; for (p = pl; p->id; p++) { + if (p->type == PT_NONE) continue; + f = htsmsg_field_find(m, p->id); if (!f) continue; @@ -141,6 +143,8 @@ prop_write_values } break; } + case PT_NONE: + break; } } @@ -178,6 +182,7 @@ prop_read_value /* Ignore */ if (p->opts & optmask) return; + if (p->type == PT_NONE) return; /* Ignore */ if (inc && !htsmsg_get_u32_or_default(inc, p->id, 0)) @@ -214,6 +219,8 @@ prop_read_value case PT_DBL: htsmsg_add_dbl(m, name, *(double*)val); break; + case PT_NONE: + break; } } } @@ -238,21 +245,44 @@ void prop_serialize (void *obj, const property_t *pl, htsmsg_t *msg, int optmask, htsmsg_t *inc) { + htsmsg_field_t *f; + if(pl == NULL) return; for(; pl->id; pl++) { + /* Remove parent */ + // TODO: this is really horrible and inefficient! + HTSMSG_FOREACH(f, msg) { + htsmsg_t *t = htsmsg_field_get_map(f); + const char *str; + if (t && (str = htsmsg_get_str(t, "id"))) { + if (!strcmp(str, pl->id)) { + htsmsg_field_destroy(msg, f); + break; + } + } + } + /* Ignore */ if (inc && !htsmsg_get_u32_or_default(inc, pl->id, 0)) continue; htsmsg_t *m = htsmsg_create_map(); - /* Metadata */ + /* ID / type */ htsmsg_add_str(m, "id", pl->id); + htsmsg_add_str(m, "type", val2str(pl->type, typetab) ?: "none"); + + /* Skip - special blocker */ + if (pl->type == PT_NONE) { + htsmsg_add_msg(msg, NULL, m); + continue; + } + + /* Metadata */ htsmsg_add_str(m, "caption", pl->name); - htsmsg_add_str(m, "type", val2str(pl->type, typetab) ?: "unknown"); if (pl->islist) htsmsg_add_u32(m, "list", 1); @@ -277,6 +307,8 @@ prop_serialize case PT_STR: htsmsg_add_str(m, "default", pl->def.s ?: ""); break; + case PT_NONE: + break; } /* Options */ diff --git a/src/prop.h b/src/prop.h index b89f9819..cd31f7ea 100644 --- a/src/prop.h +++ b/src/prop.h @@ -28,6 +28,7 @@ * Property types */ typedef enum { + PT_NONE, PT_BOOL, PT_STR, PT_INT,