📄 server.cpp
字号:
//// Get the instance of the CIM_ObjectManager class, creating the instance if it// does not already exist in the repository.//// @param includeQualifiers Boolean// @param includeClassOrigin Boolean// @param propertylist CIMPropertyList//// @return CIMInstance with a single built instance of the class//// @exception repository instances if exception to enumerateInstances// for this class.//CIMInstance InteropProvider::getObjectManagerInstance(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::getObjectManagerInstance"); // Try to get the instance from the repository. CIMInstance instance; bool found = false; Array<CIMInstance> tmpInstances = repository->enumerateInstancesForClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_OBJECTMANAGER, false, false, false, CIMPropertyList()); Uint32 numInstances = tmpInstances.size(); if(numInstances == 1) { instance = tmpInstances[0]; } PEGASUS_ASSERT(numInstances <= 1); if(instance.isUninitialized()) { // // No instance in the repository. Build new instance and save it. // CIMClass omClass; instance = buildInstanceSkeleton(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_OBJECTMANAGER, omClass); // Set the common key properties setCommonKeys(instance); setPropertyValue(instance, OM_PROPERTY_CREATIONCLASSNAME, PEGASUS_CLASSNAME_PG_OBJECTMANAGER.getString()); setPropertyValue(instance, OM_PROPERTY_NAME, String(PEGASUS_INSTANCEID_GLOBAL_PREFIX) + ":" + Guid::getGuid()); setPropertyValue(instance, OM_PROPERTY_ELEMENTNAME, String("Pegasus")); Array<Uint16> operationalStatus; operationalStatus.append(2); setPropertyValue(instance, OM_PROPERTY_OPERATIONALSTATUS, operationalStatus); setPropertyValue(instance, OM_PROPERTY_STARTED, CIMValue(Boolean(true))); // // Description property this object manager instance. // If PEGASUS_CIMOM_DESCRIPTION is non-zero length, use it. // Otherwise build form the components below, as defined in // PegasusVersion.h. String descriptionStatus; String pegasusProductStatus(PEGASUS_PRODUCT_STATUS); if(pegasusProductStatus.size() > 0) descriptionStatus = " " + pegasusProductStatus; String description = (String(PEGASUS_CIMOM_DESCRIPTION).size() != 0) ? String(PEGASUS_CIMOM_DESCRIPTION) : String(PEGASUS_CIMOM_GENERIC_NAME) + " " + String(PEGASUS_PRODUCT_NAME) + " Version " + String(PEGASUS_PRODUCT_VERSION) + descriptionStatus; setPropertyValue(instance, OM_PROPERTY_DESCRIPTION, description); // Property GatherStatisticalData. Initially this is set to false // and can then be modified by a modify instance on the instance. Boolean gatherStatDataFlag = false; setPropertyValue(instance, OM_PROPERTY_GATHERSTATISTICALDATA, gatherStatDataFlag); // Set the statistics property into the Statisticaldata class so that // it can perform statistics gathering if necessary. #ifndef PEGASUS_DISABLE_PERFINST StatisticalData* sd = StatisticalData::current(); sd->setCopyGSD(gatherStatDataFlag); #endif // write instance to the repository CIMObjectPath instancePath = repository->createInstance( PEGASUS_NAMESPACENAME_INTEROP, instance); instance.setPath(instancePath); } CIMObjectPath currentPath = instance.getPath(); currentPath.setHost(hostName); currentPath.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP); instance.setPath(currentPath); PEG_METHOD_EXIT(); return instance;}//// Modify the existing Object Manager instance. Only a single property// modification is allowed, the statistical data setting. Any other change is// rejected with an exception.//void InteropProvider::modifyObjectManagerInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance& modifiedIns, const Boolean includeQualifiers, const CIMPropertyList& propertyList){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::modifyObjectManagerInstance"); // Modification only allowed when Performance staticistics are active#ifndef PEGASUS_DISABLE_PERFINST Uint32 propListSize = propertyList.size(); if(propListSize == 0 && !propertyList.isNull()) return; if(propertyList.size() != 1 || propertyList[0] != OM_PROPERTY_GATHERSTATISTICALDATA) { throw CIMNotSupportedException(String("Only modification of ") + OM_PROPERTY_GATHERSTATISTICALDATA.getString() + " allowed"); } Boolean statisticsFlag; CIMInstance omInstance; // We modify only if this property exists. // could either use the property from modifiedIns or simply replace // value in property from object manager. if (modifiedIns.findProperty(OM_PROPERTY_GATHERSTATISTICALDATA) != PEG_NOT_FOUND) { omInstance = getObjectManagerInstance(); if(omInstance.isUninitialized()) { throw CIMObjectNotFoundException(instanceReference.toString()); } statisticsFlag = getPropertyValue(modifiedIns, OM_PROPERTY_GATHERSTATISTICALDATA, false); // set the changed property into the instance setPropertyValue(omInstance, OM_PROPERTY_GATHERSTATISTICALDATA, statisticsFlag); } else { // if statistics property not in place, simply exit. Nothing to do // not considered an error PEG_METHOD_EXIT(); return; } // Modify the instance on disk try { repository->modifyInstance(instanceReference.getNameSpace(), omInstance, false, propertyList); } catch(const CIMException&) { PEG_METHOD_EXIT(); throw; } catch(const Exception&) { PEG_METHOD_EXIT(); throw; } Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE, "Interop Provider Set Statistics gathering in CIM_ObjectManager: $0", (statisticsFlag? "true" : "false")); StatisticalData* sd = StatisticalData::current(); sd->setCopyGSD(statisticsFlag); PEG_METHOD_EXIT(); return;#else PEG_METHOD_EXIT(); throw CIMNotSupportedException (OM_PROPERTY_GATHERSTATISTICALDATA.getString() + " modify operation not supported by Interop Provider");#endif}//// Get an instance of the PG_ComputerSystem class produced by the// ComputerSystem provider in the root/cimv2 namespace.//// @param includeQualifiers Boolean// @param includeClassOrigin Boolean// @param propertylist CIMPropertyList//// @return CIMInstance of PG_ComputerSystem class.//// @exception ObjectNotFound exception if a ComputerSystem instance cannot// be retrieved.//CIMInstance InteropProvider::getComputerSystemInstance(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::getComputerSystemInstance"); CIMInstance instance; AutoMutex mut(interopMut); Array<CIMInstance> tmpInstances = cimomHandle.enumerateInstances( OperationContext(), PEGASUS_NAMESPACENAME_CIMV2, PEGASUS_CLASSNAME_PG_COMPUTERSYSTEM, true, false, false, false, CIMPropertyList()); Uint32 numInstances = tmpInstances.size(); PEGASUS_ASSERT(numInstances <= 1); if(numInstances > 0) { instance = tmpInstances[0]; CIMObjectPath tmpPath = instance.getPath(); tmpPath.setHost(hostName); tmpPath.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP); instance.setPath(tmpPath); } if(instance.isUninitialized()) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, "Could not find ComputerSystem instance"); } PEG_METHOD_EXIT(); return instance;}//// Returns an instance of the HostedObjectManager association linking the// ObjectManager and ComputerSystem instances managed by this provider.//CIMInstance InteropProvider::getHostedObjectManagerInstance(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::getHostedObjectManagerInstance"); // Try to get the current object. If true then it is already created. CIMInstance instance; bool found = false; CIMObjectPath csPath = getComputerSystemInstance().getPath(); CIMObjectPath omPath = getObjectManagerInstance().getPath(); String csPathString = csPath.toString(); String omPathString = omPath.toString(); CIMClass hostedOMClass = repository->getClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_HOSTEDOBJECTMANAGER, false, true, false); instance = hostedOMClass.buildInstance(false, false, CIMPropertyList()); setPropertyValue(instance, PROPERTY_ANTECEDENT, CIMValue(csPath)); setPropertyValue(instance, PROPERTY_DEPENDENT, CIMValue(omPath)); instance.setPath(instance.buildPath(hostedOMClass)); PEG_METHOD_EXIT(); return instance;}//// Returns an array containing all of the HostedAccessPoint association// instances for this CIMOM. One will be produced for every instance of// CIMXMLCommunicatiomMechanism managed by this provider.//Array<CIMInstance> InteropProvider::enumHostedAccessPointInstances(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::enumHostedAccessPointInstance"); Array<CIMInstance> instances; CIMObjectPath csPath = getComputerSystemInstance().getPath(); Array<CIMInstance> commMechs = enumCIMXMLCommunicationMechanismInstances(); CIMClass hapClass = repository->getClass(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_HOSTEDACCESSPOINT, false, true, false); for(Uint32 i = 0, n = commMechs.size(); i < n; ++i) { CIMInstance & currentCommMech = commMechs[i]; CIMInstance hapInstance = hapClass.buildInstance(false, false, CIMPropertyList()); setPropertyValue(hapInstance, PROPERTY_ANTECEDENT, csPath); setPropertyValue(hapInstance, PROPERTY_DEPENDENT, currentCommMech.getPath()); hapInstance.setPath(hapInstance.buildPath(hapClass)); instances.append(hapInstance); } PEG_METHOD_EXIT(); return instances;}//// Returns an array containing all of the CommMechanismForManager association// instances for this CIMOM. One will be produced for every instance of// CIMXMLCommunicatiomMechanism managed by this provider.//Array<CIMInstance> InteropProvider::enumCommMechanismForManagerInstances(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::enumCommMechanismForManagerInstances"); Array<CIMInstance> commInstances = enumCIMXMLCommunicationMechanismInstances(); CIMInstance instanceObjMgr = getObjectManagerInstance(); CIMObjectPath refObjMgr = instanceObjMgr.getPath(); Array<CIMInstance> assocInstances; CIMClass targetClass; CIMInstance instanceskel = buildInstanceSkeleton( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_COMMMECHANISMFORMANAGER, targetClass); for (Uint32 i = 0, n = commInstances.size(); i < n; ++i) { CIMInstance instance = instanceskel.clone(); setPropertyValue(instance, PROPERTY_ANTECEDENT, refObjMgr); setPropertyValue(instance, PROPERTY_DEPENDENT, commInstances[i].getPath()); instance.setPath(instance.buildPath(targetClass)); assocInstances.append(instance); } PEG_METHOD_EXIT(); return assocInstances;}PEGASUS_NAMESPACE_END// END OF FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -