Skip to content

Commit

Permalink
genicam: allow Boolean as a pIsLocked target
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Feb 23, 2022
1 parent 4ff017c commit 7aeecc2
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/arvgcfeaturenode.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,23 +356,23 @@ gboolean
arv_gc_feature_node_is_locked (ArvGcFeatureNode *gc_feature_node, GError **error)
{
ArvGcFeatureNodePrivate *priv = arv_gc_feature_node_get_instance_private (gc_feature_node);
gboolean value;
gboolean locked;
GError *local_error = NULL;

g_return_val_if_fail (ARV_IS_GC_FEATURE_NODE (gc_feature_node), FALSE);

if (priv->is_locked == NULL)
return FALSE;

value = arv_gc_property_node_get_int64 (priv->is_locked, &local_error) != 0;
locked = arv_gc_property_node_get_int64 (priv->is_locked, &local_error) != 0;

if (local_error != NULL) {
g_propagate_prefixed_error (error, local_error, "[%s ]",
arv_gc_feature_node_get_name (gc_feature_node));
return FALSE;
}

return value;
return locked;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/arvgcpropertynode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <arvgcfeaturenode.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcboolean.h>
#include <arvgcstring.h>
#include <arvgc.h>
#include <arvdomtext.h>
Expand Down Expand Up @@ -379,6 +380,8 @@ arv_gc_property_node_get_int64 (ArvGcPropertyNode *node, GError **error)
return arv_gc_integer_get_value (ARV_GC_INTEGER (pvalue_node), error);
} else if (ARV_IS_GC_FLOAT (pvalue_node)) {
return (gint64) arv_gc_float_get_value (ARV_GC_FLOAT (pvalue_node), error);
} else if (ARV_IS_GC_BOOLEAN (pvalue_node)) {
return arv_gc_boolean_get_value (ARV_GC_BOOLEAN (pvalue_node), error) ? 1 : 0;
}

arv_warning_genicam ("[GcPropertyNode::get_int64] Invalid node '%s'",
Expand Down
31 changes: 31 additions & 0 deletions tests/data/genicam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,37 @@
<Value>2</Value>
</Integer>

<Integer Name="LockedByInteger">
<pIsLocked>IntegerLock</pIsLocked>
<Value>0</Value>
</Integer>

<Integer Name="LockedByFloat">
<pIsLocked>FloatLock</pIsLocked>
<Value>0</Value>
</Integer>

<Integer Name="LockedByBoolean">
<pIsLocked>BooleanLock</pIsLocked>
<Value>0</Value>
</Integer>

<Integer Name="IntegerLock">
<Value>0</Value>
</Integer>

<Float Name="FloatLock">
<Value>0</Value>
</Float>

<Boolean Name="BooleanLock">
<Value>0</Value>
</Boolean>

<Integer Name="NoLock">
<Value>0</Value>
</Integer>

<Port Name="Device" NameSpace="Standard">
</Port>

Expand Down
59 changes: 59 additions & 0 deletions tests/genicam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,64 @@ category_test (void)
g_object_unref (device);
}

static void
lock_test (void)
{
ArvDevice *device;
ArvGc *genicam;
ArvGcNode *node;
ArvGcNode *lock;
GError *error = NULL;

device = arv_fake_device_new ("TEST0", &error);
g_assert (ARV_IS_FAKE_DEVICE (device));
g_assert (error == NULL);

genicam = arv_device_get_genicam (device);
g_assert (ARV_IS_GC (genicam));

node = arv_gc_get_node (genicam, "LockedByInteger");
g_assert (ARV_IS_GC_INTEGER_NODE (node));
lock = arv_gc_get_node (genicam, "IntegerLock");
g_assert (ARV_IS_GC_INTEGER (lock));

g_assert (!arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

arv_gc_integer_set_value (ARV_GC_INTEGER (lock), 10, &error);
g_assert (arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

node = arv_gc_get_node (genicam, "LockedByFloat");
g_assert (ARV_IS_GC_INTEGER_NODE (node));
lock = arv_gc_get_node (genicam, "FloatLock");
g_assert (ARV_IS_GC_FLOAT (lock));

g_assert (!arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

arv_gc_float_set_value (ARV_GC_FLOAT (lock), 10.0, &error);
g_assert (arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

node = arv_gc_get_node (genicam, "LockedByBoolean");
g_assert (ARV_IS_GC_INTEGER_NODE (node));
lock = arv_gc_get_node (genicam, "BooleanLock");
g_assert (ARV_IS_GC_BOOLEAN (lock));

g_assert (!arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

arv_gc_boolean_set_value (ARV_GC_BOOLEAN (lock), TRUE, &error);
g_assert (arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));
g_assert (error == NULL);

node = arv_gc_get_node (genicam, "NoLock");
g_assert (ARV_IS_GC_INTEGER_NODE (node));
g_assert (!arv_gc_feature_node_is_locked (ARV_GC_FEATURE_NODE (node), &error));

g_object_unref (device);
}
int
main (int argc, char *argv[])
{
Expand All @@ -1249,6 +1307,7 @@ main (int argc, char *argv[])
g_test_add_func ("/genicam/indexed", indexed_test);
g_test_add_func ("/genicam/visibility", visibility_test);
g_test_add_func ("/genicam/category", category_test);
g_test_add_func ("/genicam/lock", lock_test);

result = g_test_run();

Expand Down

0 comments on commit 7aeecc2

Please sign in to comment.