CMPIObjectPath * get_assoc_targetClass_ObjectPath(const CMPIBroker * broker, const CMPIObjectPath * ref, const char *_RefLeftClass, const char *_RefRightClass, CMPIStatus *rc) { CMPIObjectPath *op = NULL; const char *targetName = NULL; /* * get name of the target class */ targetName = get_assoc_targetClass_Name(broker, ref, _RefLeftClass, _RefRightClass, rc); if (targetName != NULL) { /* * create new object path of the target class */ op = CMNewObjectPath(broker, CMGetCharsPtr(CMGetNameSpace(ref, rc), NULL), targetName, rc); if (!op) CMSetStatusWithChars(_broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed in cmpiTestAssociationProvider"); } return op; }
CMPIObjectPath * get_assoc_targetClass_ObjectPath(const CMPIBroker * broker, const CMPIObjectPath * ref, const char *_RefLeftClass, const char *_RefRightClass, CMPIStatus *rc) { CMPIObjectPath *op = NULL; const char *targetName = NULL; /* * get name of the target class */ targetName = get_assoc_targetClass_Name(broker, ref, _RefLeftClass, _RefRightClass, rc); if (targetName != NULL) { /* * create new object path of the target class */ op = CMNewObjectPath(broker, CMGetCharsPtr(CMGetNameSpace(ref, rc), NULL), targetName, rc); } return op; }
CMPIStatus TestAssociationProviderReferenceNames(CMPIAssociationMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *resultClass, const char *role) { CMPIInstance *ci = NULL; CMPIObjectPath *op = NULL; CMPIObjectPath *rop = NULL; CMPIObjectPath *cop = NULL; CMPIEnumeration *en = NULL; CMPIData data; const char *targetName = NULL; const char *_thisClassName; const char *_RefLeftClass = NULL; const char *_RefRightClass = NULL; CMPIStatus rc = { CMPI_RC_OK, NULL }; _thisClassName = _ClassName; /* * get object path of the target class */ op = get_assoc_targetClass_ObjectPath(_broker, ref, _RefLeftClass, _RefRightClass, &rc); /* * check for a failure in creating the object path */ if (rc.rc != CMPI_RC_OK) return rc; /* * the target class does not belong to us so just return CMPI_RC_OK */ if (!op) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_OK, NULL ); return rc; } /* * create new object path of association */ rop = CMNewObjectPath(_broker, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL), _thisClassName, &rc); /* * upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames(_broker, ctx, op, &rc); /* * as long as object path entries are found in the enumeration */ if (!rc.rc) while (CMHasNext(en, &rc)) { /* * get the object path */ data = CMGetNext(en, &rc); /* * create new instance of the association */ ci = CMNewInstance(_broker, rop, &rc); /* * get name of the target class */ targetName = get_assoc_targetClass_Name(_broker, ref, _RefLeftClass, _RefRightClass, &rc); /* * set the properties of the association instance depending on the * constellation of the source class (parameter ref) and the target * class (see targetName) */ if (strcmp(targetName, "CMPI_TEST_Person") == 0) { CMSetProperty(ci, "model", (CMPIValue *) & (data.value.ref), CMPI_ref); CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref); } else if (strcmp(targetName, "CMPI_TEST_Vehicle") == 0) { CMSetProperty(ci, "model", (CMPIValue *) & (data.value.ref), CMPI_ref); CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref); } /* * get object path of association instance */ cop = CMGetObjectPath(ci, &rc); /* * set namespace in object path of association */ CMSetNameSpace(cop, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL)); /* * and return the association object path as result of the * referenceNames() call */ CMReturnObjectPath(rslt, cop); } return rc; }
CMPIStatus TestCMPIAssociationProviderReferences( CMPIAssociationMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * ref, const char *resultClass, const char *role , const char** properties) { CMPIInstance * ci = NULL; CMPIObjectPath * op = NULL; CMPIObjectPath * rop = NULL; CMPIEnumeration * en = NULL; CMPIData data ; const char * targetName = NULL; char * _thisClassName; char * _RefLeftClass = NULL; char * _RefRightClass = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; _thisClassName=_ClassName; PROV_LOG_OPEN (_thisClassName, _ProviderLocation); PROV_LOG ("\n\n********************* %s CMPI References() called", _thisClassName); /* get object path of the target class */ op = get_assoc_targetClass_ObjectPath( _broker, ref, _RefLeftClass, _RefRightClass, &rc); PROV_LOG (" New Object Path [%s]", CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL)); /* create new object path of association */ rop = CMNewObjectPath( _broker, CMGetCharsPtr(CMGetNameSpace(ref,&rc),NULL), _thisClassName, &rc ); /* upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames( _broker, ctx, op, &rc); /* as long as object path entries are found in the enumeration */ while( CMHasNext( en, &rc) ) { /* get the object path */ data = CMGetNext( en, &rc); { /* create new instance of the association */ ci = CMNewInstance( _broker, rop, &rc); /* get name of the target class */ targetName = get_assoc_targetClass_Name( _broker, ref, _RefLeftClass, _RefRightClass, &rc); /* set the properties of the association instance depending on the * constellation of the source class (parameter ref) and the target * class (see targetName) */ if(strcmp (targetName, "CMPI_TEST_Person")== 0) { CMSetProperty( ci, "model", (CMPIValue*)&(data.value.ref), CMPI_ref ); CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref ); } else if( strcmp( targetName,"CMPI_TEST_Vehicle") == 0 ) { CMSetProperty( ci, "model", (CMPIValue*)&(data.value.ref), CMPI_ref ); CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref ); } CMReturnInstance( rslt, ci ); } } PROV_LOG ("\n\n********************* %s CMPI References() exited", _thisClassName); PROV_LOG_CLOSE (); return rc; }