[aravis] gc_register_node: allow SwissKnife nodes for register address computation.



commit ac87bd67e6acf57f7bce963b17e9afd7dd254f1f
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Mar 7 16:33:16 2012 +0100

    gc_register_node: allow SwissKnife nodes for register address computation.

 src/arvgcregisternode.c |   10 +++++++-
 src/arvgcregisternode.h |    1 +
 tests/data/genicam.xml  |   32 +++++++++++++++++++++++++++
 tests/genicam.c         |   54 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/src/arvgcregisternode.c b/src/arvgcregisternode.c
index 8e368f2..da999f0 100644
--- a/src/arvgcregisternode.c
+++ b/src/arvgcregisternode.c
@@ -28,6 +28,7 @@
 #include <arvgcregisternode.h>
 #include <arvgcindexnode.h>
 #include <arvgcinvalidatornode.h>
+#include <arvgcswissknife.h>
 #include <arvgcregister.h>
 #include <arvgcinteger.h>
 #include <arvgcfloat.h>
@@ -124,7 +125,10 @@ arv_gc_register_node_post_new_child (ArvDomNode *self, ArvDomNode *child)
 				ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
 				break;
 		}
-	}
+	} else if (ARV_IS_GC_SWISS_KNIFE (child))
+		node->swiss_knives = g_slist_prepend (node->swiss_knives, child);
+	else
+		ARV_DOM_NODE_CLASS (parent_class)->post_new_child (self, child);
 }
 
 static void
@@ -233,6 +237,9 @@ _get_address (ArvGcRegisterNode *gc_register_node)
 	for (iter = gc_register_node->addresses; iter != NULL; iter = iter->next)
 		value += arv_gc_property_node_get_int64 (iter->data);
 
+	for (iter = gc_register_node->swiss_knives; iter != NULL; iter = iter->next)
+		value += arv_gc_integer_get_value (iter->data);
+
 	if (gc_register_node->index != NULL)
 		value += arv_gc_index_node_get_index (ARV_GC_INDEX_NODE (gc_register_node->index),
 						      _get_length (gc_register_node));
@@ -443,6 +450,7 @@ arv_gc_register_node_finalize (GObject *object)
 	ArvGcRegisterNode *gc_register_node = ARV_GC_REGISTER_NODE (object);
 
 	g_slist_free (gc_register_node->addresses);
+	g_slist_free (gc_register_node->swiss_knives);
 	g_free (gc_register_node->cache);
 	g_slist_free (gc_register_node->invalidators);
 
diff --git a/src/arvgcregisternode.h b/src/arvgcregisternode.h
index c73d2e8..53e525a 100644
--- a/src/arvgcregisternode.h
+++ b/src/arvgcregisternode.h
@@ -76,6 +76,7 @@ struct _ArvGcRegisterNode {
 	GType value_type;
 
 	GSList *addresses;
+	GSList *swiss_knives;
 	ArvGcPropertyNode *index;
 	ArvGcPropertyNode *length;
 	ArvGcPropertyNode *port;
diff --git a/tests/data/genicam.xml b/tests/data/genicam.xml
index cdb95c5..65cf99b 100644
--- a/tests/data/genicam.xml
+++ b/tests/data/genicam.xml
@@ -120,4 +120,36 @@
 		<Value>0</Value>
 	</Integer>
 
+	<Integer Name="IntRegisterAddress">
+		<Value>0x50</Value>
+	</Integer>
+
+	<IntReg Name="IntRegisterA">
+		<Address>0x1000</Address>
+		<pAddress>IntRegisterAddress</pAddress>
+		<Length>8</Length>
+		<AccessMode>RW</AccessMode>
+		<Cachable>NoCache</Cachable>
+		<PollingTime>5</PollingTime>
+		<Sign>Unsigned</Sign>
+		<Endianess>LittelEndian</Endianess>
+	</IntReg>
+
+	<IntReg Name="IntRegisterB">
+		<Address>0x2000</Address>
+		<IntSwissKnife Name="IntRegisterBAddress">
+			<Formula>0xff</Formula>
+		</IntSwissKnife>
+		<Length>8</Length>
+		<AccessMode>RW</AccessMode>
+		<Cachable>NoCache</Cachable>
+		<PollingTime>5</PollingTime>
+		<Sign>Unsigned</Sign>
+		<Endianess>LittelEndian</Endianess>
+	</IntReg>
+
+	<IntSwissKnife Name="IntSwissKnifeTest">
+		<Formula>0x1234</Formula>
+	</IntSwissKnife>
+
 </RegisterDescription>
diff --git a/tests/genicam.c b/tests/genicam.c
index 974c7dc..1184556 100644
--- a/tests/genicam.c
+++ b/tests/genicam.c
@@ -191,6 +191,58 @@ enumeration_test (void)
 	g_object_unref (device);
 }
 
+static void
+swiss_knife_test (void)
+{
+	ArvDevice *device;
+	ArvGc *genicam;
+	ArvGcNode *node;
+	gint64 value;
+
+	device = arv_fake_device_new ("TEST0");
+	g_assert (ARV_IS_FAKE_DEVICE (device));
+
+	genicam = arv_device_get_genicam (device);
+	g_assert (ARV_IS_GC (genicam));
+
+	node = arv_gc_get_node (genicam, "IntSwissKnifeTest");
+	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
+
+	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node));
+	g_assert_cmpint (value, ==, 0x1234);
+
+	g_object_unref (device);
+}
+
+static void
+register_test (void)
+{
+	ArvDevice *device;
+	ArvGc *genicam;
+	ArvGcNode *node;
+	gint64 value;
+
+	device = arv_fake_device_new ("TEST0");
+	g_assert (ARV_IS_FAKE_DEVICE (device));
+
+	genicam = arv_device_get_genicam (device);
+	g_assert (ARV_IS_GC (genicam));
+
+	node = arv_gc_get_node (genicam, "IntRegisterA");
+	g_assert (ARV_IS_GC_REGISTER (node));
+
+	value = arv_gc_register_get_address (ARV_GC_REGISTER (node));
+	g_assert_cmpint (value, ==, 0x1050);
+
+	node = arv_gc_get_node (genicam, "IntRegisterB");
+	g_assert (ARV_IS_GC_REGISTER (node));
+
+	value = arv_gc_register_get_address (ARV_GC_REGISTER (node));
+	g_assert_cmpint (value, ==, 0x20ff);
+
+	g_object_unref (device);
+}
+
 GRegex *arv_gv_device_get_url_regex (void);
 
 static void
@@ -228,6 +280,8 @@ main (int argc, char *argv[])
 	g_test_add_func ("/genicam/boolean", boolean_test);
 	g_test_add_func ("/genicam/float", float_test);
 	g_test_add_func ("/genicam/enumeration", enumeration_test);
+	g_test_add_func ("/genicam/swissknife", swiss_knife_test);
+	g_test_add_func ("/genicam/register", register_test);
 	g_test_add_func ("/genicam/url", url_test);
 
 	result = g_test_run();



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