CMPIStatus KBase_FromObjectPath(KBase* self, const CMPIObjectPath* cop) { CMPIString* cn; CMPIString* ns; CMPIStatus st = KSTATUS_INIT; CMPICount count; CMPICount i; KValue* kv; if (!self || self->magic != KMAGIC) KReturn(ERR_FAILED); /* Set namespace */ if (!(ns = CMGetNameSpace(cop, &st))) return st; self->ns = ns; /* Get classname */ if (!(cn = CMGetClassName(cop, &st))) return st; /* For each property */ count = CMGetKeyCount(cop, &st); if (!KOkay(st)) return st; for (i = 0; i < count; i++) { CMPIData cd; CMPIString* pn = NULL; KTag tag; /* Get i-th property */ cd = CMGetKeyAt(cop, i, &pn, &st); if (!KOkay(st)) return st; if (!pn) KReturn(ERR_FAILED); /* Find the given property */ if ((kv = _find_property(self, KChars(pn), &tag))) { _set_key_value(kv, tag, &cd); } } KReturn(OK); }
//finds a property static AWE_CLASS_PROPERTY *_find_property(const char *name, AWE_CLASS *pclass) { AWE_CLASS_PROPERTY *prop; if (pclass->properties) { for(prop = pclass->properties; prop->name; prop++) { if (strcmp(prop->name, name) == 0) return prop; } } return pclass->super ? _find_property(name, pclass->super) : 0; }
CMPIStatus KBase_FromArgs( KBase* self, const CMPIArgs* ca, CMPIBoolean in, CMPIBoolean out) { CMPIStatus st = KSTATUS_INIT; CMPICount count; CMPICount i; KValue* kv; if (!self || self->magic != KMAGIC) KReturn(ERR_FAILED); /* For each arg */ count = CMGetArgCount(ca, &st); if (!KOkay(st)) return st; for (i = 0; i < count; i++) { CMPIData cd; CMPIString* name = NULL; KTag tag; /* Get i-th property */ cd = CMGetArgAt(ca, i, &name, &st); if (!KOkay(st)) return st; if (!name) KReturn(ERR_FAILED); /* Find the given property */ if ((kv = _find_property(self, KChars(name), &tag))) { if (in && !(tag & KTAG_IN)) continue; if (out && !(tag & KTAG_OUT)) continue; _set_value(kv, tag, &cd); } } KReturn(OK); }
//gets an object's properties int awe_get_object_properties_va(AWE_OBJECT *obj, va_list params) { AWE_CLASS_PROPERTY *prop; const char *prop_name; int count = 0; void *buffer; while (1) { prop_name = va_arg(params, const char *); if (!prop_name) break; buffer = va_arg(params, void *); prop = _find_property(prop_name, obj->pclass); if (!prop || !prop->get) continue; prop->get(obj, buffer); count++; } return count; }
//sets an object's properties int awe_set_object_properties_va(AWE_OBJECT *obj, va_list params) { AWE_CLASS_PROPERTY *prop; const char *prop_name; int count = 0; char value[256]; obj->setting_properties = 1; while (1) { //get property name prop_name = va_arg(params, const char *); if (!prop_name) break; //find property; if not found, stop setting properties prop = _find_property(prop_name, obj->pclass); if (!prop) break; //get value from the stack memcpy(value, params, prop->stack_size); params = ((char *)params) + prop->stack_size; //set the property if (!prop->set) continue; prop->set(obj, value); count++; } obj->setting_properties = 0; //notify the object if properties have changed if (count && obj->pclass->vtable->properties_changed) obj->pclass->vtable->properties_changed(obj); //return number of set properties return count; }