[aravis] control: small command line utility for feature read/write.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] control: small command line utility for feature read/write.
- Date: Sun, 19 Jun 2011 07:48:40 +0000 (UTC)
commit 99bd6c8bd21cc2fa7c68b2ca25feba2582d942ec
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Jun 19 09:47:58 2011 +0200
control: small command line utility for feature read/write.
docs/reference/aravis/aravis-sections.txt | 3 +
src/.gitignore | 1 +
src/Makefile.am | 8 +++-
src/arvcontrol.c | 71 +++++++++++++++++++++++++++
src/arvdevice.c | 76 +++++++++++++++++------------
src/arvdevice.h | 2 +
src/arvgcboolean.c | 14 +++++
src/arvgcenumeration.c | 15 ++++++
src/arvgcfloatnode.c | 23 ++++++++-
src/arvgcfloatnode.h | 2 +
src/arvgcintegernode.c | 24 ++++++++-
src/arvgcintegernode.h | 2 +
src/arvgcnode.c | 27 ++++++++++
src/arvgcnode.h | 5 ++
src/arvgcregister.c | 61 ++++++++++++++++++++---
src/arvgcregister.h | 2 +
src/arvgcstring.c | 2 +-
17 files changed, 292 insertions(+), 46 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index f5fe2c6..09f0eb1 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -158,6 +158,7 @@ arv_device_write_register
arv_device_get_genicam_xml
arv_device_get_genicam
arv_device_execute_command
+arv_device_get_feature
arv_device_set_string_feature_value
arv_device_get_string_feature_value
arv_device_set_integer_feature_value
@@ -334,6 +335,8 @@ ArvFakeDevicePrivate
ArvGcNode
arv_gc_node_new
arv_gc_node_get_value_type
+arv_gc_node_get_value_as_string
+arv_gc_node_set_value_from_string
arv_gc_node_set_genicam
arv_gc_node_get_genicam
arv_gc_node_get_name
diff --git a/src/.gitignore b/src/.gitignore
index 6a677fd..b6bd6df 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,5 +1,6 @@
arv-fake-gv-camera-*.*
arv-show-devices-*.*
+arv-control-*.*
arvenumtypes.c
arvenumtypes.h
arvconfig.h
diff --git a/src/Makefile.am b/src/Makefile.am
index de13b81..9c66e74 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -126,7 +126,10 @@ arvenumtypes.h: arvenumtypes.h.template $(ARAVIS_HDRS) $(ARAVIS_HDRS_NO_INTRO) $
arvenumtypes.c: arvenumtypes.c.template $(ARAVIS_HDRS) $(ARAVIS_HDRS_NO_INTRO) $(GLIB_MKENUMS)
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template arvenumtypes.c.template $(libaravis_ ARAVIS_API_VERSION@_la_HEADERS)) > $@
-bin_PROGRAMS = arv-fake-gv-camera- ARAVIS_API_VERSION@ arv-show-devices- ARAVIS_API_VERSION@
+bin_PROGRAMS = \
+ arv-fake-gv-camera- ARAVIS_API_VERSION@ \
+ arv-show-devices- ARAVIS_API_VERSION@ \
+ arv-control- ARAVIS_API_VERSION@
arv_fake_gv_camera_ ARAVIS_API_VERSION@_SOURCES = arvfakegvcamera.c
arv_fake_gv_camera_ ARAVIS_API_VERSION@_LDADD = $(ARAVIS_LIBS) libaravis- ARAVIS_API_VERSION@.la
@@ -134,6 +137,9 @@ arv_fake_gv_camera_ ARAVIS_API_VERSION@_LDADD = $(ARAVIS_LIBS) libaravis- ARAVIS
arv_show_devices_ ARAVIS_API_VERSION@_SOURCES = arvshowdevices.c
arv_show_devices_ ARAVIS_API_VERSION@_LDADD = $(ARAVIS_LIBS) libaravis- ARAVIS_API_VERSION@.la
+arv_control_ ARAVIS_API_VERSION@_SOURCES = arvcontrol.c
+arv_control_ ARAVIS_API_VERSION@_LDADD = $(ARAVIS_LIBS) libaravis- ARAVIS_API_VERSION@.la
+
CLEANFILES = $(BUILT_SOURCES)
if HAVE_INTROSPECTION
diff --git a/src/arvcontrol.c b/src/arvcontrol.c
new file mode 100644
index 0000000..3563ef7
--- /dev/null
+++ b/src/arvcontrol.c
@@ -0,0 +1,71 @@
+#include <arv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static char *arv_option_device_name = NULL;
+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},
+ { "debug", 'd', 0, G_OPTION_ARG_STRING,
+ &arv_option_debug_domains, "Debug domains", NULL },
+ { NULL }
+};
+
+int
+main (int argc, char **argv)
+{
+ ArvDevice *device;
+ GOptionContext *context;
+ GError *error = NULL;
+ int i;
+
+ g_thread_init (NULL);
+ g_type_init ();
+
+ context = g_option_context_new (NULL);
+ g_option_context_add_main_entries (context, arv_option_entries, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ g_option_context_free (context);
+ g_print ("Option parsing failed: %s\n", error->message);
+ g_error_free (error);
+ return EXIT_FAILURE;
+ }
+
+ g_option_context_free (context);
+
+ arv_debug_enable (arv_option_debug_domains);
+
+ device = arv_open_device (arv_option_device_name);
+ if (!ARV_IS_DEVICE (device)) {
+ printf ("Device '%s' not found\n", arv_option_device_name);
+ return EXIT_FAILURE;
+ }
+
+ if (argc < 2) {
+ } else
+ for (i = 1; i < argc; i++) {
+ ArvGcNode *feature;
+ char **tokens;
+
+ tokens = g_strsplit (argv[i], "=", 2);
+ feature = arv_device_get_feature (device, tokens[0]);
+ if (!ARV_IS_GC_NODE (feature))
+ printf ("Feature '%s' not found\n", tokens[0]);
+ else {
+ if (tokens[1] != NULL)
+ arv_gc_node_set_value_from_string (feature, tokens[1]);
+
+ printf ("%s = %s\n", tokens[0], arv_gc_node_get_value_as_string (feature));
+ }
+ g_strfreev (tokens);
+ }
+
+ /* For debug purpose only */
+ arv_shutdown ();
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/arvdevice.c b/src/arvdevice.c
index e3db484..5929356 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -153,16 +153,32 @@ arv_device_execute_command (ArvDevice *device, const char *feature)
arv_gc_command_execute (ARV_GC_COMMAND (node));
}
+/**
+ * arv_device_get_feature:
+ * @device: a #ArvDevice
+ * @feature: a feature name
+ *
+ * Return value: (transfer none): the genicam node corresponding to the feature name, NULL if not found.
+ */
+
+ArvGcNode *
+arv_device_get_feature (ArvDevice *device, const char *feature)
+{
+ ArvGc *genicam;
+
+ genicam = arv_device_get_genicam (device);
+ g_return_val_if_fail (ARV_IS_GC (genicam), NULL);
+
+ return arv_gc_get_node (genicam, feature);
+}
+
void
arv_device_set_string_feature_value (ArvDevice *device, const char *feature, const char *value)
{
- ArvGc *genicam;
ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- g_return_if_fail (ARV_IS_GC (genicam));
+ node = arv_device_get_feature (device, feature);
- node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_ENUMERATION (node))
arv_gc_enumeration_set_string_value (ARV_GC_ENUMERATION (node), value);
else if (ARV_IS_GC_STRING (node))
@@ -172,13 +188,10 @@ arv_device_set_string_feature_value (ArvDevice *device, const char *feature, con
const char *
arv_device_get_string_feature_value (ArvDevice *device, const char *feature)
{
- ArvGc *genicam;
ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- g_return_val_if_fail (ARV_IS_GC (genicam), NULL);
+ node = arv_device_get_feature (device, feature);
- node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_ENUMERATION (node))
return arv_gc_enumeration_get_string_value (ARV_GC_ENUMERATION (node));
else if (ARV_IS_GC_STRING (node))
@@ -190,13 +203,10 @@ arv_device_get_string_feature_value (ArvDevice *device, const char *feature)
void
arv_device_set_integer_feature_value (ArvDevice *device, const char *feature, gint64 value)
{
- ArvGc *genicam;
ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- g_return_if_fail (ARV_IS_GC (genicam));
+ node = arv_device_get_feature (device, feature);
- node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_INTEGER (node))
arv_gc_integer_set_value (ARV_GC_INTEGER (node), value);
else if (ARV_IS_GC_ENUMERATION (node))
@@ -208,13 +218,10 @@ arv_device_set_integer_feature_value (ArvDevice *device, const char *feature, gi
gint64
arv_device_get_integer_feature_value (ArvDevice *device, const char *feature)
{
- ArvGc *genicam;
ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- g_return_val_if_fail (ARV_IS_GC (genicam), 0);
+ node = arv_device_get_feature (device, feature);
- node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_INTEGER (node))
return arv_gc_integer_get_value (ARV_GC_INTEGER (node));
else if (ARV_IS_GC_ENUMERATION (node))
@@ -228,13 +235,10 @@ arv_device_get_integer_feature_value (ArvDevice *device, const char *feature)
void
arv_device_get_integer_feature_bounds (ArvDevice *device, const char *feature, gint64 *min, gint64 *max)
{
- ArvGc *genicam;
ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- g_return_if_fail (ARV_IS_GC (genicam));
+ node = arv_device_get_feature (device, feature);
- node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_INTEGER (node)) {
if (min != NULL)
*min = arv_gc_integer_get_min (ARV_GC_INTEGER (node));
@@ -247,32 +251,40 @@ arv_device_get_integer_feature_bounds (ArvDevice *device, const char *feature, g
void
arv_device_set_float_feature_value (ArvDevice *device, const char *feature, double value)
{
- ArvGc *genicam;
+ ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- arv_gc_float_set_value (ARV_GC_FLOAT (arv_gc_get_node (genicam, feature)), value);
+ node = arv_device_get_feature (device, feature);
+
+ if (ARV_IS_GC_FLOAT (node))
+ arv_gc_float_set_value (ARV_GC_FLOAT (node), value);
}
double
arv_device_get_float_feature_value (ArvDevice *device, const char *feature)
{
- ArvGc *genicam;
+ ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
- return arv_gc_float_get_value (ARV_GC_FLOAT (arv_gc_get_node (genicam, feature)));
+ node = arv_device_get_feature (device, feature);
+
+ if (ARV_IS_GC_FLOAT (node))
+ return arv_gc_float_get_value (ARV_GC_FLOAT (node));
+
+ return 0.0;
}
void
arv_device_get_float_feature_bounds (ArvDevice *device, const char *feature, double *min, double *max)
{
- ArvGc *genicam;
+ ArvGcNode *node;
- genicam = arv_device_get_genicam (device);
+ node = arv_device_get_feature (device, feature);
- if (min != NULL)
- *min = arv_gc_float_get_min (ARV_GC_FLOAT (arv_gc_get_node (genicam, feature)));
- if (max != NULL)
- *max = arv_gc_float_get_max (ARV_GC_FLOAT (arv_gc_get_node (genicam, feature)));
+ if (ARV_IS_GC_FLOAT (node)) {
+ if (min != NULL)
+ *min = arv_gc_float_get_min (ARV_GC_FLOAT (node));
+ if (max != NULL)
+ *max = arv_gc_float_get_max (ARV_GC_FLOAT (node));
+ }
}
static void
diff --git a/src/arvdevice.h b/src/arvdevice.h
index 228d6fb..b92b456 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -70,6 +70,8 @@ ArvGc * arv_device_get_genicam (ArvDevice *device);
void arv_device_execute_command (ArvDevice *device, const char *feature);
+ArvGcNode * arv_device_get_feature (ArvDevice *device, const char *feature);
+
void arv_device_set_string_feature_value (ArvDevice *device, const char *feature, const char *value);
const char * arv_device_get_string_feature_value (ArvDevice *device, const char *feature);
diff --git a/src/arvgcboolean.c b/src/arvgcboolean.c
index 20d48ac..6ebd287 100644
--- a/src/arvgcboolean.c
+++ b/src/arvgcboolean.c
@@ -52,6 +52,18 @@ arv_gc_boolean_add_element (ArvGcNode *node, const char *name, const char *conte
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
}
+static void
+arv_gc_boolean_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ arv_gc_boolean_set_value (ARV_GC_BOOLEAN (node), g_strcmp0 (string, "true") == 0);
+}
+
+static const char *
+arv_gc_boolean_get_value_as_string (ArvGcNode *node)
+{
+ return arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node)) ? "true" : "false";
+}
+
/* ArvGcBoolean implementation */
gboolean
@@ -113,6 +125,8 @@ arv_gc_boolean_class_init (ArvGcBooleanClass *boolean_class)
object_class->finalize = arv_gc_boolean_finalize;
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;
}
/* ArvGcInteger interface implementation */
diff --git a/src/arvgcenumeration.c b/src/arvgcenumeration.c
index 66985a6..16b7617 100644
--- a/src/arvgcenumeration.c
+++ b/src/arvgcenumeration.c
@@ -59,6 +59,19 @@ arv_gc_enumeration_add_element (ArvGcNode *node, const char *name, const char *c
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
}
+static void
+arv_gc_enumeration_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ arv_gc_enumeration_set_string_value (ARV_GC_ENUMERATION (node), string);
+}
+
+static const char *
+arv_gc_enumeration_get_value_as_string (ArvGcNode *node)
+{
+ return arv_gc_enumeration_get_string_value (ARV_GC_ENUMERATION (node));
+}
+
+
/* ArvGcEnumeration implementation */
const char *
@@ -207,6 +220,8 @@ arv_gc_enumeration_class_init (ArvGcEnumerationClass *enumeration_class)
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;
+ node_class->get_value_as_string = arv_gc_enumeration_get_value_as_string;
}
G_DEFINE_TYPE (ArvGcEnumeration, arv_gc_enumeration, ARV_TYPE_GC_NODE)
diff --git a/src/arvgcfloatnode.c b/src/arvgcfloatnode.c
index 9b5814f..3bcb7fc 100644
--- a/src/arvgcfloatnode.c
+++ b/src/arvgcfloatnode.c
@@ -69,14 +69,31 @@ arv_gc_float_node_add_element (ArvGcNode *node, const char *name, const char *co
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
}
-/* ArvGcFloatNode implementation */
-
static GType
arv_gc_float_node_get_value_type (ArvGcNode *node)
{
return G_TYPE_DOUBLE;
}
+
+static void
+arv_gc_float_node_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ arv_gc_float_set_value (ARV_GC_FLOAT (node), g_ascii_strtod (string, NULL));
+}
+
+static const char *
+arv_gc_float_node_get_value_as_string (ArvGcNode *node)
+{
+ ArvGcFloatNode *float_node = ARV_GC_FLOAT_NODE (node);
+
+ g_ascii_dtostr (float_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, arv_gc_float_get_value (ARV_GC_FLOAT (node)));
+
+ return float_node->v_string;
+}
+
+/* ArvGcFloatNode implementation */
+
ArvGcNode *
arv_gc_float_node_new (void)
{
@@ -130,6 +147,8 @@ arv_gc_float_node_class_init (ArvGcFloatNodeClass *float_node_class)
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;
+ node_class->get_value_as_string = arv_gc_float_node_get_value_as_string;
}
/* ArvGcFloat interface implementation */
diff --git a/src/arvgcfloatnode.h b/src/arvgcfloatnode.h
index b1cf48d..07b56e3 100644
--- a/src/arvgcfloatnode.h
+++ b/src/arvgcfloatnode.h
@@ -45,6 +45,8 @@ struct _ArvGcFloatNode {
GValue maximum;
GValue increment;
char *unit;
+
+ char v_string[G_ASCII_DTOSTR_BUF_SIZE];
};
struct _ArvGcFloatNodeClass {
diff --git a/src/arvgcintegernode.c b/src/arvgcintegernode.c
index de31518..6765296 100644
--- a/src/arvgcintegernode.c
+++ b/src/arvgcintegernode.c
@@ -30,6 +30,7 @@
#include <arvgc.h>
#include <arvtools.h>
#include <string.h>
+#include <stdlib.h>
static GObjectClass *parent_class = NULL;
@@ -67,14 +68,31 @@ arv_gc_integer_node_add_element (ArvGcNode *node, const char *name, const char *
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
}
-/* ArvGcIntegerNode implementation */
-
static GType
arv_gc_integer_node_get_value_type (ArvGcNode *node)
{
return G_TYPE_INT64;
}
+static void
+arv_gc_integer_node_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ arv_gc_integer_set_value (ARV_GC_INTEGER (node), g_ascii_strtoll (string, NULL, 0));
+}
+
+static const char *
+arv_gc_integer_node_get_value_as_string (ArvGcNode *node)
+{
+ ArvGcIntegerNode *integer_node = ARV_GC_INTEGER_NODE (node);
+
+ g_snprintf (integer_node->v_string, G_ASCII_DTOSTR_BUF_SIZE,
+ "%" G_GINT64_FORMAT, arv_gc_integer_get_value (ARV_GC_INTEGER (node)));
+
+ return integer_node->v_string;
+}
+
+/* ArvGcIntegerNode implementation */
+
ArvGcNode *
arv_gc_integer_node_new (void)
{
@@ -128,6 +146,8 @@ arv_gc_integer_node_class_init (ArvGcIntegerNodeClass *integer_node_class)
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;
+ node_class->get_value_as_string = arv_gc_integer_node_get_value_as_string;
}
/* ArvGcInteger interface implementation */
diff --git a/src/arvgcintegernode.h b/src/arvgcintegernode.h
index 7cb1b3c..db098a3 100644
--- a/src/arvgcintegernode.h
+++ b/src/arvgcintegernode.h
@@ -45,6 +45,8 @@ struct _ArvGcIntegerNode {
GValue maximum;
GValue increment;
char *unit;
+
+ char v_string[G_ASCII_DTOSTR_BUF_SIZE];
};
struct _ArvGcIntegerNodeClass {
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index a39aa3e..9df4497 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -239,6 +239,33 @@ arv_gc_node_get_value_type (ArvGcNode *node)
}
void
+arv_gc_node_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ ArvGcNodeClass *node_class;
+
+ g_return_if_fail (ARV_IS_GC_NODE (node));
+ g_return_if_fail (string != NULL);
+
+ node_class = ARV_GC_NODE_GET_CLASS (node);
+ if (node_class->set_value_from_string != NULL)
+ node_class->set_value_from_string (node, string);
+}
+
+const char *
+arv_gc_node_get_value_as_string (ArvGcNode *node)
+{
+ ArvGcNodeClass *node_class;
+
+ g_return_val_if_fail (ARV_IS_GC_NODE (node), NULL);
+
+ node_class = ARV_GC_NODE_GET_CLASS (node);
+ if (node_class->get_value_as_string != NULL)
+ return node_class->get_value_as_string (node);
+
+ return NULL;
+}
+
+void
arv_gc_node_inc_modification_count (ArvGcNode *gc_node)
{
g_return_if_fail (ARV_IS_GC_NODE (gc_node));
diff --git a/src/arvgcnode.h b/src/arvgcnode.h
index edb035e..16cb586 100644
--- a/src/arvgcnode.h
+++ b/src/arvgcnode.h
@@ -51,12 +51,17 @@ struct _ArvGcNodeClass {
const char **attributes);
GType (*get_value_type) (ArvGcNode *gc_node);
gboolean (*can_add_child) (ArvGcNode *gc_node, ArvGcNode *child);
+
+ void (*set_value_from_string) (ArvGcNode *gc_node, const char *string);
+ const char * (*get_value_as_string) (ArvGcNode *gc_node);
};
GType arv_gc_node_get_type (void);
ArvGcNode * arv_gc_node_new (void);
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);
void arv_gc_node_set_genicam (ArvGcNode *gc_node, ArvGc *genicam);
ArvGc * arv_gc_node_get_genicam (ArvGcNode *gc_node);
const char * arv_gc_node_get_name (ArvGcNode *gc_node);
diff --git a/src/arvgcregister.c b/src/arvgcregister.c
index 7881cef..e1a6858 100644
--- a/src/arvgcregister.c
+++ b/src/arvgcregister.c
@@ -123,6 +123,57 @@ arv_gc_register_add_element (ArvGcNode *node, const char *name, const char *cont
ARV_GC_NODE_CLASS (parent_class)->add_element (node, name, content, attributes);
}
+static GType
+arv_gc_register_get_value_type (ArvGcNode *node)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (node);
+
+ return gc_register->value_type;
+}
+
+static void
+arv_gc_register_set_value_from_string (ArvGcNode *node, const char *string)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (node);
+
+ switch (gc_register->value_type) {
+ case G_TYPE_INT64:
+ arv_gc_integer_set_value (ARV_GC_INTEGER (node), g_ascii_strtoll (string, NULL, 0));
+ break;
+ case G_TYPE_DOUBLE:
+ arv_gc_float_set_value (ARV_GC_FLOAT (node), g_ascii_strtod (string, NULL));
+ break;
+ case G_TYPE_STRING:
+ arv_gc_string_set_value (ARV_GC_STRING (node), string);
+ break;
+ default:
+ break;
+ }
+}
+
+static const char *
+arv_gc_register_get_value_as_string (ArvGcNode *node)
+{
+ ArvGcRegister *gc_register = ARV_GC_REGISTER (node);
+
+ switch (gc_register->value_type) {
+ case G_TYPE_INT64:
+ g_snprintf (gc_register->v_string, G_ASCII_DTOSTR_BUF_SIZE,
+ "%" G_GINT64_FORMAT, arv_gc_integer_get_value (ARV_GC_INTEGER (node)));
+ return gc_register->v_string;
+ case G_TYPE_DOUBLE:
+ g_ascii_dtostr (gc_register->v_string, G_ASCII_DTOSTR_BUF_SIZE,
+ arv_gc_float_get_value (ARV_GC_FLOAT (node)));
+ return gc_register->v_string;
+ case G_TYPE_STRING:
+ return arv_gc_string_get_value (ARV_GC_STRING (node));
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
/* ArvGcRegister implementation */
gboolean
@@ -304,14 +355,6 @@ arv_gc_register_get_length (ArvGcRegister *gc_register)
return arv_gc_get_int64_from_value (genicam, &gc_register->length);
}
-static GType
-arv_gc_register_get_value_type (ArvGcNode *node)
-{
- ArvGcRegister *gc_register = ARV_GC_REGISTER (node);
-
- return gc_register->value_type;
-}
-
ArvGcNode *
arv_gc_register_new (void)
{
@@ -428,6 +471,8 @@ arv_gc_register_class_init (ArvGcRegisterClass *register_class)
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;
+ node_class->get_value_as_string = arv_gc_register_get_value_as_string;
}
/* ArvGcInteger interface implementation */
diff --git a/src/arvgcregister.h b/src/arvgcregister.h
index 6383822..5a61b5c 100644
--- a/src/arvgcregister.h
+++ b/src/arvgcregister.h
@@ -88,6 +88,8 @@ struct _ArvGcRegister {
size_t cache_size;
gboolean is_cache_valid;
+ char v_string[G_ASCII_DTOSTR_BUF_SIZE];
+
GSList *invalidators;
};
diff --git a/src/arvgcstring.c b/src/arvgcstring.c
index baf39d4..660d10f 100644
--- a/src/arvgcstring.c
+++ b/src/arvgcstring.c
@@ -38,7 +38,7 @@ 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);
+ g_return_val_if_fail (ARV_IS_GC_STRING (gc_string), NULL);
return ARV_GC_STRING_GET_INTERFACE (gc_string)->get_value (gc_string);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]