CMPIStatus IndCIMXMLHandlerEnumInstances(CMPIInstanceMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char **properties) { CMPIStatus st; CMPIEnumeration *enm; CMPIContext *ctxLocal; CMPIInstance* ci; _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerEnumInstances"); if (interOpNameSpace(ref, &st) != 1) _SFCB_RETURN(st); ctxLocal = prepareUpcall((CMPIContext *) ctx); #ifdef HAVE_OPTIMIZED_ENUMERATION CMPIString *cn; CMPIObjectPath *refLocal; cn = CMGetClassName(ref, &st); if (strcasecmp(CMGetCharPtr(cn), "cim_listenerdestination") == 0) { enm = _broker->bft->enumerateInstances(_broker, ctxLocal, ref, properties, &st); while (enm && enm->ft->hasNext(enm, &st)) { ci=(enm->ft->getNext(enm, &st)).value.inst; filterInternalProps(ci); CMReturnInstance(rslt, ci); } refLocal = CMNewObjectPath(_broker, "root/interop", "cim_listenerdestinationcimxml", &st); enm = _broker->bft->enumerateInstances(_broker, ctxLocal, refLocal, properties, &st); while (enm && enm->ft->hasNext(enm, &st)) { ci=(enm->ft->getNext(enm, &st)).value.inst; filterInternalProps(ci); CMReturnInstance(rslt, ci); } refLocal = CMNewObjectPath(_broker, "root/interop", "cim_indicationhandlercimxml", &st); enm = _broker->bft->enumerateInstances(_broker, ctxLocal, refLocal, properties, &st); while (enm && enm->ft->hasNext(enm, &st)) { ci=(enm->ft->getNext(enm, &st)).value.inst; filterInternalProps(ci); CMReturnInstance(rslt, ci); } CMRelease(refLocal); } else { enm = _broker->bft->enumerateInstances(_broker, ctxLocal, ref, properties, &st); while (enm && enm->ft->hasNext(enm, &st)) { ci=(enm->ft->getNext(enm, &st)).value.inst; filterInternalProps(ci); CMReturnInstance(rslt, ci); } } #else enm = _broker->bft->enumerateInstances(_broker, ctxLocal, ref, properties, &st); while (enm && enm->ft->hasNext(enm, &st)) { ci=(enm->ft->getNext(enm, &st)).value.inst; filterInternalProps(ci); CMReturnInstance(rslt, ci); } #endif CMRelease(ctxLocal); if (enm) CMRelease(enm); _SFCB_RETURN(st); }
static CMPIStatus ClassProviderEnumClasses(CMPIClassMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref) { CMPIStatus st = { CMPI_RC_OK, NULL }; char *cn = NULL; CMPIFlags flgs = 0; CMPIString *cni; ClassBase *cb; Iterator it; char *key; int rc; CMPIConstClass *cls; ClassRegister *cReg; ReadCtl rctl; ClassRecord *crec; _SFCB_ENTER(TRACE_PROVIDERS, "ClassProviderEnumClasss"); cReg = getNsReg(ref, &rc); if (cReg == NULL) { CMPIStatus st = { CMPI_RC_ERR_INVALID_NAMESPACE, NULL }; _SFCB_RETURN(st); } cReg->ft->wLock(cReg); flgs = ctx->ft->getEntry(ctx, CMPIInvocationFlags, NULL).value.uint32; cni = ref->ft->getClassName(ref, NULL); if (cni) { cn = (char *) cni->hdl; if (cn && *cn == 0) cn = NULL; } cb = (ClassBase *) cReg->hdl; if (cn == NULL) { for (it = cReg->ft->getFirstClassRecord(cReg, &key, &crec); key && it && crec; it = cReg->ft->getNextClassRecord(cReg, it, &key, &crec)) { char *cn = key; char *pcn = crec->parent; if ((flgs & CMPI_FLAG_DeepInheritance) || pcn == NULL) { rctl = tempRead; CMPIConstClass *rcls = getResolvedClass(cReg, cn, crec, &rctl); CMReturnInstance(rslt, (CMPIInstance *) rcls); if (rctl != cached) CMRelease(rcls); } } } else { rctl = tempRead; cls = getResolvedClass(cReg, cn, NULL, &rctl); if (cls == NULL) { st.rc = CMPI_RC_ERR_INVALID_CLASS; } else if ((flgs & CMPI_FLAG_DeepInheritance) == 0) { UtilList *ul = getChildren(cReg, cn); char *child; if (ul) for (child = (char *) ul->ft->getFirst(ul); child; child = (char *) ul->ft->getNext(ul)) { rctl = tempRead; cls = getResolvedClass(cReg, child, NULL, &rctl); CMReturnInstance(rslt, (CMPIInstance *) cls); if (rctl != cached) CMRelease(cls); } } else if (cn && (flgs & CMPI_FLAG_DeepInheritance)) { loopOnChildren(cReg, cn, rslt); } } cReg->ft->wUnLock(cReg); _SFCB_RETURN(st); }
static void return2result(void *ret, CMPIInstance *ci) { CMPIResult *rslt = (CMPIResult *) ret; CMReturnInstance(rslt, ci); }
CMPIStatus getRefs(const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * cop, const char *assocClass, const char *resultClass, const char *role, const char *resultRole, const char **propertyList, int associatorFunction) { UtilList *refs = UtilFactory->newList(memAddUtilList, memUnlinkEncObj); char *ns = (char *) CMGetNameSpace(cop, NULL)->hdl; CMPIStatus st = { CMPI_RC_OK, NULL }; _SFCB_ENTER(TRACE_INTERNALPROVIDER, "getRefs"); if (assocClass != NULL) { CMPIObjectPath *path; if (assocForName(ns, assocClass, role, resultRole) == NULL) { /* * for an unknown class we just return nothing */ _SFCB_RETURN(st); } path = CMNewObjectPath(_broker, ns, assocClass, NULL); SafeInternalProviderAddEnumInstances(refs, NULL, ctx, path, propertyList, &st, 1); } else { CMPIData rv; CMPIObjectPath *op = CMNewObjectPath(Broker, ns, "$ClassProvider$", &st); CMPIArgs *in = CMNewArgs(Broker, NULL); CMPIArgs *out = CMNewArgs(Broker, NULL); rv = CBInvokeMethod(Broker, ctx, op, "getassocs", in, out, &st); if (out) { int i, m; CMPIArray *ar = CMGetArg(out, "assocs", &st).value.array; for (i = 0, m = CMGetArrayCount(ar, NULL); i < m; i++) { char *name = CMGetArrayElementAt(ar, i, NULL).value.string->hdl; if (name) { CMPIObjectPath *cop = CMNewObjectPath(Broker, ns, name, NULL); if (cop) { SafeInternalProviderAddEnumInstances(refs, NULL, ctx, cop, propertyList, &st, 1); } } _SFCB_TRACE(1, ("--- assoc %s", name)); } } } if (role) { // filter out the associations not matching the role property CMPIInstance *ci; UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop); for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) { CMPIData data = CMGetProperty(ci, role, NULL); if ((data.state & CMPI_notFound) || data.type != CMPI_ref || objectPathEquals(pn, data.value.ref, NULL, 0) == 0) { refs->ft->removeCurrent(refs); } } pn->ft->release(pn); } else { // filter out associations not referencing pathName CMPIInstance *ci; int matched, i, m; UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop); for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) { for (matched = 0, i = 0, m = CMGetPropertyCount(ci, NULL); i < m; i++) { CMPIData data = CMGetPropertyAt(ci, i, NULL, NULL); if (data.type == CMPI_ref && objectPathEquals(pn, data.value.ref, NULL, 0)) { matched = 1; break; } } if (matched == 0) refs->ft->removeCurrent(refs); } pn->ft->release(pn); } if (associatorFunction == REF) { CMPIInstance *ci; for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) { CMReturnInstance(rslt, ci); } refs->ft->release(refs); _SFCB_RETURN(st); } else if (associatorFunction == REF_NAME) { CMPIInstance *ci; for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) { CMPIObjectPath *ref = CMGetObjectPath(ci, NULL); CMReturnObjectPath(rslt, ref); } refs->ft->release(refs); _SFCB_RETURN(st); } else { // Use hashtable to avoid dup'd associators CMPIInstance *ci; UtilHashTable *assocs = UtilFactory->newHashTable(61, UtilHashTable_charKey); UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop); for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) { // Q: for ASSOC_NAME we should not require the // object exist if we go by the book, should we? // The current approach retrieves the instances // via the CIMOM handle if (resultRole) { CMPIData data = CMGetProperty(ci, resultRole, NULL); UtilStringBuffer *an = NULL; if ((data.state & CMPI_notFound) == 0 && data.type == CMPI_ref && objectPathEquals(pn, data.value.ref, &an, 0) == 0) { if (resultClass == NULL || CMClassPathIsA(Broker, data.value.ref, resultClass, NULL)) { CMPIInstance *aci = CBGetInstance(Broker, ctx, data.value.ref, propertyList, &st); assocs->ft->put(assocs, an->ft->getCharPtr(an), aci); } } } else { // must loop over the properties to find ref instances int i, m; for (i = 0, m = CMGetPropertyCount(ci, NULL); i < m; i++) { CMPIData data = CMGetPropertyAt(ci, i, NULL, NULL); if (data.type == CMPI_ref) { CMPIObjectPath *ref = data.value.ref; CMPIString *tns = CMGetNameSpace(ref, NULL); if (tns == NULL || tns->hdl == NULL) CMSetNameSpace(ref, ns); UtilStringBuffer *an = NULL; if (objectPathEquals(pn, ref, &an, 0) == 0) { if (resultClass == NULL || CMClassPathIsA(Broker, ref, resultClass, NULL)) { CMPIInstance *aci = CBGetInstance(Broker, ctx, ref, propertyList, &st); if (aci) assocs->ft->put(assocs, an->ft->getCharPtr(an), aci); } } } } } } { HashTableIterator *it; char *an; CMPIInstance *aci; for (it = assocs->ft->getFirst(assocs, (void **) &an, (void **) &aci); it; it = assocs->ft->getNext(assocs, it, (void **) &an, (void **) &aci)) { if (associatorFunction == ASSOC) CMReturnInstance(rslt, aci); else { CMPIObjectPath *op = CMGetObjectPath(aci, NULL); CMReturnObjectPath(rslt, op); } } } refs->ft->release(refs); assocs->ft->release(assocs); pn->ft->release(pn); _SFCB_RETURN(st); } }
int assoc_ServiceProcess( const CMPIBroker * _broker, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * ref, int assocType, CMPIStatus * rc ) { CMPIString * sourceClass = NULL; CMPIData serviceName; CMPIObjectPath * op = NULL; CMPIObjectPath * rop = NULL; CMPIInstance * rci = NULL; CMPIInstance * sci = NULL; LXS_Handle lhdl; LXS_Service * lxssvc = NULL; int i = 0; _OSBASE_TRACE(2,("--- assoc_ServiceProcess() called")); /* check if source instance does exist */ sci = CBGetInstance(_broker, ctx, ref, NULL, rc); if( sci == NULL ) { if( rc->rc == CMPI_RC_ERR_FAILED ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "GetInstance of source object failed."); } if( rc->rc == CMPI_RC_ERR_NOT_FOUND ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_NOT_FOUND, "Source object not found."); } _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } sourceClass = CMGetClassName(ref, rc); if (CMGetCharPtr(sourceClass) == NULL) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Could not get source class name."); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } /* source class is Linux_UnixProcess; target class is Linux_Service */ if( strcasecmp(CMGetCharPtr(sourceClass),_RefRightClass) == 0 ) { /* NOT_SUPPORTED - association is uni-directional */ } /* source class is Linux_Service; target class is Linux_UnixProcess */ else if( strcasecmp(CMGetCharPtr(sourceClass),_RefLeftClass) == 0 ) { serviceName = CMGetKey(ref, "Name", rc); if( serviceName.value.string == NULL ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Could not get Name of Service" ); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } lhdl=LXS_InitFiltered(CMGetCharPtr(serviceName.value.string)); if (lhdl==NULL) { _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service.")); return 0; } lxssvc=LXS_Next(lhdl); if (lxssvc==NULL) { _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service.")); return 0; } /* get the list of associated processe */ for (i=0;lxssvc->svProcesses[i]!=NULL;i++) { op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), _RefRightClass, rc ); if( CMIsNullObject(op) ) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg))); return -1; } CMAddKey(op, "CSCreationClassName", CSCreationClassName, CMPI_chars); CMAddKey(op, "CSName", get_system_name(), CMPI_chars); CMAddKey(op, "OSCreationClassName", OSCreationClassName, CMPI_chars); CMAddKey(op, "OSName", get_os_name(), CMPI_chars); CMAddKey(op, "CreationClassName", _RefRightClass, CMPI_chars); CMAddKey(op, "Handle", lxssvc->svProcesses[i], CMPI_chars); if (assocType&ATYPE_ASSOC) { /* the process (name) */ if (assocType&ATYPE_NAME) { CMReturnObjectPath(rslt, op); } else { rci = CBGetInstance(_broker, ctx, op, NULL, rc); if(rci==NULL) { return -1; } CMReturnInstance( rslt, rci ); } } else { /* the reference object (name) */ if (assocType&ATYPE_NAME) { rop = _makePath_ServiceProcess(_broker, ref, op, rc); CMReturnObjectPath(rslt, rop); } else { rci = _makeInst_ServiceProcess(_broker, ref, op, rc); CMReturnInstance( rslt, rci ); } } } LXS_Term(lhdl); } _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited")); return 0; }
static CMPIStatus ClassProviderEnumClasses(CMPIClassMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref) { CMPIStatus st = { CMPI_RC_OK, NULL }; char *cn = NULL; CMPIFlags flgs = 0; CMPIString *cni; ClassBase *cb; HashTableIterator *it; char *key; int rc; CMPIConstClass *cls; ClassRegister *cReg; _SFCB_ENTER(TRACE_PROVIDERS, "ClassProviderEnumClasss"); cReg = getNsReg(ref, &rc); if (cReg == NULL) { CMPIStatus st = { CMPI_RC_ERR_INVALID_NAMESPACE, NULL }; _SFCB_RETURN(st); } cReg->ft->rLock(cReg); flgs = ctx->ft->getEntry(ctx, CMPIInvocationFlags, NULL).value.uint32; cni = ref->ft->getClassName(ref, NULL); if (cni) { cn = (char *) cni->hdl; if (cn && *cn == 0) cn = NULL; } cb = (ClassBase *) cReg->hdl; if (cn == NULL) { for (it = cb->ht->ft->getFirst(cb->ht, (void **) &key, (void **) &cls); key && it && cls; it = cb->ht->ft->getNext(cb->ht, it, (void **) &key, (void **) &cls)) { if ((flgs & CMPI_FLAG_DeepInheritance) || cls->ft->getCharSuperClassName(cls) == NULL) { CMReturnInstance(rslt, (CMPIInstance *) cls); } } } else { cls = getClass(cReg, cn); if (cls == NULL) { st.rc = CMPI_RC_ERR_INVALID_CLASS; } else if ((flgs & CMPI_FLAG_DeepInheritance) == 0) { UtilList *ul = getChildren(cReg, cn); char *child; if (ul) for (child = (char *) ul->ft->getFirst(ul); child; child = (char *) ul->ft->getNext(ul)) { cls = getClass(cReg, child); CMReturnInstance(rslt, (CMPIInstance *) cls); } } else if (flgs & CMPI_FLAG_DeepInheritance) { loopOnChildren(cReg, cn, rslt); } } cReg->ft->rUnLock(cReg); _SFCB_RETURN(st); }
CMPIStatus TestAssociationProviderReferences(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; /* * 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); } CMReturnInstance(rslt, ci); } } return rc; }
CMPIStatus KDefaultGetInstance( const CMPIBroker* mb, CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { #if defined(DIRECT_CALL) static CMPIResultFT _ft = { CMPICurrentVersion, _DefaultGI_release, _DefaultGI_clone, _DefaultGI_returnData, _DefaultGI_returnInstance, _DefaultGI_returnObjectPath, _DefaultGI_returnDone, _DefaultGI_returnError }; DefaultGI_Result result; DefaultGI_Handle handle; CMPIStatus st; handle.result = cr; handle.cop = cop; handle.found = 0; result.hdl = (void*)&handle; result.ft = &_ft; st = (*mi->ft->enumerateInstances)( mi, cc, (CMPIResult*)(void*)&result, cop, NULL); if (!st.rc) return st; if (!handle.found) { KReturn(ERR_NOT_FOUND); } KReturn(OK); #else /* defined(DIRECT_CALL) */ CMPIEnumeration* e; CMPIStatus st; CMPIObjectPath* ccop; /* Create an object path with just the class from cop */ ccop = CMNewObjectPath(mb, KNameSpace(cop), KClassName(cop), &st); if (!ccop) KReturn(ERR_FAILED); /* Enumerate all instances of this class */ if (!(e = mb->bft->enumerateInstances(mb, cc, ccop, properties, &st))) KReturn(ERR_FAILED); while (CMHasNext(e, &st)) { CMPIData cd; CMPIObjectPath* tcop; cd = CMGetNext(e, &st); if (st.rc || cd.type != CMPI_instance || (cd.state & CMPI_nullValue)) KReturn(ERR_FAILED); if (!(tcop = CMGetObjectPath(cd.value.inst, &st))) KReturn(ERR_FAILED); if (KMatch(tcop, cop)) { CMReturnInstance(cr, cd.value.inst); KReturn(OK); } } KReturn(ERR_NOT_FOUND); #endif /* !defined(DIRECT_CALL) */ }
CMPIStatus TestAssociationProviderAssociators(CMPIAssociationMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *_RefLeftClass, const char *_RefRightClass, const char *role, const char *resultRole, const char **properties) { CMPIObjectPath *op = NULL; CMPIEnumeration *en = NULL; CMPIData data; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIString *sourceClass = NULL; sourceClass = CMGetClassName(ref, &rc); /* * 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; } sourceClass = CMGetClassName(op, &rc); /* * Call to Associators */ /* * upcall to CIMOM; call enumInstances() of the target class */ en = CBEnumInstances(_broker, ctx, op, NULL, &rc); /* * as long as instance entries are found in the enumeration */ if (!rc.rc) while (CMHasNext(en, &rc)) { /* * get the instance */ data = CMGetNext(en, &rc); /* * and return the target class instance as result of the * associators() call */ CMReturnInstance(rslt, data.value.inst); } return rc; }
CMPIStatus TestInstanceProviderExecQuery ( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * referencePath, const char *query, const char *lang) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIStatus rc_Eval = { CMPI_RC_OK, NULL }; CMPIStatus rc_Clone = { CMPI_RC_OK, NULL }; CMPIStatus rc_Array = { CMPI_RC_OK, NULL }; CMPISelectExp *se_def = NULL; CMPICount cnt = 0; CMPIArray *projection = NULL; unsigned int j = 0; CMPIBoolean evalRes; CMPIData arr_data; CMPIInstance *instance1; CMPIObjectPath *cop1; CMPIData data; CMPIValue value1; const char* prop_name; CMPIData retProp; /*create the select expression */ se_def = CMNewSelectExp (_broker, query, lang, &projection, &rc_Clone); if (se_def) { /*loop over instances in array to evaluate for requested properties */ for (j = 0; j < numOfInst ; j++) { /*check for validity of Instance,that its not deleted */ if(valid[j] == 1) { /*get the element from array */ arr_data = CMGetArrayElementAt( clone_arr_ptr, j, &rc); /*Evaluate the instance using this select expression */ evalRes = CMEvaluateSelExp(se_def,arr_data.value.inst, &rc_Eval); if (evalRes) { /*check if any of properties are requested */ if (projection) { /*get number of properties requested */ cnt = CMGetArrayCount (projection, &rc_Array); /*if count is not equal to number of properties of instance */ if(cnt == 1) { /*check for the properties, requested */ data = CMGetArrayElementAt( projection, 0, &rc_Array); prop_name = CMGetCharsPtr ( data.value.string, &rc); /*create the new instance that has to be returned */ cop1 = CMNewObjectPath( _broker, "root/cimv2", _ClassName, &rc); instance1 = CMNewInstance(_broker, cop1, &rc); /*if property name is "Identifier", gets its value from instance */ if(!strcmp(prop_name, "Identifier")) { retProp = CMGetProperty( arr_data.value.inst, "Identifier", &rc); value1.uint8 = retProp.value.uint8; CMSetProperty( instance1, "Identifier", (CMPIValue *)&value1, CMPI_uint8); } /*if property name is "Message", gets its value from instance */ if(!strcmp(prop_name, "Message")) { retProp = CMGetProperty( arr_data.value.inst, "Message", &rc); value1.string = retProp.value.string; CMSetProperty( instance1, "Message", (CMPIValue *)&value1, CMPI_string); } /*if the query is evaluated return instance */ CMReturnInstance (rslt, instance1); } } else { CMReturnInstance(rslt, arr_data.value.inst); } } } } } CMReturnDone (rslt); CMReturn (CMPI_RC_OK); }
CMPIStatus Linux_FanProviderGetInstance( CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const char **properties) { UNUSED(mi); CMPIInstance * ci = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; struct cim_fan * sptr = NULL; CMPIData data; CMPIArray * other_identifying_info = NULL; CMPIString * sys_path = NULL; CMPIString * fan_name = NULL; CMPIString * device_id = NULL; cim_fan_error_t cmdrc; _OSBASE_TRACE(1,("--- %s CMPI GetInstance() called",_ClassName)); _check_system_key_value_pairs(_broker, cop, "SystemCreationClassName", "SystemName", &rc); if (rc.rc != CMPI_RC_OK) { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); return rc; } data = CMGetKey(cop, "OtherIdentifyingInfo", &rc); if ( !rc.rc && data.type == CMPI_stringA && (other_identifying_info = data.value.array) && !rc.rc && (CMGetArrayCount(other_identifying_info, &rc) > 1) && !rc.rc) { data = CMGetArrayElementAt(other_identifying_info, 0, &rc); if (!rc.rc) sys_path = data.value.string; data = CMGetArrayElementAt(other_identifying_info, 1, &rc); if (!rc.rc) fan_name = data.value.string; } device_id = CMGetKey(cop, "DeviceID", &rc).value.string; if ((sys_path == NULL || fan_name == NULL) && (device_id == NULL)) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED, "Could not get fan ID." ); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); return rc; } if (sys_path && fan_name) { cmdrc = get_fan_data(CMGetCharPtr(sys_path), CMGetCharPtr(fan_name), &sptr); } if ((cmdrc || !sptr) && device_id) { cmdrc = get_fan_data_by_id(CMGetCharPtr(device_id), &sptr); } if (cmdrc || !sptr) { CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_NOT_FOUND, cim_fan_strerror(cmdrc)); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() exited : %s", _ClassName,CMGetCharPtr(rc.msg))); return rc; } ci = _makeInst_Fan(_broker, ctx, cop, properties, sptr, &rc); if (sptr) free_fan(sptr); if (ci == NULL) { if (rc.msg != NULL) { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed : %s", _ClassName, CMGetCharPtr(rc.msg))); }else { _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() failed", _ClassName)); } return rc; } CMReturnInstance(rslt, ci); CMReturnDone(rslt); _OSBASE_TRACE(1, ("--- %s CMPI GetInstance() exited", _ClassName)); 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; }
CMPIStatus TestCMPIBrokerInstanceProviderGetInstance (CMPIInstanceMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const char **properties) { CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIString* retNamespace; CMPIString* retClassname; CMPIString* type; CMPIData retData; CMPIObjectPath* obj; CMPIBoolean bol = 0; const char* str1; const char* str2; PROV_LOG_OPEN (_ClassName, _ProviderLocation); PROV_LOG("GetInstance"); PROV_LOG("++++Namespace"); obj = CMGetObjectPath(_inst, &rc); PROV_LOG("++++ Status of CMGetObjectPath : (%s)", strCMPIStatus(rc)); retNamespace = CMGetNameSpace(obj, &rc); PROV_LOG("++++ Status of CMGetNameSpace : (%s)", strCMPIStatus(rc)); retClassname = CMGetClassName(obj, &rc); PROV_LOG("++++ Status of CMGetClassName : (%s)", strCMPIStatus(rc)); str1 = CMGetCharsPtr(retNamespace, &rc); PROV_LOG("++++ Status of CMGetCharsPtr : (%s)", strCMPIStatus(rc)); str2 = CMGetCharsPtr(retClassname, &rc); PROV_LOG("++++ Status of CMGetCharsPtr : (%s)", strCMPIStatus(rc)); retData = CMGetProperty(_inst, "n64", &rc); PROV_LOG("++++ Status of CMGetProperty : (%s)", strCMPIStatus(rc)); PROV_LOG("n64 = %" PEGASUS_64BIT_CONVERSION_WIDTH "u", retData.value.uint64); /* Test cases for increasing coverage in CMPI_BrokerEnc.cpp*/ type = CDGetType (_broker, rslt, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type " "CMPIResult with CMPI_ResultInstOnStack_Ftab : (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); bol = CDIsOfType (_broker, rslt, "CMPIResult", &rc); if ( bol ) { PROV_LOG ("++++ CDIsOfType for CMPIResult with " "CMPI_ResultInstOnStack_Ftab status is (%s) : %d", strCMPIStatus (rc), bol); } PROV_LOG_CLOSE(); if (_inst) { CMReturnInstance(rslt, _inst); CMReturnDone(rslt); CMReturn (CMPI_RC_OK); } else { CMReturn (CMPI_RC_ERR_NOT_SUPPORTED); } }