[aravis/dom] dom: make genicam enumeration test pass.



commit ebbfe406c78b337b23615cbac4072cec2cfb694c
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Feb 29 11:18:37 2012 +0100

    dom: make genicam enumeration test pass.

 src/arvgcenumentry.c   |   46 +++++++++++------
 src/arvgcenumentry.h   |    7 ++-
 src/arvgcenumeration.c |  133 ++++++++++++++++++++++++------------------------
 src/arvgcenumeration.h |    8 ++-
 4 files changed, 106 insertions(+), 88 deletions(-)
---
diff --git a/src/arvgcenumentry.c b/src/arvgcenumentry.c
index 9dee4c4..8ee3fcf 100644
--- a/src/arvgcenumentry.c
+++ b/src/arvgcenumentry.c
@@ -1,6 +1,6 @@
 /* Aravis - Digital camera library
  *
- * Copyright  2009-2010 Emmanuel Pacaud
+ * Copyright  2009-2012 Emmanuel Pacaud
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,20 +39,33 @@ arv_gc_enum_entry_get_node_name (ArvDomNode *node)
 	return "EnumEntry";
 }
 
-/* ArvGcFeatureNode implementation */
-
-#if 0
 static void
-arv_gc_enum_entry_add_element (ArvGcFeatureNode *node, const char *name, const char *content, const char **attributes)
+arv_gc_enum_entry_post_new_child (ArvDomNode *self, ArvDomNode *child)
 {
-	ArvGcEnumEntry *gc_enum_entry = ARV_GC_ENUM_ENTRY (node);
+	ArvGcEnumEntry *node = ARV_GC_ENUM_ENTRY (self);
+
+	if (ARV_IS_GC_PROPERTY_NODE (child)) {
+		ArvGcPropertyNode *property_node = ARV_GC_PROPERTY_NODE (child);
+
+		switch (arv_gc_property_node_get_node_type (property_node)) {
+			case ARV_GC_PROPERTY_NODE_TYPE_VALUE:
+			case ARV_GC_PROPERTY_NODE_TYPE_P_VALUE:
+				node->value = property_node;
+				break;
+			default:
+				ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
+				break;
+		}
+	}
+}
 
-	if (strcmp (name, "Value") == 0) {
-		gc_enum_entry->value = g_ascii_strtoll (content, NULL, 0);
-	} else
-		ARV_GC_FEATURE_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
+static void
+arv_gc_integer_node_pre_remove_child (ArvDomNode *self, ArvDomNode *child)
+{
+	g_assert_not_reached ();
 }
-#endif
+
+/* ArvGcFeatureNode implementation */
 
 /* ArvGcEnumEntry implementation */
 
@@ -61,7 +74,10 @@ arv_gc_enum_entry_get_value (ArvGcEnumEntry *entry)
 {
 	g_return_val_if_fail (ARV_IS_GC_ENUM_ENTRY (entry), 0);
 
-	return entry->value;
+	if (entry->value != NULL)
+		return arv_gc_property_node_get_int64 (entry->value);
+
+	return 0;
 }
 
 ArvGcNode *
@@ -83,8 +99,6 @@ arv_gc_enum_entry_init (ArvGcEnumEntry *gc_enum_entry)
 static void
 arv_gc_enum_entry_finalize (GObject *object)
 {
-/*        ArvGcEnumEntry *gc_enum_entry = ARV_GC_ENUM_ENTRY (object);*/
-
 	parent_class->finalize (object);
 }
 
@@ -93,13 +107,13 @@ arv_gc_enum_entry_class_init (ArvGcEnumEntryClass *this_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (this_class);
 	ArvDomNodeClass *dom_node_class = ARV_DOM_NODE_CLASS (this_class);
-/*        ArvGcFeatureNodeClass *gc_feature_node_class = ARV_GC_FEATURE_NODE_CLASS (this_class);*/
 
 	parent_class = g_type_class_peek_parent (this_class);
 
 	object_class->finalize = arv_gc_enum_entry_finalize;
 	dom_node_class->get_node_name = arv_gc_enum_entry_get_node_name;
-/*        gc_feature_node_class->add_element = arv_gc_enum_entry_add_element;*/
+	dom_node_class->post_new_child = arv_gc_enum_entry_post_new_child;
+	dom_node_class->pre_remove_child = arv_gc_integer_node_pre_remove_child;
 }
 
 G_DEFINE_TYPE (ArvGcEnumEntry, arv_gc_enum_entry, ARV_TYPE_GC_FEATURE_NODE)
diff --git a/src/arvgcenumentry.h b/src/arvgcenumentry.h
index 9c9d288..fd4ac30 100644
--- a/src/arvgcenumentry.h
+++ b/src/arvgcenumentry.h
@@ -1,6 +1,6 @@
 /* Aravis - Digital camera library
  *
- * Copyright  2009-2010 Emmanuel Pacaud
+ * Copyright  2009-2012 Emmanuel Pacaud
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 
 #include <arvtypes.h>
 #include <arvgcfeaturenode.h>
+#include <arvgcpropertynode.h>
 
 G_BEGIN_DECLS
 
@@ -38,9 +39,9 @@ G_BEGIN_DECLS
 typedef struct _ArvGcEnumEntryClass ArvGcEnumEntryClass;
 
 struct _ArvGcEnumEntry {
-	ArvGcFeatureNode	node;
+	ArvGcFeatureNode base;
 
-	gint64 value;
+	ArvGcPropertyNode *value;
 };
 
 struct _ArvGcEnumEntryClass {
diff --git a/src/arvgcenumeration.c b/src/arvgcenumeration.c
index 9730cbd..cb7780d 100644
--- a/src/arvgcenumeration.c
+++ b/src/arvgcenumeration.c
@@ -1,6 +1,6 @@
 /* Aravis - Digital camera library
  *
- * Copyright  2009-2010 Emmanuel Pacaud
+ * Copyright  2009-2012 Emmanuel Pacaud
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,7 @@
 
 static GObjectClass *parent_class = NULL;
 
-/* ArvGcFeatureNode implementation */
+/* ArvGcDomNode implementation */
 
 static const char *
 arv_gc_enumeration_get_node_name (ArvDomNode *node)
@@ -42,30 +42,40 @@ arv_gc_enumeration_get_node_name (ArvDomNode *node)
 	return "Enumeration";
 }
 
-#if 0
 static gboolean
-arv_gc_enumeration_can_append_child (ArvGcFeatureNode *node, ArvGcFeatureNode *child)
+arv_gc_enumeration_can_append_child (ArvDomNode *node, ArvDomNode *child)
 {
-	if (ARV_IS_GC_ENUM_ENTRY (child))
-		return TRUE;
-
-	return FALSE;
+	return (ARV_IS_GC_ENUM_ENTRY (child) || ARV_IS_GC_PROPERTY_NODE (child));
 }
 
 static void
-arv_gc_enumeration_add_element (ArvGcFeatureNode *node, const char *name, const char *content, const char **attributes)
+arv_gc_enumeration_post_new_child (ArvDomNode *self, ArvDomNode *child)
 {
-	ArvGcEnumeration *gc_enumeration = ARV_GC_ENUMERATION (node);
+	ArvGcEnumeration *node = ARV_GC_ENUMERATION (self);
+
+	if (ARV_IS_GC_PROPERTY_NODE (child)) {
+		ArvGcPropertyNode *property_node = ARV_GC_PROPERTY_NODE (child);
+
+		switch (arv_gc_property_node_get_node_type (property_node)) {
+			case ARV_GC_PROPERTY_NODE_TYPE_VALUE:
+			case ARV_GC_PROPERTY_NODE_TYPE_P_VALUE:
+				node->value = property_node;
+				break;
+			default:
+				ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
+				break;
+		}
+	} else if (ARV_IS_GC_ENUM_ENTRY (child))
+		node->entries = g_slist_prepend (node->entries, child);
+}
 
-	if (strcmp (name, "Value") == 0) {
-		arv_force_g_value_to_int64 (&gc_enumeration->value,
-					    g_ascii_strtoll (content, NULL, 0));
-	} else if (strcmp (name, "pValue") == 0) {
-		arv_force_g_value_to_string (&gc_enumeration->value, content);
-	} else
-		ARV_GC_FEATURE_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
+static void
+arv_gc_enumeration_pre_remove_child (ArvDomNode *self, ArvDomNode *child)
+{
+	g_assert_not_reached ();
 }
-#endif
+
+/* ArvGcFeatureNode implementation */
 
 static void
 arv_gc_enumeration_set_value_from_string (ArvGcFeatureNode *node, const char *string)
@@ -85,29 +95,26 @@ arv_gc_enumeration_get_value_as_string (ArvGcFeatureNode *node)
 const char *
 arv_gc_enumeration_get_string_value (ArvGcEnumeration *enumeration)
 {
-	g_assert_not_reached ();
-
-/*        const GSList *iter;*/
-/*        gint64 value;*/
+	const GSList *iter;
+	gint64 value;
 
-/*        g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);*/
+	g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);
 
-/*        value = arv_gc_get_int64_from_value (arv_gc_node_get_genicam (ARV_GC_NODE (enumeration)),*/
-/*                                                                      &enumeration->value);*/
+	value = arv_gc_enumeration_get_int_value (enumeration);
 
-/*        for (iter = arv_gc_feature_node_get_childs (ARV_GC_FEATURE_NODE (enumeration)); iter != NULL; iter = iter->next) {*/
-/*                if (arv_gc_enum_entry_get_value (iter->data) == value) {*/
-/*                        const char *string;*/
+	for (iter = enumeration->entries; iter != NULL; iter = iter->next) {
+		if (arv_gc_enum_entry_get_value (iter->data) == value) {
+			const char *string;
 
-/*                        string = arv_gc_feature_node_get_name (iter->data);*/
-/*                        arv_log_genicam ("[GcEnumeration::get_string_value] value = %Ld - string = %s",*/
-/*                                         value, string);*/
-/*                        return string;*/
-/*                }*/
-/*        }*/
+			string = arv_gc_feature_node_get_name (iter->data);
+			arv_log_genicam ("[GcEnumeration::get_string_value] value = %Ld - string = %s",
+					 value, string);
+			return string;
+		}
+	}
 
-/*        arv_warning_genicam ("[GcEnumeration::get_string_value] value = %Ld not found for node %s",*/
-/*                             value, arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (enumeration)));*/
+	arv_warning_genicam ("[GcEnumeration::get_string_value] value = %Ld not found for node %s",
+			     value, arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (enumeration)));
 
 	return NULL;
 }
@@ -115,23 +122,19 @@ arv_gc_enumeration_get_string_value (ArvGcEnumeration *enumeration)
 void
 arv_gc_enumeration_set_string_value (ArvGcEnumeration *enumeration, const char *value)
 {
-	g_assert_not_reached ();
-
-/*        const GSList *iter;*/
+	const GSList *iter;
 
-/*        g_return_if_fail (ARV_IS_GC_ENUMERATION (enumeration));*/
+	g_return_if_fail (ARV_IS_GC_ENUMERATION (enumeration));
 
-/*        for (iter = arv_gc_feature_node_get_childs (ARV_GC_FEATURE_NODE (enumeration)); iter != NULL; iter = iter->next)*/
-/*                if (g_strcmp0 (arv_gc_feature_node_get_name (iter->data), value) == 0) {*/
-/*                        arv_log_genicam ("[GcEnumeration::set_string_value] value = %d - string = %s",*/
-/*                                         &enumeration->value, value);*/
-/*                        arv_gc_set_int64_to_value (arv_gc_node_get_genicam (ARV_GC_NODE (enumeration)),*/
-/*                                                   &enumeration->value,*/
-/*                                                   arv_gc_enum_entry_get_value (iter->data));*/
-/*                        return;*/
-/*                }*/
+	for (iter = enumeration->entries; iter != NULL; iter = iter->next)
+		if (g_strcmp0 (arv_gc_feature_node_get_name (iter->data), value) == 0) {
+			arv_log_genicam ("[GcEnumeration::set_string_value] value = %d - string = %s",
+					 &enumeration->value, value);
+			arv_gc_enumeration_set_int_value (enumeration, arv_gc_enum_entry_get_value (iter->data));
+			return;
+		}
 
-/*        arv_warning_genicam ("[GcEnumeration::set_string_value] entry %s not found", value);*/
+	arv_warning_genicam ("[GcEnumeration::set_string_value] entry %s not found", value);
 }
 
 gint64
@@ -139,8 +142,10 @@ arv_gc_enumeration_get_int_value (ArvGcEnumeration *enumeration)
 {
 	g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), 0);
 
-	return arv_gc_get_int64_from_value (arv_gc_node_get_genicam (ARV_GC_NODE (enumeration)),
-					    &enumeration->value);
+	if (enumeration->value != NULL)
+		return arv_gc_property_node_get_int64 (enumeration->value);
+
+	return 0;
 }
 
 gint64 *
@@ -181,8 +186,8 @@ arv_gc_enumeration_set_int_value (ArvGcEnumeration *enumeration, gint64 value)
 {
 	g_return_if_fail (ARV_IS_GC_ENUMERATION (enumeration));
 
-	arv_gc_set_int64_to_value (arv_gc_node_get_genicam (ARV_GC_NODE (enumeration)),
-				   &enumeration->value, value);
+	if (enumeration->value)
+		arv_gc_property_node_set_int64 (enumeration->value, value);
 }
 
 /**
@@ -195,13 +200,9 @@ arv_gc_enumeration_set_int_value (ArvGcEnumeration *enumeration, gint64 value)
 const GSList *
 arv_gc_enumeration_get_entries (ArvGcEnumeration *enumeration)
 {
-	g_assert_not_reached ();
-
-	return NULL;
-
-/*        g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);*/
+	g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);
 
-/*        return arv_gc_feature_node_get_childs (ARV_GC_FEATURE_NODE (enumeration));*/
+	return enumeration->entries;
 }
 
 ArvGcNode *
@@ -217,16 +218,15 @@ arv_gc_enumeration_new (void)
 static void
 arv_gc_enumeration_init (ArvGcEnumeration *gc_enumeration)
 {
-	g_value_init (&gc_enumeration->value, G_TYPE_INT64);
-	g_value_set_int64 (&gc_enumeration->value, 0);
 }
 
 static void
 arv_gc_enumeration_finalize (GObject *object)
 {
-	ArvGcEnumeration *gc_enumeration = ARV_GC_ENUMERATION (object);
+	ArvGcEnumeration *enumeration = ARV_GC_ENUMERATION (object);
 
-	g_value_unset (&gc_enumeration->value);
+	g_slist_free (enumeration->entries);
+	enumeration->entries = NULL;
 
 	parent_class->finalize (object);
 }
@@ -243,8 +243,9 @@ arv_gc_enumeration_class_init (ArvGcEnumerationClass *this_class)
 	object_class->finalize = arv_gc_enumeration_finalize;
 
 	dom_node_class->get_node_name = arv_gc_enumeration_get_node_name;
-/*        gc_feature_node_class->add_element = arv_gc_enumeration_add_element;*/
-/*        gc_feature_node_class->can_add_child = arv_gc_enumeration_can_add_child;*/
+	dom_node_class->can_append_child = arv_gc_enumeration_can_append_child;
+	dom_node_class->post_new_child = arv_gc_enumeration_post_new_child;
+	dom_node_class->pre_remove_child = arv_gc_enumeration_pre_remove_child;
 	gc_feature_node_class->set_value_from_string = arv_gc_enumeration_set_value_from_string;
 	gc_feature_node_class->get_value_as_string = arv_gc_enumeration_get_value_as_string;
 }
diff --git a/src/arvgcenumeration.h b/src/arvgcenumeration.h
index 7e351c5..1993622 100644
--- a/src/arvgcenumeration.h
+++ b/src/arvgcenumeration.h
@@ -1,6 +1,6 @@
 /* Aravis - Digital camera library
  *
- * Copyright  2009-2010 Emmanuel Pacaud
+ * Copyright  2009-2012 Emmanuel Pacaud
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 
 #include <arvtypes.h>
 #include <arvgcfeaturenode.h>
+#include <arvgcpropertynode.h>
 
 G_BEGIN_DECLS
 
@@ -38,9 +39,10 @@ G_BEGIN_DECLS
 typedef struct _ArvGcEnumerationClass ArvGcEnumerationClass;
 
 struct _ArvGcEnumeration {
-	ArvGcFeatureNode	node;
+	ArvGcFeatureNode base;
 
-	GValue value;
+	ArvGcPropertyNode *value;
+	GSList *entries;
 };
 
 struct _ArvGcEnumerationClass {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]