ncGraphGetOption()

Info Value
Header mvnc.h
Library libmvnc.so
Version 2.0
See also struct ncGraphHandle_t, ncGraphOption_t, ncGraphSetOption()

Overview

This function gets the value of an option for a graph. The available options and possible values can be found in the ncGraphOption_t enumeration.

Prototype

ncStatus_t ncGraphGetOption(struct ncGraphHandle_t* graphHandle,
                            int option, void* data,
                            unsigned int* dataLength);

Parameters

Name Type Description
graphHandle struct ncGraphHandle_t* A pointer to an ncGraphHandle_t struct for the graph for which the option value will be retrieved. The graph state must be NC_GRAPH_CREATED or NC_GRAPH_ALLOCATED.
option int A value from the ncGraphOption_t enumeration that specifies which option’s value will be retrieved.
data void* A pointer to a buffer where the value of the option will be copied. The size and type of data this points to will depend on the option that is specified. See ncGraphOption_t for option data types.
dataLength unsigned int* A pointer to an unsigned int which contains the size, in bytes, of the buffer allocated by the caller for the data parameter.

Upon normal return (status code NC_OK), dataLength will be set to the number of bytes copied to the data buffer. In the event that the data buffer was an insufficient size to hold the option value, the return status code will be NC_INVALID_DATA_LENGTH and dataLength will be set to the size required to hold the option value.

Return

An appropriate value from the ncStatus_t enumeration.

If the data buffer was an insufficient size to hold the option value, the return status code will be NC_INVALID_DATA_LENGTH and dataLength will be set to the size required to hold the option value.

Notes

  • If you don’t know what value to use for dataLength, you can call this function once with a dataLength of 0 to have dataLength be set to the correct value and then allocate a correctly sized buffer and call this function again. See the example below.

Example

Get an option value when you know the correct data length:

#include <stdio.h>
#include <mvnc.h>

int main(int argc, char** argv)
{
    ncStatus_t retCode;
    struct ncDeviceHandle_t* deviceHandlePtr;
    struct ncGraphHandle_t* graphHandlePtr;
    
    ncDeviceCreate(0, &deviceHandlePtr);
    ncDeviceOpen(deviceHandlePtr);
    ncGraphCreate("My Graph", &graphHandlePtr);

    unsigned int optionSize = NC_MAX_NAME_SIZE;
    char graphName[NC_MAX_NAME_SIZE];
    retCode = ncGraphGetOption(graphHandlePtr, NC_RO_GRAPH_NAME, graphName, &optionSize);
    if (retCode != NC_OK)
    {
        printf("Error getting graph option[%d].\n", retCode);
    }
    else
    {
        printf("Graph option NC_RO_GRAPH_NAME is: '%s'\n", graphName);
    }

    // clean up the graph and device
    ncGraphDestroy(&graphHandlePtr);
    ncDeviceClose(deviceHandlePtr);
    ncDeviceDestroy(&deviceHandlePtr);
}

Get an option value when you don’t know the correct data length:

#include <mvnc.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    ncStatus_t retCode;
    struct ncGraphHandle_t* graphHandle;
    char* graphName; 
    unsigned int dataLength;
    
    /* Initialize a graph handle */
    retCode = ncGraphCreate("graph1", &graphHandle);
    
    /* retCode should be NC_OK unless there was a problem */
    if(retCode != NC_OK)
    {
        printf("Error: %d\n", retCode);
        exit(-1);
    }
    
    /* Call ncGraphGetOption once to get the correct dataLength */
    graphName = NULL;
    dataLength = 0;
    retCode = ncGraphGetOption(graphHandle, NC_RO_GRAPH_NAME, graphName, &dataLength);

    /* retCode should be NC_INVALID_DATA_LENGTH unless there was another problem */
    if(retCode != NC_INVALID_DATA_LENGTH)
    {
        printf("Error: %d\n", retCode);
        exit(-1);
    }
    
    /* Now the value of dataLength is correctly set */
    /* Allocate the array buffer */
    graphName = (char*)malloc(dataLength);
    
    /* Get the graph name option value */
    retCode = ncGraphGetOption(graphHandle, NC_RO_GRAPH_NAME, graphName, &dataLength);
    
    /* Use the graph name as needed */
    printf("The graph name is %s.\n", graphName);
    
    return 0;
}