CMPIStatus get_profile(const CMPIBroker *broker, const CMPIObjectPath *reference, const char **properties, const char* pfx, struct reg_prof *profile, CMPIInstance **_inst) { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance = NULL; CMPIArray *array; instance = get_typed_instance(broker, pfx, "RegisteredProfile", CIM_INTEROP_NS, false); if (instance == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Can't create RegisteredProfile instance"); goto out; } if (properties) { const char *keys[] = {"InstanceID", NULL}; CMSetPropertyFilter(instance, properties, keys); } CMSetProperty(instance, "InstanceID", (CMPIValue *)profile->reg_id, CMPI_chars); CMSetProperty(instance, "RegisteredOrganization", (CMPIValue *)&profile->reg_org, CMPI_uint16); CMSetProperty(instance, "RegisteredName", (CMPIValue *)profile->reg_name, CMPI_chars); CMSetProperty(instance, "RegisteredVersion", (CMPIValue *)profile->reg_version, CMPI_chars); array = CMNewArray(broker, 1, CMPI_uint16, &s); if ((s.rc != CMPI_RC_OK) || (CMIsNullObject(array))) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to create CMPIArray object"); goto out; } CMSetArrayElementAt(array, 0, &profile->ad_types, CMPI_uint16); CMSetProperty(instance, "AdvertiseTypes", (CMPIValue *)&array, CMPI_uint16A); *_inst = instance; out: return s; }
/***************************************************************************** * Set CIM instance properties based on backend xen resource data * * @param in ft - xen backend provider function table * @param in/out inst - CIM instance whose properties are to be set * @param in res - xen resource * @param in properties - CIM properties that caller cares about * @return CMPIrc error codes *****************************************************************************/ CMPIrc prov_pxy_setproperties( const XenProviderInstanceFT* ft, CMPIInstance *inst, const void *res, const char **properties) { provider_resource *resource = (provider_resource *) res; if(res == NULL || CMIsNullObject(inst)) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Invalid input parameter")); return CMPI_RC_ERR_FAILED; } RESET_XEN_ERROR(resource->session->xen); /* Setup a filter to only return the desired properties. */ const char **keys = ft->xen_resource_get_keys(resource->broker, resource->classname); CMSetPropertyFilter(inst, properties, keys); return ft->xen_resource_set_properties(resource, inst); }
CMPIInstance * _makeInst_TestClassA( const CMPIBroker * _broker, const CMPIContext * ctx, const CMPIObjectPath * cop, const char ** properties) { CMPIArray *array = NULL; CMPIValue opstatus; CMPIValue status; CMPIValue theKey; CMPIObjectPath* op=NULL; CMPIInstance* ci=NULL; opstatus.uint16 = 0; /* Unknown */ status.uint16 = 2; /* Enabled */ theKey.uint32 = 2; // // Construct ObjectPath // op=_makePath_TestClassA(_broker,ctx,cop); // // Create a new instance and fill it's properties // ci = CMNewInstance( _broker, op, NULL); CMRelease(op); CMSetPropertyFilter(ci,properties,NULL); // // Properties of CIM_ManagedElement // CMSetProperty(ci,"Caption","Test class A",CMPI_chars); CMSetProperty( ci, "Description", "Test class used for all kinds of testing", CMPI_chars); CMSetProperty(ci,"ElementName","Instance1",CMPI_chars); // // Properties of CIM_ManagedSystemElement // array = CMNewArray(_broker,1,CMPI_uint16,NULL); CMSetArrayElementAt(array,0,&opstatus,CMPI_uint16); CMSetProperty(ci,"OperationalStatus",(CMPIValue*)&(array),CMPI_uint16A); // // Properties of CIM_EnabledLogicalElement // CMSetProperty(ci,"EnabledState",&status,CMPI_uint16); CMSetProperty(ci,"OtherEnabledState","NULL",CMPI_chars); CMSetProperty(ci,"RequestedState",&status,CMPI_uint16); CMSetProperty(ci,"EnabledDefault",&status,CMPI_uint16); // // Properties of CIM_TestClass // CMSetProperty(ci,"theKey",&theKey,CMPI_uint32 ); CMSetProperty(ci,"theData",&theKey,CMPI_uint32 ); CMSetProperty(ci,"theString","Test Instance Number One",CMPI_chars); return ci; }
CMPIInstance * _makeInst_TestClass( const CMPIBroker * _broker, const CMPIContext * ctx, const CMPIObjectPath * ref, const char ** properties, CMPIStatus * rc, unsigned int theKey) { CMPIValue opstatus; CMPIValue status; CMPIObjectPath * op = NULL; CMPIInstance * ci = NULL; char * theName = NULL; CMPIArray *array = NULL; char **keys = NULL; int keyCount = 0; opstatus.uint16 = 0; /* Unknown */ status.uint16 = 2; /* Enabled */ // // Initialize Name // theName = calloc(1,20); sprintf(theName, "%u", theKey); // // Construct ObjectPath // op = CMNewObjectPath( _broker, CMGetCharsPtr(CMGetNameSpace(ref,rc), NULL), _ClassName, rc); if (CMIsNullObject(op)) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); goto exit; } // // Create a new instance and fill it's properties // ci = CMNewInstance( _broker, op, rc); if (CMIsNullObject(ci)) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIInstance failed." ); goto exit; } // // Set property filter // keys = calloc(2,sizeof(char*)); keys[0] = strdup("theKey"); CMSetPropertyFilter(ci,properties,(const char**)keys); for (;keys[keyCount]!=NULL;keyCount++) { free((char*)keys[keyCount]); } free(keys); // // Properties of CIM_ManagedElement // CMSetProperty(ci,"Caption","Performance Test class",CMPI_chars); CMSetProperty( ci, "Description", "Test class used for all kinds of testing", CMPI_chars); CMSetProperty(ci,"ElementName",theName,CMPI_chars); // // Properties of CIM_ManagedSystemElement // // TBD: InstallDate array = CMNewArray(_broker,1,CMPI_uint16,rc); CMSetArrayElementAt(array,0,&opstatus,CMPI_uint16); CMSetProperty(ci,"OperationalStatus",(CMPIValue*)&(array),CMPI_uint16A); // // Properties of CIM_EnabledLogicalElement // CMSetProperty( ci, "EnabledState", &status, CMPI_uint16); CMSetProperty( ci, "RequestedState", &status, CMPI_uint16); CMSetProperty( ci, "EnabledDefault", &status, CMPI_uint16); // // Properties of CIM_TestClass // CMSetProperty(ci,"theKey",&theKey , CMPI_uint32 ); CMSetProperty(ci,"theData",&theKey , CMPI_uint32 ); CMSetProperty(ci,"theString0","Test Data Number Zero",CMPI_chars); CMSetProperty(ci,"theString1","Test Data Number One",CMPI_chars); CMSetProperty(ci,"theString2","Test Data Number Two",CMPI_chars); CMSetProperty(ci,"theString3","Test Data Number Three",CMPI_chars); CMSetProperty(ci,"theString4","Test Data Number Four",CMPI_chars); CMSetProperty(ci,"theString5","Test Data Number Five",CMPI_chars); CMSetProperty(ci,"theString6","Test Data Number Six",CMPI_chars); CMSetProperty(ci,"theString7","Test Data Number Seven",CMPI_chars); CMSetProperty(ci,"theString8","Test Data Number Eight",CMPI_chars); CMSetProperty(ci,"theString9","Test Data Number Nine",CMPI_chars); exit: free(theName); return ci; }
CMPIInstance * _makeInst_Service( const CMPIBroker * _broker, const CMPIContext * ctx, const CMPIObjectPath * ref, const char ** properties, LXS_Service * lxssvc, CMPIStatus * rc) { CMPIObjectPath * op = NULL; CMPIInstance * ci = NULL; const char ** keys = NULL; int keyCount = 0; _OSBASE_TRACE(2,("--- _makeInst_Service() called")); /* the sblim-cmpi-base package offers some tool methods to get common * system data */ if( !get_system_name() ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "no host name found" ); _OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), _ClassName, rc ); if( CMIsNullObject(op) ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); _OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } ci = CMNewInstance( _broker, op, rc); if( CMIsNullObject(ci) ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIInstance failed." ); _OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } /* set property filter */ keys = calloc(5,sizeof(char*)); keys[0] = strdup("SystemCreationClassName"); keys[1] = strdup("SystemName"); keys[2] = strdup("CreationClassName"); keys[3] = strdup("Name"); CMSetPropertyFilter(ci,properties,keys); for( ;keys[keyCount]!=NULL;keyCount++) { free((char*)keys[keyCount]); } free(keys); CMSetProperty( ci, "SystemCreationClassName", CSCreationClassName, CMPI_chars ); CMSetProperty( ci, "SystemName", get_system_name(), CMPI_chars ); CMSetProperty( ci, "CreationClassName", _ClassName, CMPI_chars ); CMSetProperty( ci, "Name", lxssvc->svName, CMPI_chars ); CMSetProperty( ci, "Caption", "Linux (/etc/init.d) Service", CMPI_chars); CMSetProperty( ci, "Description", "Instances of this class represents the /etc/init.d managed Services.", CMPI_chars); CMSetProperty( ci, "Status", lxssvc->svStatus, CMPI_chars); CMSetProperty( ci, "Started", (CMPIValue*)&(lxssvc->svStarted), CMPI_boolean); exit: _OSBASE_TRACE(2,("--- _makeInst_Service() exited")); return ci; }
// For Increasing the Coverage of CMPIInstance static int _testInstance () { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIInstance* instance = NULL; CMPIObjectPath* objPath = NULL; CMPIObjectPath* objPathFake = NULL; CMPIValue value; CMPIType type = CMPI_uint64; CMPIData retData; CMPIData returnedData1; const char* property_name = "s"; const char* origin = "origin"; void* handle; int flag = 1; value.uint64 = PEGASUS_UINT64_LITERAL(5000000000); PROV_LOG("++++ _testInstance"); objPath = make_ObjectPath(_broker, _Namespace, "TestCMPI_Instance"); instance = make_Instance(objPath); /* Test cases to increase coverage in instSetPropertyWithOrigin function */ /* Setting n64 property in class TestCMPI_Instance. So origin has been set to TestCMPI_Instance.*/ rc = CMSetPropertyWithOrigin(instance, "n64", &value, type, "TestCMPI_Instance"); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin for n64 property status : (%s)", strCMPIStatus(rc)); } /* CMGetProperty is called to verify the value of the property just being set. */ retData = CMGetProperty(instance, "n64", &rc); if (retData.type == CMPI_uint64 && retData.value.uint64 == PEGASUS_UINT64_LITERAL(5000000000)) { PROV_LOG("++++ CMGetProperty for n64 property status : (%s)," "value (%"PEGASUS_64BIT_CONVERSION_WIDTH"u)", strCMPIStatus(rc), retData.value.uint64); } /* Setting non-member property of type CMPI_ref*/ type= CMPI_ref; value.ref = objPath; rc = CMSetPropertyWithOrigin(instance, "objPath", &value, type, origin); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin status : (%s)",strCMPIStatus(rc)); } /* Setting non-memeber property of type other than CMPI_ref*/ value.uint32 = 32; type = CMPI_uint32; rc = CMSetPropertyWithOrigin(instance, "n32", &value, type, NULL); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin status : (%s)",strCMPIStatus(rc)); } /* Testing error path for instGetProperty with NULL property name*/ returnedData1 = CMGetProperty(instance, NULL, &rc); if (rc.rc == CMPI_RC_ERR_INVALID_PARAMETER ) { PROV_LOG("++++ CMGetProperty with NULL property name status: (%s) ", strCMPIStatus(rc)); } /*-----------------------------------------------------------------------*/ /* Test cases to cover error paths for instSetObjectPath and instSetPropertyFilter*/ /* Testing error path by passing CMPIObjectPath with class name different from the classname for CMPIInstance in CMSetObjectPath*/ objPathFake = CMNewObjectPath(_broker, _Namespace, "TestCMPIInstance_Method", NULL); rc = CMSetObjectPath(instance, objPathFake); if ( rc.rc == CMPI_RC_ERR_FAILED || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ Test for CMSetObjectPath with wrong input passed"); } /* Testing error path by passing NULL to instSetObjectPath*/ rc = CMSetObjectPath(instance, NULL); if ( rc.rc == CMPI_RC_ERR_INVALID_PARAMETER || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ Test for CMSetObjectPath with NULL input passed "); } /* Testing error paths by setting handle to CMPIInstance to NULL and using that in calls to instSetObjectPath and instSetPropertyFilter*/ handle = instance->hdl; instance->hdl = NULL ; rc = CMSetObjectPath(instance, NULL); if ( rc.rc == CMPI_RC_ERR_INVALID_HANDLE || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ CMSetObjectPath with NULL handle for" " CMPIInstance passed"); } PROV_LOG("++++ CMSetObjectPath : (%s) ",strCMPIStatus(rc)); rc = CMSetPropertyFilter(instance,&property_name,NULL); if( rc.rc == CMPI_RC_ERR_INVALID_HANDLE ) { PROV_LOG("++++ CMSetPropertyFilter with NULL handle for CMPIInstance" " status : (%s)", strCMPIStatus (rc)); } instance->hdl = handle; /*-----------------------------------------------------------------------*/ return flag; } // _testInstance end