]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
idnode prop: make it possible for child classes to override parent props
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 17 Mar 2014 23:43:45 +0000 (23:43 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Tue, 18 Mar 2014 21:46:11 +0000 (21:46 +0000)
src/idnode.c
src/prop.c
src/prop.h

index 64ac2c5bcb0690a6db8ce9bc8b52ec23dcc75b69..b06756e82385af9328bbbc779df60e731aac7050 100644 (file)
@@ -539,6 +539,7 @@ idnode_cmp_sort
       break;
     case PT_DBL:
       // TODO
+    case PT_NONE:
       break;
   }
   return 0;
index 2aa94d756e28d6e55fc359b7507a11d107381883..37084d0d93832799060905cccf03e6cf832da3b7 100644 (file)
@@ -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 */
index b89f981979ae5fad9f0364a0cac7713b17fa1e00..cd31f7ea131805591b20fcd83cdb37e2f67c9752 100644 (file)
@@ -28,6 +28,7 @@
  * Property types
  */
 typedef enum {
+  PT_NONE,
   PT_BOOL,
   PT_STR,
   PT_INT,