[aravis] genicam: partly implement isImplemented and isAvailable for Enumeration elements.



commit b2efc926130ad95480901e7acf6b9ab00844decd
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon May 30 23:53:26 2011 +0200

    genicam: partly implement isImplemented and isAvailable for Enumeration elements.

 docs/reference/aravis/aravis-sections.txt |    2 +
 gst/.gitignore                            |    1 -
 gst/gstaravis.c                           |    2 +-
 src/arvcamera.c                           |   19 +----
 src/arvcamera.h                           |    6 +-
 src/arvgcenumeration.c                    |   33 +++++++
 src/arvgcenumeration.h                    |   15 ++--
 src/arvgcnode.c                           |   25 ++++++
 src/arvgcnode.h                           |    1 +
 tests/Makefile.am                         |    6 +-
 tests/data/genicam.xml                    |  131 ++++++++++++-----------------
 tests/genicam.c                           |   79 +++++++++++++++++
 12 files changed, 214 insertions(+), 106 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 076bf07..f5fe2c6 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -205,6 +205,7 @@ arv_gc_enumeration_set_string_value
 arv_gc_enumeration_get_int_value
 arv_gc_enumeration_set_int_value
 arv_gc_enumeration_get_entries
+arv_gc_enumeration_get_available_int_values
 <SUBSECTION Standard>
 ARV_GC_ENUMERATION
 ARV_IS_GC_ENUMERATION
@@ -338,6 +339,7 @@ arv_gc_node_get_genicam
 arv_gc_node_get_name
 arv_gc_node_get_tooltip
 arv_gc_node_get_description
+arv_gc_node_is_available
 arv_gc_node_set_attribute
 arv_gc_node_add_element
 arv_gc_node_can_add_child
diff --git a/gst/.gitignore b/gst/.gitignore
index 2da7952..e69de29 100644
--- a/gst/.gitignore
+++ b/gst/.gitignore
@@ -1 +0,0 @@
-gst-aravis-launch
diff --git a/gst/gstaravis.c b/gst/gstaravis.c
index 86b32a5..149bc49 100644
--- a/gst/gstaravis.c
+++ b/gst/gstaravis.c
@@ -64,7 +64,7 @@ static GstCaps *
 gst_aravis_get_all_camera_caps (GstAravis *gst_aravis)
 {
 	GstCaps *caps;
-	ArvPixelFormat *pixel_formats;
+	gint64 *pixel_formats;
 	double frame_rate;
 	int min_height, min_width;
 	int max_height, max_width;
diff --git a/src/arvcamera.c b/src/arvcamera.c
index 8660b75..858efba 100644
--- a/src/arvcamera.c
+++ b/src/arvcamera.c
@@ -344,31 +344,16 @@ arv_camera_get_pixel_format (ArvCamera *camera)
  * Returns: (array length=n_pixel_formats) (transfer full): a newly allocated array of #ArvPixelFormat
  */
 
-ArvPixelFormat *
+gint64 *
 arv_camera_get_available_pixel_formats (ArvCamera *camera, guint *n_pixel_formats)
 {
 	ArvGcNode *enumeration;
-	ArvPixelFormat *pixel_formats;
-	const GSList *entries, *iter;
-	unsigned int i;
 
 	g_return_val_if_fail (ARV_IS_CAMERA (camera), NULL);
-	g_return_val_if_fail (n_pixel_formats != NULL, NULL);
 
 	enumeration = arv_gc_get_node (camera->priv->genicam, "PixelFormat");
-	if (!ARV_IS_GC_ENUMERATION (enumeration))
-		return NULL;
-
-	*n_pixel_formats = arv_gc_node_get_n_childs (enumeration);
-	if (*n_pixel_formats == 0)
-		return NULL;
-
-	pixel_formats = g_new (ArvPixelFormat, *n_pixel_formats);
-	entries = arv_gc_enumeration_get_entries (ARV_GC_ENUMERATION (enumeration));
-	for (iter = entries, i = 0; iter != NULL; iter = iter->next, i++)
-		pixel_formats[i] = arv_gc_enum_entry_get_value (iter->data);
 
-	return pixel_formats;
+	return arv_gc_enumeration_get_available_int_values (ARV_GC_ENUMERATION (enumeration), n_pixel_formats);
 }
 
 /* Acquisition control */
diff --git a/src/arvcamera.h b/src/arvcamera.h
index 2f23fcb..3ac5f60 100644
--- a/src/arvcamera.h
+++ b/src/arvcamera.h
@@ -71,9 +71,9 @@ void		arv_camera_get_height_bounds	(ArvCamera *camera, gint *min, gint *max);
 void		arv_camera_set_binning		(ArvCamera *camera, gint dx, gint dy);
 void		arv_camera_get_binning		(ArvCamera *camera, gint *dx, gint *dy);
 
-void 		arv_camera_set_pixel_format 	(ArvCamera *camera, ArvPixelFormat format);
-ArvPixelFormat 	arv_camera_get_pixel_format 	(ArvCamera *camera);
-ArvPixelFormat *arv_camera_get_available_pixel_formats 	(ArvCamera *camera, guint *n_pixel_formats);
+void 		arv_camera_set_pixel_format 		(ArvCamera *camera, ArvPixelFormat format);
+ArvPixelFormat 	arv_camera_get_pixel_format 		(ArvCamera *camera);
+gint64 *	arv_camera_get_available_pixel_formats 	(ArvCamera *camera, guint *n_pixel_formats);
 
 /* Acquisition control */
 
diff --git a/src/arvgcenumeration.c b/src/arvgcenumeration.c
index 00a1424..66985a6 100644
--- a/src/arvgcenumeration.c
+++ b/src/arvgcenumeration.c
@@ -118,6 +118,39 @@ arv_gc_enumeration_get_int_value (ArvGcEnumeration *enumeration)
 					    &enumeration->value);
 }
 
+gint64 *
+arv_gc_enumeration_get_available_int_values (ArvGcEnumeration *enumeration, guint *n_values)
+{
+	gint64 *values;
+	const GSList *entries, *iter;
+	unsigned int i;
+
+	g_return_val_if_fail (n_values != NULL, NULL);
+
+	*n_values = 0;
+
+	g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);
+
+	entries = arv_gc_enumeration_get_entries (enumeration);
+
+	*n_values = 0;
+	for (iter = entries; iter != NULL; iter = iter->next)
+		if (arv_gc_node_is_available (iter->data))
+		    (*n_values)++;
+
+	if (*n_values == 0)
+		return NULL;
+
+	values = g_new (gint64, *n_values);
+	for (iter = entries, i = 0; iter != NULL; iter = iter->next)
+		if (arv_gc_node_is_available (iter->data)) {
+			values[i] = arv_gc_enum_entry_get_value (iter->data);
+			i++;
+		}
+
+	return values;
+}
+
 void
 arv_gc_enumeration_set_int_value (ArvGcEnumeration *enumeration, gint64 value)
 {
diff --git a/src/arvgcenumeration.h b/src/arvgcenumeration.h
index 88b5c8f..9a796db 100644
--- a/src/arvgcenumeration.h
+++ b/src/arvgcenumeration.h
@@ -49,12 +49,15 @@ struct _ArvGcEnumerationClass {
 
 GType 		arv_gc_enumeration_get_type 	(void);
 
-ArvGcNode * 	arv_gc_enumeration_new 	(void);
-const char *	arv_gc_enumeration_get_string_value	(ArvGcEnumeration *enumeration);
-void		arv_gc_enumeration_set_string_value	(ArvGcEnumeration *enumeration, const char *value);
-gint64 		arv_gc_enumeration_get_int_value	(ArvGcEnumeration *enumeration);
-void		arv_gc_enumeration_set_int_value	(ArvGcEnumeration *enumeration, gint64 value);
-const GSList *	arv_gc_enumeration_get_entries		(ArvGcEnumeration *enumeration);
+ArvGcNode * 	arv_gc_enumeration_new 				(void);
+
+const char *	arv_gc_enumeration_get_string_value		(ArvGcEnumeration *enumeration);
+void		arv_gc_enumeration_set_string_value		(ArvGcEnumeration *enumeration, const char *value);
+gint64 		arv_gc_enumeration_get_int_value		(ArvGcEnumeration *enumeration);
+void		arv_gc_enumeration_set_int_value		(ArvGcEnumeration *enumeration, gint64 value);
+const GSList *	arv_gc_enumeration_get_entries			(ArvGcEnumeration *enumeration);
+
+gint64 *	arv_gc_enumeration_get_available_int_values	(ArvGcEnumeration *enumeration,	guint *n_values);
 
 G_END_DECLS
 
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index d4d246b..a39aa3e 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -30,6 +30,7 @@
 
 #include <arvgcnode.h>
 #include <arvgc.h>
+#include <arvtools.h>
 #include <arvdebug.h>
 #include <string.h>
 
@@ -43,6 +44,9 @@ struct _ArvGcNodePrivate {
 	char *description;
 	char *display_name;
 
+	GValue is_implemented;
+	GValue is_available;
+
 	unsigned int n_childs;
 	GSList *childs;
 
@@ -81,6 +85,15 @@ arv_gc_node_get_display_name (ArvGcNode *node)
 	return node->priv->display_name;
 }
 
+gboolean
+arv_gc_node_is_available (ArvGcNode *gc_node)
+{
+	g_return_val_if_fail (ARV_IS_GC_NODE (gc_node), FALSE);
+
+	return arv_gc_get_int64_from_value (gc_node->priv->genicam, &gc_node->priv->is_implemented) != 0 &&
+		arv_gc_get_int64_from_value (gc_node->priv->genicam, &gc_node->priv->is_available) != 0;
+}
+
 static void
 _set_attribute (ArvGcNode *node, const char *name, const char *value)
 {
@@ -116,6 +129,10 @@ _add_element (ArvGcNode *node, const char *name, const char *content, const char
 	} else if (strcmp (name, "DisplayName") == 0) {
 		g_free (node->priv->display_name);
 		node->priv->display_name = g_strdup (content);
+	} else if (strcmp (name, "pIsImplemented") == 0) {
+		arv_force_g_value_to_string (&node->priv->is_implemented, content);
+	} else if (strcmp (name, "pIsAvailable") == 0) {
+		arv_force_g_value_to_string (&node->priv->is_available, content);
 	}
 }
 
@@ -249,6 +266,11 @@ arv_gc_node_init (ArvGcNode *gc_node)
 	gc_node->priv->childs = NULL;
 	gc_node->priv->n_childs = 0;
 
+	g_value_init (&gc_node->priv->is_implemented, G_TYPE_INT64);
+	g_value_set_int64 (&gc_node->priv->is_implemented, 1);
+	g_value_init (&gc_node->priv->is_available, G_TYPE_INT64);
+	g_value_set_int64 (&gc_node->priv->is_available, 1);
+
 	gc_node->priv->modification_count = 0;
 }
 
@@ -268,6 +290,9 @@ arv_gc_node_finalize (GObject *object)
 	g_free (node->priv->description);
 	g_free (node->priv->display_name);
 
+	g_value_unset (&node->priv->is_implemented);
+	g_value_unset (&node->priv->is_available);
+
 	parent_class->finalize (object);
 }
 
diff --git a/src/arvgcnode.h b/src/arvgcnode.h
index 7881fbc..edb035e 100644
--- a/src/arvgcnode.h
+++ b/src/arvgcnode.h
@@ -62,6 +62,7 @@ ArvGc * 	arv_gc_node_get_genicam			(ArvGcNode *gc_node);
 const char *	arv_gc_node_get_name			(ArvGcNode *gc_node);
 const char *	arv_gc_node_get_tooltip			(ArvGcNode *gc_node);
 const char *	arv_gc_node_get_description		(ArvGcNode *gc_node);
+gboolean	arv_gc_node_is_available		(ArvGcNode *gc_node);
 void		arv_gc_node_set_attribute 		(ArvGcNode *gc_node, const char *name, const char *value);
 void 		arv_gc_node_add_element 		(ArvGcNode *gc_node, const char *name, const char *content,
 							 const char **attributes);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 895e799..f53f9b7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,7 @@ arv_zip_test_LDADD = $(test_progs_ldadd)
 arv_camera_test_SOURCES = arvcameratest.c
 arv_camera_test_LDADD = $(test_progs_ldadd)
 
-TEST_PROGS += evaluator buffer fake cpp
+TEST_PROGS += evaluator buffer fake genicam cpp
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
@@ -37,5 +37,9 @@ fake_SOURCES = fake.c
 fake_CFLAGS = -DGENICAM_FILENAME="\"$(top_srcdir)/src/arv-fake-camera.xml\""
 fake_LDADD = $(test_progs_ldadd)
 
+genicam_SOURCES = genicam.c
+genicam_CFLAGS = -DGENICAM_FILENAME="\"$(top_srcdir)/tests/data/genicam.xml\""
+genicam_LDADD = $(test_progs_ldadd)
+
 cpp_SOURCES = cpp.cc
 cpp_LDADD = $(test_progs_ldadd)
diff --git a/tests/data/genicam.xml b/tests/data/genicam.xml
index 1c8163e..26a130a 100644
--- a/tests/data/genicam.xml
+++ b/tests/data/genicam.xml
@@ -1,82 +1,59 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <RegisterDescription
- ModelName="Model"
- VendorName="Emmanuel"
- StandardNameSpace="None"
- SchemaMajorVersion="1"
- SchemaMinorVersion="0"
- SchemaSubMinorVersion="0"
- MajorVersion="292"
- MinorVersion="0"
- SubMinorVersion="0"
- ToolTip="TestTooltip"
- ProductGuid="111-222"
- VersionGuid="222-333"
- xmlns="http://www.genicam.org/GenApi/Version_1_0";
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
- xsi:schemaLocation="http://www.genicam.org/GenApi/Version_1_0 GenApiSchema.xsd">
- <Category Name="Root" NameSpace="Standard">
-  <pFeature>AcquisitionControl</pFeature>
- </Category>
-
- <Category Name="AcquisitionControl" NameSpace="Custom">
-  <pFeature>AcquisitionStart</pFeature>
-  <pFeature>AcquisitionStop</pFeature>
- </Category>
-
- <Command Name="AcquisitionStart" NameSpace="Standard">
-  <Description>Start acquisition. Before image acquisition can occur, acquisition must be started, either by a hardware trigger or this software command.</Description>
-  <pValue>RegAcquisitionCommand</pValue>
-  <CommandValue>1</CommandValue>
- </Command>
-
- <Command Name="AcquisitionStop" NameSpace="Standard">
-  <Description>Stop acquisition. Acquisition will stop after acquisition of the current frame is complete.</Description>
-  <pValue>RegAcquisitionCommand</pValue>
-  <CommandValue>0</CommandValue>
- </Command>
-
- <IntReg Name="RegAcquisitionCommand" NameSpace="Custom">
-  <Address>0x130F4</Address>
-  <Length>4</Length>
-  <AccessMode>WO</AccessMode>
-  <pPort>Device</pPort>
-  <Sign>Unsigned</Sign>
-  <Endianess>BigEndian</Endianess>
- </IntReg>
-
- <IntReg Name="RegPixelFormat" NameSpace="Custom">
-  <Address>0x12120</Address>
-  <Length>4</Length>
-  <AccessMode>RW</AccessMode>
-  <pPort>Device</pPort>
-  <pInvalidator>BinningHorizontal</pInvalidator>
-  <pInvalidator>BinningVertical</pInvalidator>
-  <Sign>Unsigned</Sign>
-  <Endianess>BigEndian</Endianess>
- </IntReg>
-
- <IntReg Name="RegWhitebalValueMax" NameSpace="Custom">
-  <Address>0x1418C</Address>
-  <Length>4</Length>
-  <AccessMode>RW</AccessMode>
-  <pPort>Device</pPort>
-  <Sign>Unsigned</Sign>
-  <Endianess>BigEndian</Endianess>
- </IntReg>
-
- <IntSwissKnife Name="IntWidthIncrement" NameSpace="Custom">
-  <pVariable Name="FORMAT">RegPixelFormat</pVariable>
-  <Formula>((FORMAT=35127328) || (FORMAT=34603039) || (FORMAT=34340894)) ? 4 : 1</Formula>
- </IntSwissKnife>
-
- <SwissKnife Name="WhitebalValueMin" NameSpace="Custom">
-  <pVariable Name="VALUE">RegWhitebalValueMin</pVariable>
-  <Formula>(VALUE / 100)</Formula>
- </SwissKnife>
-
- <Port Name="Device" NameSpace="Standard">
- </Port>
+	ModelName="Model"
+	VendorName="Emmanuel"
+	StandardNameSpace="None"
+	SchemaMajorVersion="1"
+	SchemaMinorVersion="0"
+	SchemaSubMinorVersion="0"
+	MajorVersion="292"
+	MinorVersion="0"
+	SubMinorVersion="0"
+	ToolTip="TestTooltip"
+	ProductGuid="111-222"
+	VersionGuid="222-333"
+	xmlns="http://www.genicam.org/GenApi/Version_1_0";
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+	xsi:schemaLocation="http://www.genicam.org/GenApi/Version_1_0 GenApiSchema.xsd">
+
+	<Category Name="Root" NameSpace="Standard">
+		<pFeature>RWInteger</pFeature>
+		<pFeature>Enumeration</pFeature>
+	</Category>
+
+	<Integer Name="RWInteger">
+		<Value>1</Value>
+	</Integer>
+
+	<Enumeration Name="Enumeration">
+		<EnumEntry Name="Entry0">
+			<Value>0</Value>
+		</EnumEntry>
+		<EnumEntry Name="Entry1">
+			<Value>1</Value>
+		</EnumEntry>
+		<EnumEntry Name="EntryNotAvailable">
+			<Value>2</Value>
+			<pIsAvailable>NotAvailable</pIsAvailable>
+		</EnumEntry>
+		<EnumEntry Name="EntryNotImplemented">
+			<Value>3</Value>
+			<pIsImplemented>NotAvailable</pIsImplemented>
+		</EnumEntry>
+		<pValue>EnumerationValue</pValue>
+	</Enumeration>
+
+	<Integer Name="NotImplemented">
+		<Value>0</Value>
+	</Integer>
+
+	<Integer Name="NotAvailable">
+		<Value>0</Value>
+	</Integer>
+
+	<Integer Name="EnumerationValue">
+		<Value>0</Value>
+	</Integer>
 
 </RegisterDescription>
diff --git a/tests/genicam.c b/tests/genicam.c
new file mode 100644
index 0000000..f54d706
--- /dev/null
+++ b/tests/genicam.c
@@ -0,0 +1,79 @@
+#include <glib.h>
+#include <arv.h>
+
+static void
+integer_test (void)
+{
+	ArvDevice *device;
+	ArvGc *genicam;
+	ArvGcNode *node;
+	gint64 v_int64;
+
+	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, "RWInteger");
+	g_assert (ARV_IS_GC_INTEGER_NODE (node));
+
+	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node));
+	g_assert_cmpint (v_int64, ==, 1);
+
+	g_object_unref (device);
+}
+
+static void
+enumeration_test (void)
+{
+	ArvDevice *device;
+	ArvGc *genicam;
+	ArvGcNode *node;
+	gint64 v_int64;
+	gint64 *values;
+	guint n_values;
+
+	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, "Enumeration");
+	g_assert (ARV_IS_GC_ENUMERATION (node));
+
+	v_int64 = arv_gc_enumeration_get_int_value (ARV_GC_ENUMERATION (node));
+	g_assert_cmpint (v_int64, ==, 0);
+
+	values = arv_gc_enumeration_get_available_int_values (ARV_GC_ENUMERATION (node), &n_values);
+	g_assert_cmpint (n_values, ==, 2);
+	g_assert (values != NULL);
+
+	g_free (values);
+
+	g_object_unref (device);
+}
+
+int
+main (int argc, char *argv[])
+{
+	int result;
+	int i;
+
+	g_test_init (&argc, &argv, NULL);
+
+	g_type_init ();
+
+	arv_set_fake_camera_genicam_filename (GENICAM_FILENAME);
+
+	g_test_add_func ("/genicam/integer", integer_test);
+	g_test_add_func ("/genicam/enumeration", enumeration_test);
+
+	result = g_test_run();
+
+	arv_shutdown ();
+
+	return result;
+}
+



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