[aravis] control: add an option for the listing of available features.



commit 41115c3ce2bdd6342f34389e55a1be7c1279e941
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Jun 20 15:49:09 2011 +0200

    control: add an option for the listing of available features.

 docs/reference/aravis/aravis-sections.txt |    2 +
 src/arvcontrol.c                          |   36 ++++++++++++++++++++++++++++-
 src/arvgcboolean.c                        |    7 +++++
 src/arvgccategory.c                       |   36 ++++++++++++++++++++++++++--
 src/arvgccategory.h                       |    5 +++-
 src/arvgccommand.c                        |    7 +++++
 src/arvgcconverter.c                      |   12 +++++++++
 src/arvgcenumentry.c                      |    7 +++++
 src/arvgcenumeration.c                    |    7 +++++
 src/arvgcfloatnode.c                      |    7 +++++
 src/arvgcintegernode.c                    |    7 +++++
 src/arvgcnode.c                           |   23 ++++++++++++++++++
 src/arvgcnode.h                           |    3 ++
 src/arvgcport.c                           |    9 +++++++
 src/arvgcregister.c                       |   22 +++++++++++++++++
 src/arvgcswissknife.c                     |   12 +++++++++
 16 files changed, 197 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 09f0eb1..b6afe16 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -334,6 +334,7 @@ ArvFakeDevicePrivate
 <TITLE>ArvGcNode</TITLE>
 ArvGcNode
 arv_gc_node_new
+arv_gc_node_get_node_name
 arv_gc_node_get_value_type
 arv_gc_node_get_value_as_string
 arv_gc_node_set_value_from_string
@@ -494,6 +495,7 @@ ArvGcBooleanClass
 <TITLE>ArvGcCategory</TITLE>
 ArvGcCategory
 arv_gc_category_new
+arv_gc_category_get_features
 <SUBSECTION Standard>
 ARV_GC_CATEGORY
 ARV_IS_GC_CATEGORY
diff --git a/src/arvcontrol.c b/src/arvcontrol.c
index 3563ef7..9d865f4 100644
--- a/src/arvcontrol.c
+++ b/src/arvcontrol.c
@@ -3,17 +3,46 @@
 #include <stdio.h>
 
 static char *arv_option_device_name = NULL;
+static gboolean arv_option_list = FALSE;
 static char *arv_option_debug_domains = NULL;
 
 static const GOptionEntry arv_option_entries[] =
 {
 	{ "name",		'n', 0, G_OPTION_ARG_STRING,
 		&arv_option_device_name,"Camera name", NULL},
+	{ "list",		'l', 0, G_OPTION_ARG_NONE,
+		&arv_option_list,	"List available features", NULL},
 	{ "debug", 		'd', 0, G_OPTION_ARG_STRING,
 		&arv_option_debug_domains, 	"Debug domains", NULL },
 	{ NULL }
 };
 
+static void
+arv_control_list_features (ArvGc *genicam, const char *feature, int level)
+{
+	ArvGcNode *node;
+
+	node = arv_gc_get_node (genicam, feature);
+	if (ARV_IS_GC_NODE (node)) {
+		int i;
+
+		for (i = 0; i < level; i++)
+			printf ("    ");
+
+		printf ("%s: '%s'\n", arv_gc_node_get_node_name (node), feature);
+
+		if (ARV_IS_GC_CATEGORY (node)) {
+			const GSList *features;
+			const GSList *iter;
+
+			features = arv_gc_category_get_features (ARV_GC_CATEGORY (node));
+
+			for (iter = features; iter != NULL; iter = iter->next)
+				arv_control_list_features (genicam, iter->data, level + 1);
+		}
+	}
+}
+
 int
 main (int argc, char **argv)
 {
@@ -45,7 +74,12 @@ main (int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	if (argc < 2) {
+	if (arv_option_list) {
+		ArvGc *genicam;
+
+		genicam = arv_device_get_genicam (device);
+		arv_control_list_features (genicam, "Root",0);
+	} else if (argc < 2) {
 	} else
 		for (i = 1; i < argc; i++) {
 			ArvGcNode *feature;
diff --git a/src/arvgcboolean.c b/src/arvgcboolean.c
index 6ebd287..840c0bb 100644
--- a/src/arvgcboolean.c
+++ b/src/arvgcboolean.c
@@ -34,6 +34,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_boolean_get_node_name (ArvGcNode *node)
+{
+	return "Boolean";
+}
+
 static void
 arv_gc_boolean_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -124,6 +130,7 @@ arv_gc_boolean_class_init (ArvGcBooleanClass *boolean_class)
 
 	object_class->finalize = arv_gc_boolean_finalize;
 
+	node_class->get_node_name = arv_gc_boolean_get_node_name;
 	node_class->add_element = arv_gc_boolean_add_element;
 	node_class->set_value_from_string = arv_gc_boolean_set_value_from_string;
 	node_class->get_value_as_string = arv_gc_boolean_get_value_as_string;
diff --git a/src/arvgccategory.c b/src/arvgccategory.c
index 224c699..4a3c0fb 100644
--- a/src/arvgccategory.c
+++ b/src/arvgccategory.c
@@ -33,19 +33,42 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_category_get_node_name (ArvGcNode *node)
+{
+	return "Category";
+}
+
 static void
 arv_gc_category_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
-/*        ArvGcCategory *gc_category = ARV_GC_CATEGORY (node);*/
+	ArvGcCategory *category = ARV_GC_CATEGORY (node);
 
 	if (strcmp (name, "pFeature") == 0) {
-		/* TODO */
+		category->features = g_slist_append (category->features, g_strdup (content));
 	} else
 		ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
 }
 
 /* ArvGcCategory implementation */
 
+/**
+ * arv_gc_category_get_features:
+ * @category: a #ArvGcCategory
+ *
+ * Get a list of strings with the name of the features listed in the given category node.
+ *
+ * Returns: a list of strings.
+ */
+
+const GSList *
+arv_gc_category_get_features (ArvGcCategory *category)
+{
+	g_return_val_if_fail (ARV_IS_GC_CATEGORY (category), NULL);
+
+	return category->features;
+}
+
 ArvGcNode *
 arv_gc_category_new (void)
 {
@@ -59,12 +82,18 @@ arv_gc_category_new (void)
 static void
 arv_gc_category_init (ArvGcCategory *gc_category)
 {
+	gc_category->features = NULL;
 }
 
 static void
 arv_gc_category_finalize (GObject *object)
 {
-/*        ArvGcCategory *gc_category = ARV_GC_CATEGORY (object);*/
+	ArvGcCategory *gc_category = ARV_GC_CATEGORY (object);
+	GSList *iter;
+
+	for (iter = gc_category->features; iter != NULL; iter = iter->next)
+		g_free (iter->data);
+	g_slist_free (gc_category->features);
 
 	parent_class->finalize (object);
 }
@@ -79,6 +108,7 @@ arv_gc_category_class_init (ArvGcCategoryClass *category_class)
 
 	object_class->finalize = arv_gc_category_finalize;
 
+	node_class->get_node_name = arv_gc_category_get_node_name;
 	node_class->add_element = arv_gc_category_add_element;
 }
 
diff --git a/src/arvgccategory.h b/src/arvgccategory.h
index 52da852..48dad09 100644
--- a/src/arvgccategory.h
+++ b/src/arvgccategory.h
@@ -39,6 +39,8 @@ typedef struct _ArvGcCategoryClass ArvGcCategoryClass;
 
 struct _ArvGcCategory {
 	ArvGcNode	node;
+
+	GSList *features;
 };
 
 struct _ArvGcCategoryClass {
@@ -47,7 +49,8 @@ struct _ArvGcCategoryClass {
 
 GType 		arv_gc_category_get_type 	(void);
 
-ArvGcNode * 	arv_gc_category_new 	(void);
+ArvGcNode * 	arv_gc_category_new 		(void);
+const GSList * 	arv_gc_category_get_features 	(ArvGcCategory *category);
 
 G_END_DECLS
 
diff --git a/src/arvgccommand.c b/src/arvgccommand.c
index d65c21a..73dc778 100644
--- a/src/arvgccommand.c
+++ b/src/arvgccommand.c
@@ -38,6 +38,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_command_get_node_name (ArvGcNode *node)
+{
+	return "Command";
+}
+
 static void
 arv_gc_command_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -116,6 +122,7 @@ arv_gc_command_class_init (ArvGcCommandClass *command_class)
 
 	object_class->finalize = arv_gc_command_finalize;
 
+	node_class->get_node_name = arv_gc_command_get_node_name;
 	node_class->add_element = arv_gc_command_add_element;
 }
 
diff --git a/src/arvgcconverter.c b/src/arvgcconverter.c
index d9c9369..ab44dfd 100644
--- a/src/arvgcconverter.c
+++ b/src/arvgcconverter.c
@@ -44,6 +44,17 @@ typedef struct {
 	char *node_name;
 } ArvGcConverterVariableInfos;
 
+static const char *
+arv_gc_converter_get_node_name (ArvGcNode *node)
+{
+	ArvGcConverter *gc_converter = ARV_GC_CONVERTER (node);
+
+	if (gc_converter->value_type == G_TYPE_DOUBLE)
+		return "Converter";
+
+	return "IntConverter";
+}
+
 static void
 arv_gc_converter_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -159,6 +170,7 @@ arv_gc_converter_class_init (ArvGcConverterClass *converter_class)
 
 	object_class->finalize = arv_gc_converter_finalize;
 
+	node_class->get_node_name = arv_gc_converter_get_node_name;
 	node_class->add_element = arv_gc_converter_add_element;
 	node_class->get_value_type = arv_gc_converter_node_get_value_type;
 }
diff --git a/src/arvgcenumentry.c b/src/arvgcenumentry.c
index 7be74d9..bcb6202 100644
--- a/src/arvgcenumentry.c
+++ b/src/arvgcenumentry.c
@@ -33,6 +33,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_enum_entry_get_node_name (ArvGcNode *node)
+{
+	return "EnumEntry";
+}
+
 static void
 arv_gc_enum_entry_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -88,6 +94,7 @@ arv_gc_enum_entry_class_init (ArvGcEnumEntryClass *enum_entry_class)
 
 	object_class->finalize = arv_gc_enum_entry_finalize;
 
+	node_class->get_node_name = arv_gc_enum_entry_get_node_name;
 	node_class->add_element = arv_gc_enum_entry_add_element;
 }
 
diff --git a/src/arvgcenumeration.c b/src/arvgcenumeration.c
index 16b7617..b606b25 100644
--- a/src/arvgcenumeration.c
+++ b/src/arvgcenumeration.c
@@ -36,6 +36,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_enumeration_get_node_name (ArvGcNode *node)
+{
+	return "Enumeration";
+}
+
 static gboolean
 arv_gc_enumeration_can_add_child (ArvGcNode *node, ArvGcNode *child)
 {
@@ -218,6 +224,7 @@ arv_gc_enumeration_class_init (ArvGcEnumerationClass *enumeration_class)
 
 	object_class->finalize = arv_gc_enumeration_finalize;
 
+	node_class->get_node_name = arv_gc_enumeration_get_node_name;
 	node_class->add_element = arv_gc_enumeration_add_element;
 	node_class->can_add_child = arv_gc_enumeration_can_add_child;
 	node_class->set_value_from_string = arv_gc_enumeration_set_value_from_string;
diff --git a/src/arvgcfloatnode.c b/src/arvgcfloatnode.c
index b23d19a..c3e228d 100644
--- a/src/arvgcfloatnode.c
+++ b/src/arvgcfloatnode.c
@@ -35,6 +35,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_float_node_get_node_name (ArvGcNode *node)
+{
+	return "Float";
+}
+
 static void
 arv_gc_float_node_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -146,6 +152,7 @@ arv_gc_float_node_class_init (ArvGcFloatNodeClass *float_node_class)
 
 	object_class->finalize = arv_gc_float_node_finalize;
 
+	node_class->get_node_name = arv_gc_float_node_get_node_name;
 	node_class->add_element = arv_gc_float_node_add_element;
 	node_class->get_value_type = arv_gc_float_node_get_value_type;
 	node_class->set_value_from_string = arv_gc_float_node_set_value_from_string;
diff --git a/src/arvgcintegernode.c b/src/arvgcintegernode.c
index 6765296..488223f 100644
--- a/src/arvgcintegernode.c
+++ b/src/arvgcintegernode.c
@@ -36,6 +36,12 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_integer_node_get_node_name (ArvGcNode *node)
+{
+	return "Integer";
+}
+
 static void
 arv_gc_integer_node_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -144,6 +150,7 @@ arv_gc_integer_node_class_init (ArvGcIntegerNodeClass *integer_node_class)
 
 	object_class->finalize = arv_gc_integer_node_finalize;
 
+	node_class->get_node_name = arv_gc_integer_node_get_node_name;
 	node_class->add_element = arv_gc_integer_node_add_element;
 	node_class->get_value_type = arv_gc_integer_node_get_value_type;
 	node_class->set_value_from_string = arv_gc_integer_node_set_value_from_string;
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index c572ddc..1010426 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -199,6 +199,29 @@ arv_gc_node_new (void)
 	return node;
 }
 
+/**
+ * arv_gc_node_get_node_name:
+ * @gc_node: a #ArvGcNode
+ *
+ * Retrieves the Genicam name of the given node ("Integer", "IntReg", ...).
+ *
+ * Returns: The node name, %NULL on error.
+ */
+
+const char *
+arv_gc_node_get_node_name (ArvGcNode *gc_node)
+{
+	ArvGcNodeClass *gc_node_class;
+
+	g_return_val_if_fail (ARV_IS_GC_NODE (gc_node), FALSE);
+
+	gc_node_class = ARV_GC_NODE_GET_CLASS (gc_node);
+	if (gc_node_class->get_node_name != NULL)
+	       return gc_node_class->get_node_name (gc_node);
+
+	return NULL;
+}
+
 void
 arv_gc_node_set_genicam	(ArvGcNode *node, ArvGc *genicam)
 {
diff --git a/src/arvgcnode.h b/src/arvgcnode.h
index 16cb586..f4d413c 100644
--- a/src/arvgcnode.h
+++ b/src/arvgcnode.h
@@ -46,6 +46,8 @@ struct _ArvGcNode {
 struct _ArvGcNodeClass {
 	GObjectClass parent_class;
 
+	const char *	(*get_node_name)		(ArvGcNode *gc_node);
+
 	void		(*set_attribute)		(ArvGcNode *gc_node, const char *name, const char *value);
 	void 		(*add_element)			(ArvGcNode *gc_node, const char *name, const char *content,
 							 const char **attributes);
@@ -59,6 +61,7 @@ struct _ArvGcNodeClass {
 GType arv_gc_node_get_type (void);
 
 ArvGcNode * 	arv_gc_node_new 			(void);
+const char *	arv_gc_node_get_node_name		(ArvGcNode *gc_node);
 GType 		arv_gc_node_get_value_type 		(ArvGcNode *gc_node);
 void		arv_gc_node_set_value_from_string	(ArvGcNode *gc_node, const char *string);
 const char *	arv_gc_node_get_value_as_string		(ArvGcNode *gc_node);
diff --git a/src/arvgcport.c b/src/arvgcport.c
index abedcd0..cdc231e 100644
--- a/src/arvgcport.c
+++ b/src/arvgcport.c
@@ -31,6 +31,12 @@
 
 static GObjectClass *parent_class = NULL;
 
+static const char *
+arv_gc_port_get_node_name (ArvGcNode *node)
+{
+	return "Port";
+}
+
 void
 arv_gc_port_read (ArvGcPort *port, void *buffer, guint64 address, guint64 length)
 {
@@ -84,10 +90,13 @@ static void
 arv_gc_port_class_init (ArvGcPortClass *port_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (port_class);
+	ArvGcNodeClass *node_class = ARV_GC_NODE_CLASS (port_class);
 
 	parent_class = g_type_class_peek_parent (port_class);
 
 	object_class->finalize = arv_gc_port_finalize;
+
+	node_class->get_node_name = arv_gc_port_get_node_name;
 }
 
 G_DEFINE_TYPE (ArvGcPort, arv_gc_port, ARV_TYPE_GC_NODE)
diff --git a/src/arvgcregister.c b/src/arvgcregister.c
index e1a6858..9001c4a 100644
--- a/src/arvgcregister.c
+++ b/src/arvgcregister.c
@@ -45,6 +45,27 @@ static GObjectClass *parent_class = NULL;
 
 /* ArvGcNode implementation */
 
+static const char *
+arv_gc_register_get_node_name (ArvGcNode *node)
+{
+	ArvGcRegister *gc_register = ARV_GC_REGISTER (node);
+
+	switch (gc_register->type) {
+		case ARV_GC_REGISTER_TYPE_REGISTER:
+			return "Register";
+		case ARV_GC_REGISTER_TYPE_INTEGER:
+			return "IntReg";
+		case ARV_GC_REGISTER_TYPE_MASKED_INTEGER:
+			return "MaskedIntReg";
+		case ARV_GC_REGISTER_TYPE_FLOAT:
+			return "FloatReg";
+		case ARV_GC_REGISTER_TYPE_STRING:
+			return "StringReg";
+	}
+
+	return NULL;
+}
+
 static void
 arv_gc_register_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -469,6 +490,7 @@ arv_gc_register_class_init (ArvGcRegisterClass *register_class)
 
 	object_class->finalize = arv_gc_register_finalize;
 
+	node_class->get_node_name = arv_gc_register_get_node_name;
 	node_class->add_element = arv_gc_register_add_element;
 	node_class->get_value_type = arv_gc_register_get_value_type;
 	node_class->set_value_from_string = arv_gc_register_set_value_from_string;
diff --git a/src/arvgcswissknife.c b/src/arvgcswissknife.c
index 66009b3..dc0d8b9 100644
--- a/src/arvgcswissknife.c
+++ b/src/arvgcswissknife.c
@@ -43,6 +43,17 @@ typedef struct {
 	char *node_name;
 } ArvGcSwissKnifeVariableInfos;
 
+static const char *
+arv_gc_swiss_knife_get_node_name (ArvGcNode *node)
+{
+	ArvGcSwissKnife *gc_swiss_knife = ARV_GC_SWISS_KNIFE (node);
+
+	if (gc_swiss_knife->value_type == G_TYPE_DOUBLE)
+		return "SwissKnife";
+
+	return "IntSwissKnife";
+}
+
 static void
 arv_gc_swiss_knife_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
 {
@@ -148,6 +159,7 @@ arv_gc_swiss_knife_class_init (ArvGcSwissKnifeClass *swiss_knife_class)
 
 	object_class->finalize = arv_gc_swiss_knife_finalize;
 
+	node_class->get_node_name = arv_gc_swiss_knife_get_node_name;
 	node_class->add_element = arv_gc_swiss_knife_add_element;
 	node_class->get_value_type = arv_gc_swiss_knife_node_get_value_type;
 }



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