static VALUE OpenVX_targets_list(VALUE self) { vx_uint32 t,value = 0; vx_status status = VX_FAILURE; vx_char targetname[VX_MAX_TARGET_NAME]; vx_target target = 0; VALUE array; status = vxQueryContext(context, VX_QUERY_CONTEXT_NUMTARGETS, &value, sizeof(value)); REXT_PRINT("status = %d, targets = %d\n", status, value); if (status == VX_SUCCESS) { array = rb_ary_new2(value); for (t = 0; t < value; t++) { target = vxGetTargetByIndex(context, t); if (target) { status = vxQueryTarget(target, VX_QUERY_TARGET_NAME, targetname, sizeof(targetname)); if (status == VX_SUCCESS) rb_ary_push(array, rb_str_new2(targetname)); } } } return array; }
//************************************************************************** // EXPORTED FUNCTIONS //************************************************************************** static void GetByIndex(JNIEnv *env, jobject obj, jlong c, jint i) { vx_context context = (vx_context)c; vx_target t = vxGetTargetByIndex(context, i); SetHandle(env, obj, TargetClass, parentName, c); SetHandle(env, obj, TargetClass, handleName, (jlong)t); }
vx_target vxFindTarget(vx_context context, vx_char name[VX_MAX_TARGET_NAME]) { vx_uint32 t, targets; vx_target target = 0; vx_char targetName[VX_MAX_TARGET_NAME]; vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_NUMTARGETS, &targets, sizeof(targets)); for (t = 0u; t < targets; t++) { target = vxGetTargetByIndex(context,t); vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, &targetName, VX_MAX_TARGET_NAME); if (strncmp(targetName, name, VX_MAX_TARGET_NAME) == 0) { break; } vxReleaseTarget(&target); target = 0; } return target; }
vx_bool vxFindAllTargetsOfKernelsByName(vx_context context, vx_char kname[VX_MAX_KERNEL_NAME], vx_char *targets[VX_MAX_TARGET_NAME]) { vx_bool ret = vx_false_e; vx_uint32 k = 0u, t = 0u, num_targets = 0u; vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_TARGETS, &num_targets, sizeof(num_targets)); for (t = 0u; t < num_targets; t++) { vx_target target = vxGetTargetByIndex(context, t); vx_uint32 num_kernels = 0; /* clear out the name */ memset(targets[t], 0, VX_MAX_TARGET_NAME); if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NUMKERNELS, &num_kernels, sizeof(num_kernels)) == VX_SUCCESS) { vx_size size = num_kernels * sizeof(vx_kernel_info_t); vx_kernel_info_t *kernels = malloc(size); if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_KERNELTABLE, kernels, size) == VX_SUCCESS) { for (k = 0u; k < num_kernels; k++) { /* target kernel names are allowed to have variant strings */ vx_char string[VX_MAX_KERNEL_NAME], *ker; strncpy(string, kernels[k].name, VX_MAX_KERNEL_NAME); ker = strtok(string, ":"); /* if it has any variants of this kernel it is ok */ if (strncmp(kname, ker, VX_MAX_KERNEL_NAME) == 0) { /* fill in the name if it has this kernel */ if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, targets[t], VX_MAX_TARGET_NAME) == VX_SUCCESS) { ret = vx_true_e; } break; } } } free(kernels); } } return ret; }
vx_bool vxCreateListOfAllTargets(vx_context context, vx_char **targets[], vx_uint32 *num_targets) { vx_bool ret = vx_false_e; vx_uint32 t = 0u; if (vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_TARGETS, num_targets, sizeof(*num_targets)) == VX_SUCCESS) { *targets = (vx_char **)calloc(*num_targets, sizeof(vx_char *)); if (*targets) { for (t = 0u; t < *num_targets; t++) { vx_target target = vxGetTargetByIndex(context, t); (*targets)[t] = (vx_char *)calloc(VX_MAX_TARGET_NAME, sizeof(vx_char)); if ((*targets)[t]) { if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, (*targets)[t], VX_MAX_TARGET_NAME) == VX_SUCCESS) { ret = vx_true_e; } else { ret = vx_false_e; break; } } } if (ret == vx_false_e) { do { if (t > 0) free((*targets)[--t]); } while (t != 0); } } } return ret; }
static VALUE Target_init(VALUE self, VALUE index) { vx_target target = vxGetTargetByIndex(context, FIX2UINT(index)); DATA_PTR(self) = (void *)target; return Qnil; }