VisionWorks Toolkit Reference

September 29, 2015 | 1.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
2. Input Validation

This section demonstrates input validation implementation.

You must provide the validation function for input parameters.

The validation function checks 1 parameter in 1 call and has the following prototype:

vx_status keypointArraySort_input_validate(vx_node node, vx_uint32 index)

2.1 Check for the source array:

if (index == 0)
{
vx_array src = NULL;
vxQueryParameter(param0, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
vx_enum item_type = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &item_type, sizeof(item_type));
if (item_type == VX_TYPE_KEYPOINT)
{
status = VX_SUCCESS;
}
else
{
vxAddLogEntry((vx_reference)node, status,
"[keypoint_array_sort] Invalid item type for \'src\' array, it should be VX_TYPE_KEYPOINT");
}
}

2.2 Check for the Boolean scalar:

else if (index == 2)
{
vx_scalar use_strength_scalar = NULL;
vxQueryParameter(param2, VX_PARAMETER_ATTRIBUTE_REF, &use_strength_scalar, sizeof(use_strength_scalar));
vx_enum type = 0;
vxQueryScalar(use_strength_scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type));
if (type == VX_TYPE_BOOL)
{
status = VX_SUCCESS;
}
else
{
vxAddLogEntry((vx_reference)use_strength_scalar, status, "Invalid type for \'sort_cmp\' in KeypointArraySort Kernel, it should be VX_TYPE_ENUM");
}
vxReleaseScalar(&use_strength_scalar);
}

The Full Code for the Node Input Validation

vx_status keypointArraySort_input_validate(vx_node node, vx_uint32 index)
{
if (index == 0)
{
vx_array src = NULL;
vxQueryParameter(param0, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
vx_enum item_type = 0;
vxQueryArray(src, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &item_type, sizeof(item_type));
if (item_type == VX_TYPE_KEYPOINT)
{
status = VX_SUCCESS;
}
else
{
vxAddLogEntry((vx_reference)node, status,
"[keypoint_array_sort] Invalid item type for \'src\' array, it should be VX_TYPE_KEYPOINT");
}
}
else if (index == 2)
{
vx_scalar use_strength_scalar = NULL;
vxQueryParameter(param2, VX_PARAMETER_ATTRIBUTE_REF, &use_strength_scalar, sizeof(use_strength_scalar));
vx_enum type = 0;
vxQueryScalar(use_strength_scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type));
if (type == VX_TYPE_BOOL)
{
status = VX_SUCCESS;
}
else
{
vxAddLogEntry((vx_reference)use_strength_scalar, status, "Invalid type for \'sort_cmp\' in KeypointArraySort Kernel, it should be VX_TYPE_ENUM");
}
vxReleaseScalar(&use_strength_scalar);
}
return status;
}