[aravis] genicam: implement Boolean node.



commit 7c2e44e5e5f010a7b2b17166e2cd370cbfe4445f
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Fri Apr 2 20:00:46 2010 +0200

    genicam: implement Boolean node.

 src/Makefile.am    |    2 +
 src/arv.h          |    1 +
 src/arvgcboolean.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/arvgcboolean.h |   60 +++++++++++++++++++++++++++
 src/arvtest.c      |    6 +++
 src/arvtypes.h     |    1 +
 6 files changed, 185 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 03b9066..baab8aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,7 @@ libaravis_la_SOURCES =				\
 	arvgc.c					\
 	arvgcnode.c				\
 	arvgccategory.c				\
+	arvgcboolean.c				\
 	arvgcenumeration.c			\
 	arvgcenumentry.c			\
 	arvgcintegernode.c			\
@@ -70,6 +71,7 @@ ARAVIS_HDRS = 					\
 	arvgc.h					\
 	arvgcnode.h				\
 	arvgccategory.h				\
+	arvgcboolean.h				\
 	arvgcenumeration.h			\
 	arvgcenumentry.h			\
 	arvgcintegernode.h			\
diff --git a/src/arv.h b/src/arv.h
index acfaac2..f44743f 100644
--- a/src/arv.h
+++ b/src/arv.h
@@ -33,6 +33,7 @@
 #include <arvgc.h>
 #include <arvgcnode.h>
 #include <arvgccategory.h>
+#include <arvgcboolean.h>
 #include <arvgcenumeration.h>
 #include <arvgcenumentry.h>
 #include <arvgcintegernode.h>
diff --git a/src/arvgcboolean.c b/src/arvgcboolean.c
new file mode 100644
index 0000000..2eda354
--- /dev/null
+++ b/src/arvgcboolean.c
@@ -0,0 +1,115 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <arvgcboolean.h>
+#include <arvgc.h>
+#include <arvtools.h>
+#include <string.h>
+
+static GObjectClass *parent_class = NULL;
+
+/* ArvGcNode implementation */
+
+static void
+arv_gc_boolean_add_element (ArvGcNode *node, const char *name, const char *content, const char **attributes)
+{
+	ArvGcBoolean *gc_boolean = ARV_GC_BOOLEAN (node);
+
+	if (strcmp (name, "Value") == 0) {
+		arv_force_g_value_to_int64 (&gc_boolean->value,
+					    g_ascii_strtoll (content, NULL, 0));
+	} else if (strcmp (name, "pValue") == 0) {
+		arv_force_g_value_to_string (&gc_boolean->value, content);
+	} else if (strcmp (name, "OnValue") == 0) {
+		gc_boolean->on_value = g_ascii_strtoll (content, NULL, 0);
+	} else if (strcmp (name, "OffValue") == 0) {
+		gc_boolean->off_value = g_ascii_strtoll (content, NULL, 0);
+	} else
+		ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
+}
+
+/* ArvGcBoolean implementation */
+
+gboolean
+arv_gc_boolean_get_value (ArvGcBoolean *gc_boolean)
+{
+	g_return_val_if_fail (ARV_IS_GC_BOOLEAN (gc_boolean), FALSE);
+
+	return arv_gc_get_int64_from_value (arv_gc_node_get_genicam (ARV_GC_NODE (gc_boolean)),
+					    &gc_boolean->value) == gc_boolean->on_value;
+}
+
+void
+arv_gc_boolean_set_value (ArvGcBoolean *gc_boolean, gboolean v_boolean)
+{
+	g_return_if_fail (ARV_IS_GC_BOOLEAN (gc_boolean));
+
+	arv_gc_set_int64_to_value (arv_gc_node_get_genicam (ARV_GC_NODE (gc_boolean)),
+				   &gc_boolean->value,
+				   v_boolean ? gc_boolean->on_value : gc_boolean->off_value);
+}
+
+ArvGcNode *
+arv_gc_boolean_new (void)
+{
+	ArvGcNode *node;
+
+	node = g_object_new (ARV_TYPE_GC_BOOLEAN, NULL);
+
+	return node;
+}
+
+static void
+arv_gc_boolean_init (ArvGcBoolean *gc_boolean)
+{
+	g_value_init (&gc_boolean->value, G_TYPE_INT64);
+	g_value_set_int64 (&gc_boolean->value, 0);
+	gc_boolean->on_value = 1;
+	gc_boolean->off_value = 0;
+}
+
+static void
+arv_gc_boolean_finalize (GObject *object)
+{
+	ArvGcBoolean *gc_boolean = ARV_GC_BOOLEAN (object);
+
+	g_value_unset (&gc_boolean->value);
+
+	parent_class->finalize (object);
+}
+
+static void
+arv_gc_boolean_class_init (ArvGcBooleanClass *boolean_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (boolean_class);
+	ArvGcNodeClass *node_class = ARV_GC_NODE_CLASS (boolean_class);
+
+	parent_class = g_type_class_peek_parent (boolean_class);
+
+	object_class->finalize = arv_gc_boolean_finalize;
+
+	node_class->add_element = arv_gc_boolean_add_element;
+}
+
+/* ArvGcInteger interface implementation */
+
+G_DEFINE_TYPE (ArvGcBoolean, arv_gc_boolean, ARV_TYPE_GC_NODE)
diff --git a/src/arvgcboolean.h b/src/arvgcboolean.h
new file mode 100644
index 0000000..3436325
--- /dev/null
+++ b/src/arvgcboolean.h
@@ -0,0 +1,60 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef ARV_GC_BOOLEAN_H
+#define ARV_GC_BOOLEAN_H
+
+#include <arvtypes.h>
+#include <arvgcnode.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_GC_BOOLEAN             (arv_gc_boolean_get_type ())
+#define ARV_GC_BOOLEAN(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_GC_BOOLEAN, ArvGcBoolean))
+#define ARV_GC_BOOLEAN_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_GC_BOOLEAN, ArvGcBooleanClass))
+#define ARV_IS_GC_BOOLEAN(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_GC_BOOLEAN))
+#define ARV_IS_GC_BOOLEAN_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_GC_BOOLEAN))
+#define ARV_GC_BOOLEAN_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_GC_BOOLEAN, ArvGcBooleanClass))
+
+typedef struct _ArvGcBooleanClass ArvGcBooleanClass;
+
+struct _ArvGcBoolean {
+	ArvGcNode	node;
+
+	GValue value;
+	gint64 on_value;
+	gint64 off_value;
+};
+
+struct _ArvGcBooleanClass {
+	ArvGcNodeClass parent_class;
+};
+
+GType 		arv_gc_boolean_get_type 	(void);
+
+ArvGcNode * 	arv_gc_boolean_new 		(void);
+gboolean 	arv_gc_boolean_get_value 	(ArvGcBoolean *gc_boolean);
+void 		arv_gc_boolean_set_value 	(ArvGcBoolean *gc_boolean, gboolean v_boolean);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvtest.c b/src/arvtest.c
index 0cec546..6dba0cc 100644
--- a/src/arvtest.c
+++ b/src/arvtest.c
@@ -97,6 +97,7 @@ main (int argc, char **argv)
 		double v_double_min;
 		double v_double_max;
 		const char *v_string;
+		gboolean v_boolean;
 
 		genicam = arv_device_get_genicam (device);
 
@@ -160,6 +161,11 @@ main (int argc, char **argv)
 		node = arv_gc_get_node (genicam, "TriggerSelector");
 		v_string = arv_gc_enumeration_get_string_value (ARV_GC_ENUMERATION (node));
 		g_print ("trigger selector    = %s\n", v_string);
+		node = arv_gc_get_node (genicam, "ReverseX");
+		if (node != NULL) {
+			v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node));
+			g_print ("reverse x          = %s\n", v_boolean ? "TRUE" : "FALSE");
+		}
 
 		stream = arv_device_get_stream (device);
 		if (arv_option_auto_buffer)
diff --git a/src/arvtypes.h b/src/arvtypes.h
index 608413f..5373b84 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -35,6 +35,7 @@ typedef struct _ArvGc 			ArvGc;
 
 typedef struct _ArvGcNode 		ArvGcNode;
 typedef struct _ArvGcCategory		ArvGcCategory;
+typedef struct _ArvGcBoolean		ArvGcBoolean;
 typedef struct _ArvGcEnumeration	ArvGcEnumeration;
 typedef struct _ArvGcEnumEntry		ArvGcEnumEntry;
 typedef struct _ArvGcIntegerNode	ArvGcIntegerNode;



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