VisionWorks Toolkit Reference

December 18, 2015 | 1.2 Release

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

This section illustrates the implementation of the input validation callback function.

An input validation callback function is needed to validate node input parameter data objects. The callback is called automatically at graph verification time for each individual input parameter of any node that instantiates the user custom kernel.

2.1 Input validation callback prototype

Input validation callbacks have the same prototype for any kernel:

vx_status keypointArraySort_input_validate(vx_node node, vx_uint32 index)

This function must return an error status in case the parameter checked by the validator function is incorrect. There is also the possibility to provide richer information by logging a message (with vxAddLogEntry) that is retrieved by the application if it has registered a log callback function.

2.2 Check 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.3 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);
}

Complete Code for the Input Validation Callback

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;
}