From: Gareth S B. <bes...@us...> - 2005-06-19 19:23:05
|
Update of /cvsroot/sblim/sfcc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15662 Modified Files: test.c Log Message: changes to test.c Index: test.c =================================================================== RCS file: /cvsroot/sblim/sfcc/test.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- test.c 13 Jun 2005 23:50:46 -0000 1.4 +++ test.c 19 Jun 2005 19:22:56 -0000 1.5 @@ -1,52 +1,187 @@ - #include "cmci.h" -int main(int argc, char *argv[]) +static char * _HOSTNAME = "bestorga.ibm.com"; + +extern char *value2Chars(CMPIType type, CMPIValue * value); + +static void showObjectPath( CMPIObjectPath * objectpath ) +{ + CMPIString * namespace = objectpath->ft->getNameSpace(objectpath, NULL); + CMPIString * classname = objectpath->ft->getClassName(objectpath, NULL); + int numkeys = objectpath->ft->getKeyCount(objectpath, NULL); + int i; + + if (namespace && namespace->hdl) printf("namespace=%s\n", (char *)namespace->hdl); + if (classname && classname->hdl) printf("classname=%s\n", (char *)classname->hdl); + if (numkeys) { + printf("keys:\n"); + for (i=0; i<numkeys; i++) { + CMPIString * keyname; + CMPIData data = objectpath->ft->getKeyAt(objectpath, i, &keyname, NULL); + printf("\t%s=%s\n", (char *)keyname->hdl, value2Chars(data.type, &data.value)); + } + } + + if (classname) CMRelease(classname); + if (namespace) CMRelease(namespace); +} + + +static void showInstance( CMPIInstance *instance ) +{ + CMPIObjectPath * objectpath = instance->ft->getObjectPath(instance, NULL); + CMPIString * objectpathname = objectpath->ft->toString(objectpath, NULL); + CMPIString * namespace = objectpath->ft->getNameSpace(objectpath, NULL); + CMPIString * classname = objectpath->ft->getClassName(objectpath, NULL); + int numproperties = instance->ft->getPropertyCount(instance, NULL); + int i; + + if (objectpathname && objectpathname->hdl) printf("objectpath=%s\n", (char *)objectpathname->hdl); + if (namespace && namespace->hdl) printf("namespace=%s\n", (char *)namespace->hdl); + if (classname && classname->hdl) printf("classname=%s\n", (char *)classname->hdl); + if (numproperties) { + printf("properties:\n"); + for (i=0; i<numproperties; i++) { + CMPIString * propertyname; + CMPIData data = instance->ft->getPropertyAt(instance, i, &propertyname, NULL); + printf("\t%s=%s\n", (char *)propertyname->hdl, value2Chars(data.type, &data.value)); + } + } + + if (classname) CMRelease(classname); + if (namespace) CMRelease(namespace); + if (objectpathname) CMRelease(objectpathname); + if (objectpath) CMRelease(objectpath); +} + + +static void showClass( CMPIConstClass * class ) +{ + CMPIString * classname = class->ft->getClassName(class, NULL); + int numproperties = class->ft->getPropertyCount(class, NULL); + int i; + + if (classname && classname->hdl) printf("classname=%s\n", (char *)classname->hdl); + if (numproperties) { + printf("properties:\n"); + for (i=0; i<numproperties; i++) { + CMPIString * propertyname; + CMPIData data = class->ft->getPropertyAt(class, i, &propertyname, NULL); + printf("\t%s=%s\n", (char *)propertyname->hdl, value2Chars(data.type, &data.value)); + } + } + + if (classname) CMRelease(classname); +} + + +int main( int argc, char * argv[] ) { CMCIClient *cc; - CMPIObjectPath *cop; - CMPIInstance *ci; - CMPIEnumeration *enm; - CMPIStatus rc; - CMPIConstClass *cls; - CMPIData data; - - cc=cmciConnect("localhost",NULL,NULL,NULL,NULL); - cop=newCMPIObjectPath("root/cimv2",NULL,NULL); - - enm=cc->ft->enumClassNames(cc,cop,0,&rc); - printf("--- enumClassNames rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); - while (enm->ft->hasNext(enm,NULL)) { - CMPIData d=enm->ft->getNext(enm,NULL); - CMPIString *cn=d.value.ref->ft->getClassName(d.value.ref,NULL); - printf(" -- className: %s\n",(char*)cn->hdl); - CMRelease(cn); + CMPIObjectPath * objectpath; + CMPIInstance * instance; + CMPIEnumeration * enumeration; + CMPIConstClass * class; + CMPIStatus status; + + /* Setup a conncetion to the CIMOM */ + cc = cmciConnect("localhost",NULL,NULL,NULL,NULL); + + if (1) { + /* Test enumClassNames() */ + printf("\n----------------------------------------------------------\n"); + printf("Testing enumClassNames() ...\n"); + objectpath = newCMPIObjectPath("root/cimv2", NULL, NULL); + enumeration = cc->ft->enumClassNames(cc, objectpath, 0, &status); + + /* Print the results */ + printf("enumClassNames() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); + if (!status.rc) { + printf("result(s):\n"); + while (enumeration->ft->hasNext(enumeration, NULL)) { + CMPIData data = enumeration->ft->getNext(enumeration, NULL); + showObjectPath(data.value.ref); + } + } + if (enumeration) CMRelease(enumeration); + if (objectpath) CMRelease(objectpath); } - CMRelease(enm); - CMRelease(cop); - - cop=newCMPIObjectPath("root/cimv2","Linux_ComputerSystem",NULL); - cls=cc->ft->getClass(cc,cop,0,NULL,&rc); - printf("--- getClass rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); - data=cls->ft->getProperty(cls,"InstallDate",&rc); - printf("--- getProperty rc: %d - %s %x\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL,data.state); - data=cls->ft->getProperty(cls,"EnabledDefault",&rc); - printf("--- getProperty rc: %d - %s %x %d\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL,data.state,data.value.uint16); - - CMAddKey(cop,"CreationClassName","Linux_ComputerSystem",CMPI_chars); - - enm=cc->ft->enumInstanceNames(cc,cop,&rc); - printf("--- enumInstanceNames rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); - - if (argc==1) CMAddKey(cop,"Name","localhost.localdomain",CMPI_chars); - else CMAddKey(cop,"Name","dyn-9-152-143-58.boeblingen.de.ibm.com",CMPI_chars); - - ci=cc->ft->getInstance(cc,cop,0,NULL,&rc); - printf("--- getInstance rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); - if (rc.rc) printf("You may need to modify the hostname in line 41 or 42\n"); - + + if (0) { + /* Test getClass() */ + printf("\n----------------------------------------------------------\n"); + printf("Testing getClass() ...\n"); + objectpath = newCMPIObjectPath("root/cimv2", "Linux_ComputerSystem", NULL); + class = cc->ft->getClass(cc, objectpath, 0, NULL, &status); + + /* Print the results */ + printf("getClass() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); + if (!status.rc) { + printf("result:\n"); + showClass(class); + } + if (instance) CMRelease(instance); + if (objectpath) CMRelease(objectpath); + } + + if (1) { + /* Test enumInstanceNames() */ + printf("\n----------------------------------------------------------\n"); + printf("Testing enumInstanceNames() ...\n"); + objectpath = newCMPIObjectPath("root/cimv2", "Linux_ComputerSystem", NULL); + enumeration = cc->ft->enumInstanceNames(cc, objectpath, &status); + + /* Print the results */ + printf("enumInstanceNames() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); + if (!status.rc) { + printf("result(s):\n"); + while (enumeration->ft->hasNext(enumeration, NULL)) { + CMPIData data = enumeration->ft->getNext(enumeration, NULL); + showObjectPath(data.value.ref); + } + } + if (enumeration) CMRelease(enumeration); + if (objectpath) CMRelease(objectpath); + } + + if (0) { + /* Test enumInstances() */ + printf("\n----------------------------------------------------------\n"); + printf("Testing enumInstances() ...\n"); + objectpath = newCMPIObjectPath("root/cimv2", "Linux_ComputerSystem", NULL); + enumeration = cc->ft->enumInstances(cc, objectpath, 0, NULL, &status); + + /* Print the results */ + printf("enumInstances() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); + if (!status.rc) { + printf("result(s):\n"); + while (enumeration->ft->hasNext(enumeration, NULL)) { + CMPIData data = enumeration->ft->getNext(enumeration, NULL); + showInstance(data.value.inst); + } + } + if (enumeration) CMRelease(enumeration); + if (objectpath) CMRelease(objectpath); + } + + if (1) { + /* Test getInstance() */ + printf("\n----------------------------------------------------------\n"); + printf("Testing getInstance() ...\n"); + objectpath = newCMPIObjectPath("root/cimv2", "Linux_ComputerSystem", NULL); + CMAddKey(objectpath, "CreationClassName", "Linux_ComputerSystem", CMPI_chars); + CMAddKey(objectpath, "Name", _HOSTNAME, CMPI_chars); + instance = cc->ft->getInstance(cc, objectpath, 0, NULL, &status); + + /* Print the results */ + printf("getInstance() rc=%d, msg=%s\n", status.rc, (status.msg)? (char *)status.msg->hdl : NULL); + if (!status.rc) { + printf("result:\n"); + showInstance(instance); + } + if (instance) CMRelease(instance); + if (objectpath) CMRelease(objectpath); + } + return 0; - - - } |