// transforms numerical values into their string counterpart // utilizing the Values and ValueMap qualifiers char * transformValue(char *cssf, CMPIObjectPath * op, char *propertyName) // cssf = cimSLPService Field in the struct { CMPIData qd; CMPIStatus status; char *valuestr; _SFCB_ENTER(TRACE_SLP, "transformValue"); qd = CMGetPropertyQualifier(op, propertyName, "ValueMap", &status); if (status.rc) { printf("getPropertyQualifier failed ... Status: %d\n", status.rc); _SFCB_RETURN(NULL); } if (CMIsArray(qd)) { CMPIArray *arr = qd.value.array; CMPIType eletyp = qd.type & ~CMPI_ARRAY; int j = 0; int n; n = CMGetArrayCount(arr, NULL); CMPIData ele; ele = CMGetArrayElementAt(arr, j, NULL); valuestr = value2Chars(eletyp, &ele.value); j++; while (strcmp(valuestr, cssf)) { free(valuestr); ele = CMGetArrayElementAt(arr, j, NULL); valuestr = value2Chars(eletyp, &ele.value); if (j == n) { free(valuestr); _SFCB_RETURN(cssf); // nothing found, probably "NULL" -> // return it } j++; } free(valuestr); free(cssf); if (j - 1 <= n) { qd = CMGetPropertyQualifier(op, propertyName, "Values", &status); arr = qd.value.array; eletyp = qd.type & ~CMPI_ARRAY; ele = CMGetArrayElementAt(arr, j - 1, NULL); cssf = value2Chars(eletyp, &ele.value); _SFCB_RETURN(cssf); } else { // printf("No Valuemap Entry for %s in %s. Exiting ...\n", cssf, // propertyName); _SFCB_RETURN(NULL); } } else { // printf("No qualifier found for %s. Exiting ...\n", propertyName); _SFCB_RETURN(NULL); } }
char * myGetProperty(CMPIInstance *instance, char *propertyName) { CMPIData propertyData; CMPIStatus status; if (!instance) return NULL; propertyData = instance->ft->getProperty(instance, propertyName, &status); if (!status.rc) { return value2Chars(propertyData.type, &propertyData.value); } else { return NULL; } }
int main() { CMCIClient * cc; CMPIObjectPath * objectpath; CMPIStatus status; CMPIArgs * args; char *cim_host, *cim_host_passwd, *cim_host_userid; CMPIData retval; CMPIValue arg; /* Setup a connection to the CIMOM */ cim_host = getenv("CIM_HOST"); if (cim_host == NULL) cim_host = "localhost"; cim_host_userid = getenv("CIM_HOST_USERID"); if (cim_host_userid == NULL) cim_host_userid = "root"; cim_host_passwd = getenv("CIM_HOST_PASSWD"); if (cim_host_passwd == NULL) cim_host_passwd = "password"; cc = cmciConnect(cim_host, NULL, "5988", cim_host_userid, cim_host_passwd, NULL); printf("\n----------------------------------------------------------\n"); printf("Testing invokeMethod() ...\n"); objectpath = newCMPIObjectPath("root/cimv2", "TST_MethodProperties", NULL); CMAddKey(objectpath, "CreationClassName", "TST_MethodProperties", CMPI_chars); CMAddKey(objectpath, "Id", "Instance #1", CMPI_chars); /*---------------------------------------------------------------------*/ printf("+++T1:passing IN int16_t argument\n"); args = newCMPIArgs(NULL); arg.sint16 = 65535; args->ft->addArg(args, "Property_int16", &arg, CMPI_sint16); retval = cc->ft->invokeMethod( cc, objectpath, "Method_sint16_in", args, NULL, &status); /* Print the results */ printf( "invokeMethod() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); if (args) CMRelease(args); if (status.msg) CMRelease(status.msg); if (!status.rc) { char *cv = value2Chars(retval.type,&(retval.value)); printf("result(s):\n\treturn value:%s\n", cv); if (cv != NULL) free(cv); } else goto done; /*---------------------------------------------------------------------*/ printf("+++T2:returning int16_t value\n"); retval = cc->ft->invokeMethod( cc, objectpath, "Method_sint16", NULL, NULL, &status); /* Print the results */ printf( "invokeMethod() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); if (!status.rc) { char *cv = value2Chars(retval.type,&(retval.value)); printf("result(s):\n\treturn value:%s\n", cv); if (cv != NULL) free(cv); } if (status.msg) CMRelease(status.msg); /*---------------------------------------------------------------------*/ printf("+++ T3:passing OUT int16_t value\n"); args = newCMPIArgs(NULL); retval = cc->ft->invokeMethod( cc, objectpath, "Method_sint16_out", NULL, args, &status); /* Print the results */ printf( "invokeMethod() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); if (args) { char *cv; CMPIData data = CMGetArg(args, "Arg_int16", NULL); if (!CMIsNullValue(data)) { cv = value2Chars(data.type,&(data.value)); printf("\n result(s): OUT Parm:Arg_int16 type: %d value:%s\n", data.type, cv); if (cv != NULL) free(cv); CMRelease(args); } } if (status.msg) CMRelease(status.msg); if (!status.rc) { char *cv = value2Chars(retval.type,&(retval.value)); printf("result(s):\n\treturn value:%s\n", cv); if (cv != NULL) free(cv); } else goto done; /*---------------------------------------------------------------------*/ done: if (objectpath) CMRelease(objectpath); if (cc) CMRelease(cc); return 0; }