[aravis] genicam: implement String interface in GcRegister for StringReg.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] genicam: implement String interface in GcRegister for StringReg.
- Date: Wed, 7 Apr 2010 12:44:10 +0000 (UTC)
commit ed86c691dd9614eb317c03f4c5bc57811ede9f85
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Wed Apr 7 14:43:40 2010 +0200
genicam: implement String interface in GcRegister for StringReg.
src/Makefile.am | 2 +
src/arv.h | 1 +
src/arvgcregister.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-
src/arvgcstring.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/arvgcstring.h | 53 +++++++++++++++++++++++++++++++++++++++++++
src/arvtest.c | 9 +++++++
src/arvtypes.h | 1 +
7 files changed, 185 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f3cdcc..ceba2a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,7 @@ libaravis_la_SOURCES = \
arvgcconverter.c \
arvgcport.c \
arvgcinteger.c \
+ arvgcstring.c \
arvgcfloat.c \
arvinterface.c \
arvdevice.c \
@@ -82,6 +83,7 @@ ARAVIS_HDRS = \
arvgcconverter.h \
arvgcport.h \
arvgcinteger.h \
+ arvgcstring.h \
arvgcfloat.h \
arvinterface.h \
arvdevice.h \
diff --git a/src/arv.h b/src/arv.h
index f44743f..53b351f 100644
--- a/src/arv.h
+++ b/src/arv.h
@@ -45,6 +45,7 @@
#include <arvgcport.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
+#include <arvgcstring.h>
#include <arvinterface.h>
#include <arvdevice.h>
#include <arvstream.h>
diff --git a/src/arvgcregister.c b/src/arvgcregister.c
index 6baee50..6fc5abe 100644
--- a/src/arvgcregister.c
+++ b/src/arvgcregister.c
@@ -23,6 +23,7 @@
#include <arvgcregister.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
+#include <arvgcstring.h>
#include <arvgcport.h>
#include <arvgc.h>
#include <arvtools.h>
@@ -507,6 +508,12 @@ static void
arv_gc_register_set_float_value (ArvGcFloat *gc_float, double v_double)
{
ArvGcRegister *gc_register = ARV_GC_REGISTER (gc_float);
+ ArvGc *genicam;
+
+ genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register));
+ g_return_if_fail (ARV_IS_GC (genicam));
+
+ _update_cache_size (gc_register, genicam);
if (gc_register->cache_size == 4) {
float v_float = v_double;
@@ -530,7 +537,55 @@ arv_gc_register_float_interface_init (ArvGcFloatInterface *interface)
interface->set_value = arv_gc_register_set_float_value;
}
+static const char *
+arv_gc_register_get_string_value (ArvGcString *gc_string)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (gc_string);
+
+ _read_cache (gc_register);
+
+ if (gc_register->cache_size > 0)
+ ((char *) gc_register->cache)[gc_register->cache_size - 1] = '\0';
+
+ return gc_register->cache;
+}
+
+static void
+arv_gc_register_set_string_value (ArvGcString *gc_string, const char *value)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (gc_string);
+ ArvGc *genicam;
+
+ genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register));
+ g_return_if_fail (ARV_IS_GC (genicam));
+
+ _update_cache_size (gc_register, genicam);
+
+ if (gc_register->cache_size > 0) {
+ strncpy (gc_register->cache, value, gc_register->cache_size);
+ ((char *) gc_register->cache)[gc_register->cache_size - 1] = '\0';
+
+ _write_cache (gc_register);
+ }
+}
+
+static gint64
+arv_gc_register_get_max_string_length (ArvGcString *gc_string)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (gc_string);
+
+ return arv_gc_register_get_length (gc_register);
+}
+
+static void
+arv_gc_register_string_interface_init (ArvGcStringInterface *interface)
+{
+ interface->get_value = arv_gc_register_get_string_value;
+ interface->set_value = arv_gc_register_set_string_value;
+ interface->get_max_length = arv_gc_register_get_max_string_length;
+}
+
G_DEFINE_TYPE_WITH_CODE (ArvGcRegister, arv_gc_register, ARV_TYPE_GC_NODE,
G_IMPLEMENT_INTERFACE (ARV_TYPE_GC_INTEGER, arv_gc_register_integer_interface_init)
- G_IMPLEMENT_INTERFACE (ARV_TYPE_GC_FLOAT, arv_gc_register_float_interface_init))
-
+ G_IMPLEMENT_INTERFACE (ARV_TYPE_GC_FLOAT, arv_gc_register_float_interface_init)
+ G_IMPLEMENT_INTERFACE (ARV_TYPE_GC_STRING, arv_gc_register_string_interface_init))
diff --git a/src/arvgcstring.c b/src/arvgcstring.c
new file mode 100644
index 0000000..8e59cbf
--- /dev/null
+++ b/src/arvgcstring.c
@@ -0,0 +1,62 @@
+/* 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 <arvgcstring.h>
+#include <arvtools.h>
+
+static void
+arv_gc_string_default_init (ArvGcStringInterface *gc_string_iface)
+{
+}
+
+G_DEFINE_INTERFACE (ArvGcString, arv_gc_string, G_TYPE_OBJECT)
+
+const char *
+arv_gc_string_get_value (ArvGcString *gc_string)
+{
+ g_return_val_if_fail (ARV_IS_GC_STRING (gc_string), 0);
+
+ return ARV_GC_STRING_GET_INTERFACE (gc_string)->get_value (gc_string);
+}
+
+void
+arv_gc_string_set_value (ArvGcString *gc_string, const char *value)
+{
+ g_return_if_fail (ARV_IS_GC_STRING (gc_string));
+
+ ARV_GC_STRING_GET_INTERFACE (gc_string)->set_value (gc_string, value);
+}
+
+gint64
+arv_gc_string_get_max_length (ArvGcString *gc_string)
+{
+ ArvGcStringInterface *string_interface;
+
+ g_return_val_if_fail (ARV_IS_GC_STRING (gc_string), 0);
+
+ string_interface = ARV_GC_STRING_GET_INTERFACE (gc_string);
+
+ if (string_interface->get_max_length != NULL)
+ return string_interface->get_max_length (gc_string);
+ else
+ return 0;
+}
diff --git a/src/arvgcstring.h b/src/arvgcstring.h
new file mode 100644
index 0000000..cc00ba5
--- /dev/null
+++ b/src/arvgcstring.h
@@ -0,0 +1,53 @@
+/* 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_STRING_H
+#define ARV_GC_STRING_H
+
+#include <arvtypes.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_GC_STRING (arv_gc_string_get_type ())
+#define ARV_GC_STRING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_GC_STRING, ArvGcString))
+#define ARV_IS_GC_STRING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_GC_STRING))
+#define ARV_GC_STRING_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), ARV_TYPE_GC_STRING, ArvGcStringInterface))
+
+typedef struct _ArvGcStringInterface ArvGcStringInterface;
+
+struct _ArvGcStringInterface {
+ GTypeInterface parent;
+
+ const char * (*get_value) (ArvGcString *gc_string);
+ void (*set_value) (ArvGcString *gc_string, const char *value);
+ gint64 (*get_max_length) (ArvGcString *gc_string);
+};
+
+GType arv_gc_string_get_type (void);
+
+const char * arv_gc_string_get_value (ArvGcString *gc_string);
+void arv_gc_string_set_value (ArvGcString *gc_string, const char *value);
+gint64 arv_gc_string_get_max_length (ArvGcString *gc_string);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvtest.c b/src/arvtest.c
index 1eee074..898ddea 100644
--- a/src/arvtest.c
+++ b/src/arvtest.c
@@ -118,6 +118,15 @@ main (int argc, char **argv)
arv_gc_integer_set_value (ARV_GC_INTEGER (node), arv_option_vertical_binning);
}
+ node = arv_gc_get_node (genicam, "DeviceVendorName");
+ v_string = arv_gc_string_get_value (ARV_GC_STRING (node));
+ g_print ("vendor = %s\n", v_string);
+ node = arv_gc_get_node (genicam, "DeviceModelName");
+ v_string = arv_gc_string_get_value (ARV_GC_STRING (node));
+ g_print ("model = %s\n", v_string);
+ node = arv_gc_get_node (genicam, "DeviceID");
+ v_string = arv_gc_string_get_value (ARV_GC_STRING (node));
+ g_print ("device id = %s\n", v_string);
node = arv_gc_get_node (genicam, "SensorWidth");
value = arv_gc_integer_get_value (ARV_GC_INTEGER (node));
g_print ("sensor width = %d\n", value);
diff --git a/src/arvtypes.h b/src/arvtypes.h
index 5373b84..f980855 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -48,6 +48,7 @@ typedef struct _ArvGcPort ArvGcPort;
typedef struct _ArvGcInteger ArvGcInteger;
typedef struct _ArvGcFloat ArvGcFloat;
+typedef struct _ArvGcString ArvGcString;
typedef struct _ArvInterface ArvInterface;
typedef struct _ArvDevice ArvDevice;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]