///////////////////////////////////////////////////////////////////////////// // WMIClassProvider::modifyClass // // /////////////////////////////////////////////////////////////////////////// void WMIClassProvider::modifyClass(const String& nameSpace, const String& userName, const String& password, const CIMClass& modifiedClass) { PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WMIClassProvider::modifyClass()"); setup(nameSpace, userName, password); if (!m_bInitialized) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::modifyClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception", m_bInitialized); throw CIMException(CIM_ERR_FAILED); } // check if class does exist if (!classAlreadyExists(modifiedClass.getClassName().getString())) { throw CIMException(CIM_ERR_NOT_FOUND); } // check if superclass does exist if (!classAlreadyExists(modifiedClass.getSuperClassName().getString())) { // superclass doesn't exist throw CIMException(CIM_ERR_INVALID_SUPERCLASS); } // // By Jair // // If the class already has a superclass and it isn't explicitly // defined in the <modifiedClass> definition, we must set it // before changing the control to the createClass method. This way // we don't change the Class definition, as specified in DSP0200. // CIMClass updatedClass = modifiedClass; if ((updatedClass.getSuperClassName().getString()).size() == 0) { // set the superclass CComPtr<IWbemClassObject> pClass; if (!(_collector->getObject(&pClass, updatedClass.getClassName().getString()))) { if (pClass) pClass.Release(); throw CIMException(CIM_ERR_NOT_FOUND); } String superClass = _collector->getSuperClass(pClass); if (0 != superClass.size()) { CIMName superclassName = superClass; updatedClass.setSuperClassName(superclassName); } if (pClass) pClass.Release(); } //update the class using createClass createClass(nameSpace, userName, password, updatedClass, true); PEG_METHOD_EXIT(); return; }
///////////////////////////////////////////////////////////////////////////// // WMIClassProvider::getClass // /// virtual class CIMClass. From the operations class // /////////////////////////////////////////////////////////////////////////// CIMClass WMIClassProvider::getClass( const String& nameSpace, const String& userName, const String& password, const String& className, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList) { PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIClassProvider::getClass()"); CComPtr<IWbemClassObject> pClass; setup(nameSpace,userName,password); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getClass - localOnly %x, includeQualifiers %x, includeClassOrigin %x", localOnly, includeQualifiers, includeClassOrigin); if (!m_bInitialized) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::getClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception", m_bInitialized); throw CIMException(CIM_ERR_FAILED); } try { if (!(_collector->getObject(&pClass, className))) { if (pClass) pClass.Release(); throw CIMException(CIM_ERR_NOT_FOUND); } else if (_collector->isInstance(pClass)) { if (pClass) pClass.Release(); throw CIMException(CIM_ERR_INVALID_PARAMETER); } } catch (CIMException &e) { if (pClass) pClass.Release(); switch(e.getCode()) { case CIM_ERR_INVALID_CLASS: throw CIMException(CIM_ERR_NOT_FOUND); break; default: throw; } } String superClass = _collector->getSuperClass(pClass); CIMName objName = className; CIMClass cimClass = CIMClass(objName); if (0 != superClass.size()) { CIMName superclassName = superClass; cimClass.setSuperClassName(superclassName); } if (!(_collector->getCIMClass(pClass, cimClass, localOnly, includeQualifiers, includeClassOrigin, propertyList))) { throw CIMException(CIM_ERR_NOT_FOUND); } if (pClass) pClass.Release(); PEG_METHOD_EXIT(); return cimClass; }
///////////////////////////////////////////////////////////////////////////// // WMIClassProvider::enumerateClasses // // /////////////////////////////////////////////////////////////////////////// Array<CIMClass> WMIClassProvider::enumerateClasses( const String& nameSpace, const String& userName, const String& password, const String& className, Boolean deepInheritance , Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin) { PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIClassProvider::enumerateClasses()"); HRESULT hr; long lCount = 0; DWORD dwReturned; CComPtr<IEnumWbemClassObject> pClassEnum; CComPtr<IWbemClassObject> pClass; Array<CIMClass> cimClasses; setup(nameSpace,userName,password); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "enumerateClasses - deepInheritance %x, localOnly %x, includeQualifiers %x, includeClassOrigin %x", deepInheritance, localOnly, includeQualifiers, includeClassOrigin); if (!m_bInitialized) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::enumerateClasses - m_bInitilized= %x, throw CIM_ERR_FAILED exception", m_bInitialized); throw CIMException(CIM_ERR_FAILED); } if (!(_collector->getClassEnum(&pClassEnum, className, deepInheritance))) { if (pClassEnum) pClassEnum.Release(); throw CIMException(CIM_ERR_FAILED); } // set proxy security on pClassEnum bool bSecurity = _collector->setProxySecurity(pClassEnum); // //TODO: What happens if bSecurity is false // // get the classes and append them to the array hr = pClassEnum->Next(WBEM_INFINITE, 1, &pClass, &dwReturned); while (SUCCEEDED(hr) && (1 == dwReturned)) { String className = _collector->getClassName(pClass); String superClass = _collector->getSuperClass(pClass); CIMName objName = className; CIMClass tempClass = CIMClass(objName); if (0 != superClass.size()) { CIMName superclassName = superClass; tempClass.setSuperClassName(superclassName); } if (_collector->getCIMClass(pClass, tempClass, localOnly, includeQualifiers, includeClassOrigin)) { lCount++; cimClasses.append(tempClass); } if (pClass) pClass.Release(); hr = pClassEnum->Next(WBEM_INFINITE, 1, &pClass, &dwReturned); } if (pClassEnum) pClassEnum.Release(); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::enumerateClasses() - Class count is %d", lCount); if (lCount == 0) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::enumerateClasses() - no classes found, hResult value is %x", hr); } PEG_METHOD_EXIT(); return cimClasses; }