]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
idnode: some additions to help getting individual values from idnode's
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 3 Jun 2013 20:57:26 +0000 (21:57 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Tue, 4 Jun 2013 10:13:49 +0000 (11:13 +0100)
src/idnode.c
src/idnode.h
src/prop.c
src/prop.h

index cfcc035266e0ce1bb6bb17fc5689e627e591b0e0..4238bce3ae3dbdd353571cab46d784f69475f48b 100644 (file)
@@ -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;
+}
index da079ac0c4bbaeceba111038fbb22944a5bdbf2d..f3532e54f3ba8583f6b00559262ca645372fcbad 100644 (file)
@@ -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);
index 8b0b9b1f86530b3c04b72fa81c33d77bf4ef84bc..3f69c86c6e59e2ca8ffe8aec030b302eb28ac8d2 100644 (file)
@@ -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;
index d7fcc58a8e762a039b2991518d0cd388cd75bb1d..ada7b74e3c90fcb650ee3303d3b2f337a3ffc86c 100644 (file)
@@ -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);