[aravis] genicam: Enumeration and EnumEntry implementation.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] genicam: Enumeration and EnumEntry implementation.
- Date: Fri, 2 Apr 2010 14:16:52 +0000 (UTC)
commit 8e8f134986a47b1aa5ce41b9949cc431a6f66ced
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Fri Apr 2 16:05:56 2010 +0200
genicam: Enumeration and EnumEntry implementation.
src/arvgc.c | 7 ++--
src/arvgcenumentry.c | 8 +++++
src/arvgcenumentry.h | 3 +-
src/arvgcenumeration.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++-
src/arvgcenumeration.h | 7 ++++
src/arvgcnode.c | 15 +++++++++
src/arvgcnode.h | 2 +
src/arvtest.c | 4 ++
8 files changed, 117 insertions(+), 6 deletions(-)
---
diff --git a/src/arvgc.c b/src/arvgc.c
index 3399236..201f9e3 100644
--- a/src/arvgc.c
+++ b/src/arvgc.c
@@ -67,9 +67,9 @@ arv_gc_create_node (ArvGc *genicam, const char *type)
else if (strcmp (type, "Float") == 0)
node = arv_gc_float_node_new ();
else if (strcmp (type, "Enumeration") == 0)
- node = arv_gc_enum_entry_new ();
- else if (strcmp (type, "EnumEntry") == 0)
node = arv_gc_enumeration_new ();
+ else if (strcmp (type, "EnumEntry") == 0)
+ node = arv_gc_enum_entry_new ();
else if (strcmp (type, "SwissKnife") == 0)
node = arv_gc_swiss_knife_new ();
else if (strcmp (type, "IntSwissKnife") == 0)
@@ -197,7 +197,8 @@ arv_gc_parser_end_element (void *user_data,
}
} else if (state->level > 2) {
if (state->level == 3 && state->level_3_node != NULL) {
- if (state->level_2_node != NULL)
+ if (state->level_2_node != NULL &&
+ arv_gc_node_can_add_child (state->level_2_node, state->level_3_node))
arv_gc_node_add_child (state->level_2_node, state->level_3_node);
else
g_object_unref (state->level_3_node);
diff --git a/src/arvgcenumentry.c b/src/arvgcenumentry.c
index d11f915..af7338a 100644
--- a/src/arvgcenumentry.c
+++ b/src/arvgcenumentry.c
@@ -41,6 +41,14 @@ arv_gc_enum_entry_add_element (ArvGcNode *node, const char *name, const char *co
/* ArvGcEnumEntry implementation */
+gint64
+arv_gc_enum_entry_get_value (ArvGcEnumEntry *entry)
+{
+ g_return_val_if_fail (ARV_IS_GC_ENUM_ENTRY (entry), 0);
+
+ return entry->value;
+}
+
ArvGcNode *
arv_gc_enum_entry_new (void)
{
diff --git a/src/arvgcenumentry.h b/src/arvgcenumentry.h
index 786bcc1..12d0eef 100644
--- a/src/arvgcenumentry.h
+++ b/src/arvgcenumentry.h
@@ -49,7 +49,8 @@ struct _ArvGcEnumEntryClass {
GType arv_gc_enum_entry_get_type (void);
-ArvGcNode * arv_gc_enum_entry_new (void);
+ArvGcNode * arv_gc_enum_entry_new (void);
+gint64 arv_gc_enum_entry_get_value (ArvGcEnumEntry *entry);
G_END_DECLS
diff --git a/src/arvgcenumeration.c b/src/arvgcenumeration.c
index f71c3a4..b161035 100644
--- a/src/arvgcenumeration.c
+++ b/src/arvgcenumeration.c
@@ -21,6 +21,7 @@
*/
#include <arvgcenumeration.h>
+#include <arvgcenumentry.h>
#include <arvgc.h>
#include <string.h>
@@ -28,12 +29,21 @@ static GObjectClass *parent_class = NULL;
/* ArvGcNode implementation */
+static gboolean
+arv_gc_enumeration_can_add_child (ArvGcNode *node, ArvGcNode *child)
+{
+ if (ARV_IS_GC_ENUM_ENTRY (child))
+ return TRUE;
+
+ return FALSE;
+}
+
static void
arv_gc_enumeration_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
{
/* ArvGcEnumeration *gc_enumeration = ARV_GC_ENUMERATION (node);*/
- if (strcmp (name, "pFeature") == 0) {
+ if (strcmp (name, "pValue") == 0) {
g_warning ("TODO");
} else
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
@@ -41,6 +51,64 @@ arv_gc_enumeration_add_element (ArvGcNode *node, const char *name, const char *c
/* ArvGcEnumeration implementation */
+const char *
+arv_gc_enumeration_get_string_value (ArvGcEnumeration *enumeration)
+{
+ const GSList *iter;
+ gint64 value;
+
+ 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);
+
+ for (iter = arv_gc_node_get_childs (ARV_GC_NODE (enumeration)); iter != NULL; iter = iter->next)
+ if (arv_gc_enum_entry_get_value (iter->data) == value)
+ return arv_gc_node_get_name (iter->data);
+
+ return NULL;
+}
+
+void
+arv_gc_enumeration_set_string_value (ArvGcEnumeration *enumeration, const char *value)
+{
+ const GSList *iter;
+
+ g_return_if_fail (ARV_IS_GC_ENUMERATION (enumeration));
+
+ for (iter = arv_gc_node_get_childs (ARV_GC_NODE (enumeration)); iter != NULL; iter = iter->next)
+ if (g_strcmp0 (arv_gc_node_get_name (iter->data), value) ==0)
+ 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));
+}
+
+gint64
+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);
+}
+
+void
+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);
+}
+
+const GSList *
+arv_gc_enumeration_get_entries (ArvGcEnumeration *enumeration)
+{
+ g_return_val_if_fail (ARV_IS_GC_ENUMERATION (enumeration), NULL);
+
+ return arv_gc_node_get_childs (ARV_GC_NODE (enumeration));
+}
+
ArvGcNode *
arv_gc_enumeration_new (void)
{
@@ -54,12 +122,16 @@ 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 *gc_enumeration = ARV_GC_ENUMERATION (object);
+
+ g_value_unset (&gc_enumeration->value);
parent_class->finalize (object);
}
@@ -75,6 +147,7 @@ arv_gc_enumeration_class_init (ArvGcEnumerationClass *enumeration_class)
object_class->finalize = arv_gc_enumeration_finalize;
node_class->add_element = arv_gc_enumeration_add_element;
+ node_class->can_add_child = arv_gc_enumeration_can_add_child;
}
G_DEFINE_TYPE (ArvGcEnumeration, arv_gc_enumeration, ARV_TYPE_GC_NODE)
diff --git a/src/arvgcenumeration.h b/src/arvgcenumeration.h
index 414a798..88b5c8f 100644
--- a/src/arvgcenumeration.h
+++ b/src/arvgcenumeration.h
@@ -39,6 +39,8 @@ typedef struct _ArvGcEnumerationClass ArvGcEnumerationClass;
struct _ArvGcEnumeration {
ArvGcNode node;
+
+ GValue value;
};
struct _ArvGcEnumerationClass {
@@ -48,6 +50,11 @@ 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);
G_END_DECLS
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index dc9a49f..71a2af7 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -120,6 +120,21 @@ arv_gc_node_add_element (ArvGcNode *node, const char *name, const char *content,
ARV_GC_NODE_GET_CLASS (node)->add_element (node, name, content, attributes);
}
+gboolean
+arv_gc_node_can_add_child (ArvGcNode *node, ArvGcNode *child)
+{
+ ArvGcNodeClass *node_class;
+
+ g_return_val_if_fail (ARV_IS_GC_NODE (node), FALSE);
+ g_return_val_if_fail (ARV_IS_GC_NODE (child), FALSE);
+
+ node_class = ARV_GC_NODE_GET_CLASS (node);
+ if (node_class->can_add_child == NULL)
+ return FALSE;
+
+ return node_class->can_add_child (node, child);
+}
+
void
arv_gc_node_add_child (ArvGcNode *node, ArvGcNode *child)
{
diff --git a/src/arvgcnode.h b/src/arvgcnode.h
index e31cda1..ac98284 100644
--- a/src/arvgcnode.h
+++ b/src/arvgcnode.h
@@ -50,6 +50,7 @@ struct _ArvGcNodeClass {
void (*add_element) (ArvGcNode *node, const char *name, const char *content,
const char **attributes);
GType (*get_value_type) (ArvGcNode *node);
+ gboolean (*can_add_child) (ArvGcNode *node, ArvGcNode *child);
};
GType arv_gc_node_get_type (void);
@@ -64,6 +65,7 @@ const char * arv_gc_node_get_description (ArvGcNode *node);
void arv_gc_node_set_attribute (ArvGcNode *node, const char *name, const char *value);
void arv_gc_node_add_element (ArvGcNode *node, const char *name, const char *content,
const char **attributes);
+gboolean arv_gc_node_can_add_child (ArvGcNode *node, ArvGcNode *child);
void arv_gc_node_add_child (ArvGcNode *node, ArvGcNode *child);
const GSList * arv_gc_node_get_childs (ArvGcNode *node);
diff --git a/src/arvtest.c b/src/arvtest.c
index 985180b..f5bfc62 100644
--- a/src/arvtest.c
+++ b/src/arvtest.c
@@ -96,6 +96,7 @@ main (int argc, char **argv)
double v_double;
double v_double_min;
double v_double_max;
+ const char *v_string;
genicam = arv_device_get_genicam (device);
@@ -150,6 +151,9 @@ main (int argc, char **argv)
maximum = arv_gc_integer_get_max (ARV_GC_INTEGER (node));
minimum = arv_gc_integer_get_min (ARV_GC_INTEGER (node));
g_print ("gain = %d (min:%d - max:%d)\n", value, minimum, maximum);
+ node = arv_gc_get_node (genicam, "GainAuto");
+ v_string = arv_gc_enumeration_get_string_value (ARV_GC_ENUMERATION (node));
+ g_print ("gain auto mode = %s\n", v_string);
stream = arv_device_get_stream (device);
if (arv_option_auto_buffer)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]