📄 interopproviderutils.cpp
字号:
const CIMName & propertyName, const Uint16 & value){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::_validateRequiredProperty()"); PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4, "Validate " + propertyName.getString()); Uint32 pos; if ((pos = instance.findProperty (propertyName)) == PEG_NOT_FOUND) { PEG_METHOD_EXIT(); return false; } // // Get the property // CIMConstProperty theProperty = instance.getProperty(pos); CIMValue theValue = theProperty.getValue(); // // ATTN:Required property must have a non-null value // if ((theValue.getType() != CIMTYPE_UINT16) || (theValue.isNull()) ) { PEG_METHOD_EXIT(); return false; } PEG_METHOD_EXIT(); return true;}*///// Same as above, overloaded to check key properties in CIMObjectPath objects// against a string value.//Boolean validateRequiredProperty( const CIMObjectPath & objectPath, const CIMName & propertyName, const String & value){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::_validateRequiedProperty()"); Array<CIMKeyBinding> kbArray = objectPath.getKeyBindings(); Boolean retVal = false; // find the correct key binding for(Uint32 i = 0; i < kbArray.size(); i++) { if(kbArray[i].getName() == propertyName) { retVal = (value == String::EMPTY || value == kbArray[i].getValue()); break; } } PEG_METHOD_EXIT(); return retVal;}//// Verify that this is one of the legal classnames for instance operations and// return an indicator as to which one it is.// @param - Classname// @return - Enum value indicating type// @Exceptions - throws CIMNotSupportedException if invalid class.//TARGET_CLASS translateClassInput(const CIMName& className){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::translateClassInput"); if(className.equal(PEGASUS_CLASSNAME_PG_OBJECTMANAGER)) return PG_OBJECTMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM)) return PG_CIMXMLCOMMUNICATIONMECHANISM; else if(className.equal(PEGASUS_CLASSNAME_PG_NAMESPACEINMANAGER)) return PG_NAMESPACEINMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_COMMMECHANISMFORMANAGER)) return PG_COMMMECHANISMFORMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE)) return PG_REGISTEREDPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_REGISTEREDSUBPROFILE)) return PG_REGISTEREDSUBPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_REFERENCEDPROFILE)) return PG_REFERENCEDPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE)) return PG_ELEMENTCONFORMSTOPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_SUBPROFILEREQUIRESPROFILE)) return PG_SUBPROFILEREQUIRESPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_SOFTWAREIDENTITY)) return PG_SOFTWAREIDENTITY; else if(className.equal(PEGASUS_CLASSNAME_PG_ELEMENTSOFTWAREIDENTITY)) return PG_ELEMENTSOFTWAREIDENTITY; else if(className.equal(PEGASUS_CLASSNAME_PG_INSTALLEDSOFTWAREIDENTITY)) return PG_INSTALLEDSOFTWAREIDENTITY; else if(className.equal(PEGASUS_CLASSNAME_PG_COMPUTERSYSTEM)) return PG_COMPUTERSYSTEM; else if(className.equal(PEGASUS_CLASSNAME_PG_HOSTEDOBJECTMANAGER)) return PG_HOSTEDOBJECTMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_HOSTEDACCESSPOINT)) return PG_HOSTEDACCESSPOINT; // Last entry, reverse test and throw exception if not PG_Namespace // Note: Changed to PG_Namespace for CIM 2.4 else if(!className.equal(PEGASUS_CLASSNAME_PGNAMESPACE)) throw CIMNotSupportedException (className.getString() + " not supported by Interop Provider"); PEG_METHOD_EXIT(); return PG_NAMESPACE;}//// Same as method above, but used specifically for association classes.//TARGET_CLASS translateAssocClassInput(const CIMName & className){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::translateAssocClassInput"); if(className.equal(PEGASUS_CLASSNAME_PG_NAMESPACEINMANAGER)) return PG_NAMESPACEINMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_COMMMECHANISMFORMANAGER)) return PG_COMMMECHANISMFORMANAGER; else if(className.equal(PEGASUS_CLASSNAME_PG_REFERENCEDPROFILE)) return PG_REFERENCEDPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE)) return PG_ELEMENTCONFORMSTOPROFILE; else if(className.equal(PEGASUS_CLASSNAME_PG_ELEMENTSOFTWAREIDENTITY)) return PG_ELEMENTSOFTWAREIDENTITY; // Last entry, reverse test and throw exception if not // PG_SubProfileRequiresProfile else if(!className.equal(PEGASUS_CLASSNAME_PG_SUBPROFILEREQUIRESPROFILE)) { throw CIMNotSupportedException(className.getString() + " not supported by association operations in the Interop Provider"); } PEG_METHOD_EXIT(); return PG_SUBPROFILEREQUIRESPROFILE;}//// Set the value of a property defined by property name in the instance// provided. If the property cannot be found, it simply returns.//// @param instance CIMInstance in which to set property value// @param propertyName CIMName of property in which value will be set.// @param value CIMValue value to set into property//// @return true if property value was set, false if the property was not found//void setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const CIMValue & value){ // ++EMC: AVD - return bool? would be pos != PEG_NOT_FOUND unsigned int pos = instance.findProperty(propertyName); if(pos != PEG_NOT_FOUND) instance.getProperty(pos).setValue(value);}//// Sets the correct values to the common keys defined for all of the classes.// This is SystemCreationClassName and SystemName. Note that if the properties// do not exist, we simply ignore them.//void setCommonKeys(CIMInstance& instance){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::setCommonKeys()"); setPropertyValue(instance, COMMON_PROPERTY_SYSTEMCREATIONCLASSNAME, PEGASUS_CLASSNAME_PG_COMPUTERSYSTEM.getString()); // Add property SystemName setPropertyValue(instance, COMMON_PROPERTY_SYSTEMNAME, System::getFullyQualifiedHostName()); PEG_METHOD_EXIT();}//// Retrieves the key binding given by the keyName parameter from the supplied// object path.//String getKeyValue(const CIMObjectPath& instanceName, const CIMName& keyName){ Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); // find the correct key binding for(Uint32 i = 0, n = kbArray.size(); i < n; ++i) { if (kbArray[i].getName() == keyName) return kbArray[i].getValue(); } throw CIMInvalidParameterException("Key property not found: " + keyName.getString());}//// Retrieves the key binding given by the keyName parameter from the supplied// instance.//String getKeyValue(const CIMInstance& instance, const CIMName& keyName){ Uint32 pos; CIMValue propertyValue; pos = instance.findProperty(keyName); if(pos == PEG_NOT_FOUND) throw CIMPropertyNotFoundException(keyName.getString()); propertyValue = instance.getProperty(pos).getValue(); if(propertyValue.getType() != CIMTYPE_STRING) { throw CIMInvalidParameterException("Invalid type for property: " + keyName.getString()); } String name; propertyValue.get(name); return name;}//// The following method is used to translate a string based on the// Value/ValueMap qualifiers of a property. Note that the method is written// in such a way that the translation could be done in either direction// (from Value value to ValueMap value or vice versa) or with another pair// of qualifiers with a relationship similar to the Value/ValueMap pair.//String translateValue( const String & value, const CIMName & propName, const CIMName & sourceQualifier, const CIMName & targetQualifier, const CIMClass & classDef){ String mappedValue; Uint32 index = classDef.findProperty(propName); if(index != PEG_NOT_FOUND) { CIMConstProperty prop = classDef.getProperty(index); index = prop.findQualifier(sourceQualifier); if(index != PEG_NOT_FOUND) { Array<String> sourceQualValues; prop.getQualifier(index).getValue().get(sourceQualValues); for(Uint32 i = 0, n = sourceQualValues.size(); i < n; ++i) { // If we have a match in the Source qualifier, then get the // related string from the Target qualifier if(sourceQualValues[i] == value) { index = prop.findQualifier(targetQualifier); if(index != PEG_NOT_FOUND) { Array<String> targetQualValues; prop.getQualifier(index).getValue().get( targetQualValues); mappedValue = targetQualValues[i]; } break; } } } } return mappedValue;}//// Same as above, but converts an integral value into a string first so that// it can be found when searching the Values qualifier (or some similar// qualifier).//String translateValue(Uint16 value, const CIMName & propName, const CIMName & sourceQualifier, const CIMName & targetQualifier, const CIMClass & classDef){ return translateValue(CIMValue(value).toString(), propName, sourceQualifier, targetQualifier, classDef);}//// helper function for building a reference ObjectPath for an instance// of CIM_Dependency.//CIMObjectPath buildDependencyReference( const String & hostName, const String & instanceId, const CIMName & instanceClass){ Array<CIMKeyBinding> instanceKeys; instanceKeys.append(CIMKeyBinding( COMMON_PROPERTY_INSTANCEID, instanceId,CIMKeyBinding::STRING)); return CIMObjectPath(hostName, PEGASUS_NAMESPACENAME_INTEROP, instanceClass, instanceKeys);}//// helper function for building an instance of CIM_Dependency given// the antecedent and dependent references and the concrete subclass for which// the instance will be created.//CIMInstance buildDependencyInstanceFromPaths( const CIMObjectPath & antecedent, const CIMObjectPath & dependent, const CIMClass & dependencyClass){ CIMInstance dependencyInst = dependencyClass.buildInstance(false, false, CIMPropertyList()); setPropertyValue(dependencyInst, PROPERTY_ANTECEDENT, CIMValue(antecedent)); setPropertyValue(dependencyInst, PROPERTY_DEPENDENT, CIMValue(dependent)); dependencyInst.setPath(dependencyInst.buildPath(dependencyClass)); return dependencyInst;}//// Helper function that constructs an the InstanceId property out of its// constituent pieces.//String buildProfileInstanceId(const String & organization, const String & name, const String & version){ return organization + "+" + name + "+" + version;}PEGASUS_NAMESPACE_END// END_OF_FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -