📄 elementconformstoprofile.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================///////////////////////////////////////////////////////////////////////////////// Interop Provider - This provider services those classes from the// DMTF Interop schema in an implementation compliant with the SMI-S v1.1// Server Profile//// Please see PG_ServerProfile20.mof in the directory// $(PEGASUS_ROOT)/Schemas/Pegasus/InterOp/VER20 for retails regarding the// classes supported by this control provider.//// Interop forces all creates to the PEGASUS_NAMESPACENAME_INTEROP // namespace. There is a test on each operation that returns // the Invalid Class CIMDError// This is a control provider and as such uses the Tracer functions// for data and function traces. Since we do not expect high volume// use we added a number of traces to help diagnostics.///////////////////////////////////////////////////////////////////////////////#include "InteropProvider.h"#include "InteropProviderUtils.h"#include "InteropConstants.h"PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN//// Given the two references in the association, this function creates an// instance of the PG_ElementConformsToProfile class.//CIMInstance buildElementConformsToProfile( const CIMObjectPath & currentProfile, const CIMObjectPath & currentElement, const CIMClass & elementConformsClass){ Array<CIMName> elementPropArray; elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD); elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT); CIMPropertyList elementPropList(elementPropArray); CIMInstance tmpInstance = elementConformsClass.buildInstance(false, false, elementPropList); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD, currentProfile); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT, currentElement); tmpInstance.setPath(tmpInstance.buildPath( elementConformsClass)); return tmpInstance;}//// Enumerates all of the ElementConformsToProfile association instances.//Array<CIMInstance> InteropProvider::enumElementConformsToProfileInstances( const OperationContext & opContext, const CIMNamespaceName & opNamespace){ CIMClass elementConformsClass = repository->getClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE, false, true, false); AutoMutex holder(interopMut); Array<CIMInstance> instances; verifyCachedInfo(); // Loop through the cached profile Id's and related info about its // conforming elements. for(Uint32 i = 0, n = profileIds.size(); i < n; ++i) { String & profileId = profileIds[i]; Array<CIMName> & elementList = conformingElements[i]; Array<CIMNamespaceName> & namespaceList = elementNamespaces[i]; Array<CIMObjectPath> conformingElementPaths; for(Uint32 j = 0, m = elementList.size(); j < m; ++j) { CIMName & currentElement = elementList[j]; CIMNamespaceName & currentNamespace = namespaceList[j]; if(opNamespace == PEGASUS_NAMESPACENAME_INTEROP || opNamespace == currentNamespace) { String currentElementStr(currentElement.getString()); if(currentElementStr.find(PEGASUS_DYNAMIC) == 0) { // If the provider profile registration did not provide a // list of conforming elements (presumably because there is // no such definite list), then the provider is required // to provide instances of ElementConformsToProfile in the // vendor namespace, so we do not generate instances. if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP) { continue; } CIMName subclassName( currentElementStr.subString(PEGASUS_DYNAMIC_LEN)); Array<CIMInstance> elementConformsInstances = cimomHandle.enumerateInstances(opContext, currentNamespace, subclassName, true, false, false, true, CIMPropertyList()); // Retrieve the Conforming Element for(Uint32 k = 0, x = elementConformsInstances.size(); k < x; ++k) { CIMInstance & currentInstance = elementConformsInstances[k]; // Make sure that the current instance points to the // current profile ID. CIMObjectPath profilePath = getRequiredValue<CIMObjectPath>( elementConformsInstances[k], ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD); const Array<CIMKeyBinding> & keys = profilePath.getKeyBindings(); if(keys.size() != 1) continue; if(keys.size() == 1 && keys[0].getValue() == profileId) { conformingElementPaths.append( getRequiredValue<CIMObjectPath>( currentInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT)); } } } else { // All of the instances of the current element in the // corresponding namespace conform to the current profile. Array<CIMObjectPath> paths = cimomHandle.enumerateInstanceNames(opContext, currentNamespace, currentElement); // Set the namespace in the paths just in case for(Uint32 k = 0, x = paths.size(); k < x; ++k) { CIMObjectPath & curPath = paths[k]; curPath.setNameSpace(currentNamespace); curPath.setHost(hostName); } conformingElementPaths.appendArray(paths); } } } // Create the object path for the RegisteredProfile using the given // profileId. CIMObjectPath profilePath = buildDependencyReference( hostName, profileIds[i], PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE); // Build all of the ElementConformsToProfile instances for the current // profile. for(Uint32 k = 0, x = conformingElementPaths.size(); k < x; ++k) { instances.append(buildElementConformsToProfile(profilePath, conformingElementPaths[k], elementConformsClass)); } } // Now add the default instance: the association between the Server Profile // and the ObjectManager (if we're in the Interop namespace) if(opNamespace == PEGASUS_NAMESPACENAME_INTEROP) { // Build up the Object Path for the server profile CIMObjectPath serverProfile = buildDependencyReference(hostName, buildProfileInstanceId(SNIA_NAME, "Server", SNIA_VER_110), PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE); // Retrieve the Object Manager instance CIMInstance objManager = getObjectManagerInstance(); instances.append(buildElementConformsToProfile(serverProfile, objManager.getPath(), elementConformsClass)); } return instances;}typedef Array<String> StringArray;void InteropProvider::verifyCachedInfo(){ // TBD: May need an algorithm to determine whether or not the information // cached by the Interop Provider is out of date in some way. Until that // can be created, then providers that are dynamically registered after // the Server profile has already been traversed may not be properly // reflected. Although this is a shortcoming, the current users of this // functionality do not generally use dynamic registration as part of their // installation procedures.}//// Function that determines in which namespaces a provider supports a given// class. This information is needed to properly implement the// ElementConformsToProfile association.//Array<String> findProviderNamespacesForElement( const String & moduleName, const String & providerName, const CIMName & elementClass, CIMRepository * repository, Array<CIMInstance> & providerCapabilitiesInstances){ Array<CIMInstance> capabilities; if(providerCapabilitiesInstances.size() == 0) { Array<CIMName> propList; propList.append(PROVIDERCAPABILITIES_PROPERTY_PROVIDERMODULENAME); propList.append(PROVIDERCAPABILITIES_PROPERTY_PROVIDERNAME); propList.append(PROVIDERCAPABILITIES_PROPERTY_NAMESPACES); propList.append(PROVIDERCAPABILITIES_PROPERTY_CLASSNAME); capabilities = repository->enumerateInstancesForClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PROVIDERCAPABILITIES, true, false, false); } else { capabilities = providerCapabilitiesInstances; } for(Uint32 i = 0, n = capabilities.size(); i < n; ++i) { CIMInstance & currentCapabilities = capabilities[i]; Uint32 propIndex = currentCapabilities.findProperty( PROVIDERCAPABILITIES_PROPERTY_PROVIDERMODULENAME); PEGASUS_ASSERT(propIndex != PEG_NOT_FOUND); String currentName; currentCapabilities.getProperty(propIndex).getValue().get( currentName); if(currentName == moduleName) { propIndex = currentCapabilities.findProperty( PROVIDERCAPABILITIES_PROPERTY_PROVIDERNAME); PEGASUS_ASSERT(propIndex != PEG_NOT_FOUND); currentCapabilities.getProperty(propIndex).getValue().get( currentName); if(currentName == providerName) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -