tpm_varget

Land Desktop Development ARX CPP SDK

Up a level
tpm_varget
 
 

Gets the value of a configuration variable.

int

tpm_varget(

ade_id var_id,

char *var_name,

struct *res);

Returns RTNORM or an error code.

var_id Configuration variables ID.
var_name Variable name.
res Variable value.

Configuration variables are composed of cleanup variables, cleanup action variables and topology variables. The variables are initialized to their default values. For a list of these variables and their default values, see Configuration Variables.

Assigning And Reading Resbuf Values

The following example demonstrates reading and writing a resbuf using tpm_varget and tpm_varset:

struct resbuf rb;
ade_id var_id = ADE_NULLID;
int ret = 0;

// Correct ID
var_id = tpm_varalloc();

// Set real value
rb.restype = RTREAL;
rb.resval.rreal = 0.5;
rb.rbnext = NULL;

ret = tpm_varset(var_id, "CLEAN_TOL", &rb; );

// Get real value
// rb.restype = RTREAL
// rb.resval.rreal = 0.5
ret = tpm_varget(var_id, "CLEAN_TOL", &rb;);

// Set string value
rb.restype = RTSTR;
rb.resval.rstring = (char *)malloc((unsigned)(strlen("LAYER_1") + 1));

ret = tpm_varset(var_id, "LINK_LAYER", &rb; );

// Get string value
// rb.restype = RTSTR
// rb.resval.rstring = "LAYER_1"
ret = tpm_varget(var_id, "LINK_LAYER", &rb; );

if ( ret == RTNORM )
free (rb.resval.rstring);

Sample Code

The following sample retrieves the value for the NODE_LAYER configuration variable using tpm_varget().

The topology containing the desired information is loaded then opened using tpm_acload() and tpm_acopen() respectively. A set of configuration variables is allocated using tpm_varalloc(), then filled using tpm_infobuildvar(). The topology can now be closed and unloaded using tpm_acclose and tpm_acunload respectively. A resbuf is created which will be populated with the configuration variable value using tpm_varget(), which is called with all required parameters. The return code is validated against RTNORM and appropriate status information is displayed. The resbuf is then released as required.

char* pszTopoName = "netTopo";
int topoWriteAccess = 0;
int returnCode = tpm_acload(pszTopoName, 0);
ade_id topoId = tpm_acopen(pszTopoName, topoWriteAccess);
ade_id varId = tpm_varalloc();
returnCode = tpm_infobuildvar(topoId, varId);
tpm_acclose(topoId);
char* pszConfigVarName = "NODE_LAYER";
struct resbuf* pConfigVarsRb = acutBuildList(RTSTR, "", 0);
returnCode = tpm_varget(varId, pszConfigVarName, pConfigVarsRb);
if (RTNORM == returnCode){
    acutPrintf(
        "\nThe \"%s\" configuration variables value is: \"%s\"."
        , pszConfigVarName, pConfigVarsRb->resval.rstring);
}
else {
    acutPrintf(
        "\nThe specified configuration variable was not retrieved.");
}
acutRelRb(pConfigVarsRb);