📄 wmicollector.cpp
字号:
{ if (WBEM_S_NO_MORE_DATA == hr) { break; } Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - name [%S]", bsName); bFound = true; CMyString sMethodName; sMethodName = bsName; // TODO: investigate propigation in terms of Methods. Is this applicable? Without a flavor, // where would this come from? bool bPropagated = false; //(lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false; method = WMICollector::getMethod(pClass, bsName, inParameters, outParameters, includeClassOrigin, includeQualifiers, bPropagated); try { container.addMethod(method); } catch( AlreadyExistsException& e ) { // ignore this Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - Method %s is already defined", (LPCTSTR)sMethodName); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - %s", e.getMessage()); } catch( Exception & e ) { // ignore this Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - Ignoring AddedReferenceToClass. %s", e.getMessage()); } catch(... ) { throw CIMException(CIM_ERR_FAILED, "[getAllProperties] general 1"); } bsName.Empty(); if (inParameters) inParameters.Release(); if (outParameters) outParameters.Release(); sMessage = "NextMethod()"; hr = pClass->NextMethod(0, &bsName, &inParameters, &outParameters); } pClass->EndMethodEnumeration(); if (inParameters) inParameters.Release(); if (outParameters) outParameters.Release(); if (FAILED(hr)) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - %s result is %x", sMessage.getCString(), hr); throw CIMException(CIM_ERR_FAILED, "[getAllMethods] general 2"); } PEG_METHOD_EXIT(); return bFound;}/////////////////////////////////////////////////////////////////////////////// getClassQualifiers - retrieves the// class qualifier definitions for a// class or instance and adds// them to the CIMClass or CIMInstance///////////////////////////////////////////////////////////////////////////////template<class CONTAINER>void getClassQualifiers(IWbemClassObject *pClass, CONTAINER & container){ HRESULT hr; String sMessage; CComPtr<IWbemQualifierSet> pQualifiers; CComBSTR bsName = NULL; // of the qualifier CComVariant vValue; // of the qualifier long lFlavor; // of the qualifier bool bPropagated; // true if propated from a superclass CIMQualifier qualifier; PEG_METHOD_ENTER(TRC_WMIPROVIDER,"getClassQualifiers()"); // get the qualifiers enumerator hr = pClass->GetQualifierSet(&pQualifiers); sMessage = "GetQualifier()"; if (SUCCEEDED(hr)) { hr = pQualifiers->BeginEnumeration(0); sMessage = "BeginEnumeration()"; } if (SUCCEEDED(hr)) { bsName.Empty(); vValue.Clear(); sMessage = "Next()"; hr = pQualifiers->Next(0, &bsName, &vValue, &lFlavor); } // process each qualifier while (SUCCEEDED(hr)) { if (WBEM_S_NO_MORE_DATA == hr) { break; } bPropagated = (lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false; qualifier = CIMQualifier(WMIString(bsName), WMIValue(vValue), WMIFlavor(lFlavor), bPropagated); bsName.Empty(); vValue.Clear(); try { container.addQualifier(qualifier); } catch (...) { throw CIMException(CIM_ERR_FAILED, "[getClassQualifiers] general 1"); } bsName.Empty(); vValue.Clear(); hr = pQualifiers->Next(0, &bsName, &vValue, &lFlavor); } pQualifiers->EndEnumeration(); bsName.Empty(); vValue.Clear(); if (FAILED(hr)) { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "getClassQualifiers() - %s result is %x", sMessage.getCString(), hr); throw CIMException(CIM_ERR_FAILED); } PEG_METHOD_EXIT();}////////////////////////////////////////////////////////////////////////////// WMICollector::getCIMObject - set up a getCIMObject structure///////////////////////////////////////////////////////////////////////////////bool WMICollector::getCIMObject(IWbemClassObject *pObject, CIMObject & cimObj, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList, Boolean getKeyProperties){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMObject()"); // first get the qualifiers if wanted if (includeQualifiers) { getClassQualifiers(pObject, cimObj); } // then the properties getObjectProperties(pObject, cimObj, localOnly, includeQualifiers, includeClassOrigin, propertyList, getKeyProperties); PEG_METHOD_EXIT(); return true;}////////////////////////////////////////////////////////////////////////////// WMICollector::getCIMInstance - set up a CIMInstance structure///////////////////////////////////////////////////////////////////////////////bool WMICollector::getCIMInstance(IWbemClassObject *pObject, CIMInstance & cimInst, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList, Boolean getKeyProperties){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMInstance()"); CIMObject cimObj = cimInst; getCIMObject(pObject, cimObj, localOnly, includeQualifiers, includeClassOrigin, propertyList, getKeyProperties); CIMInstance newInstance(cimObj); cimInst = newInstance; PEG_METHOD_EXIT(); return true;}/////////////////////////////////////////////////////////////////////////////// WMICollector::getCIMClass - set up a // CIMClass structure///////////////////////////////////////////////////////////////////////////////bool WMICollector::getCIMClass(IWbemClassObject *pObject, CIMClass & cimClass, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMClass()"); CIMObject cimObj = cimClass; getCIMObject(pObject, cimObj, localOnly, includeQualifiers, includeClassOrigin, propertyList); CIMClass newClass(cimObj); cimClass = newClass; // Get methods for classes only getClassMethods(pObject, cimClass, localOnly, includeQualifiers, includeClassOrigin); PEG_METHOD_EXIT(); return true;}/////////////////////////////////////////////////////////////////////////////// WMICollector::getClassName - return the value of the __CLASS// property of pObject ///////////////////////////////////////////////////////////////////////////////String WMICollector::getClassName(IWbemClassObject *pObject){ CComBSTR bsClass = "__CLASS"; return getStringProperty(pObject, bsClass);}/////////////////////////////////////////////////////////////////////////////// WMICollector::getRelativePath - return the value of the __RELPATH// property of pClass///////////////////////////////////////////////////////////////////////////////String WMICollector::getRelativePath(IWbemClassObject *pObject){ CComBSTR bsRelPath = "__RELPATH"; return getStringProperty(pObject, bsRelPath);}/////////////////////////////////////////////////////////////////////////////// WMICollector::getSuperClass - return the value of the __SUPERCLASS// property of pClass///////////////////////////////////////////////////////////////////////////////String WMICollector::getSuperClass(IWbemClassObject *pClass){ CComBSTR bsSuperClass = "__SUPERCLASS"; return getStringProperty(pClass, bsSuperClass);}/////////////////////////////////////////////////////////////////////////////// WMICollector::isInstance - returns true if pObject represents a// WMI instance - false if it is a class///////////////////////////////////////////////////////////////////////////////bool WMICollector::isInstance(IWbemClassObject *pObject){ String sClass = getClassName(pObject); String sRelPath = getRelativePath(pObject); return (!String::equal(sClass, sRelPath));}/////////////////////////////////////////////////////////////////////////////// WMICollector::getStringProperty - helper function to retrieve specific// string properties from a class or instance object ///////////////////////////////////////////////////////////////////////////////String WMICollector::getStringProperty(IWbemClassObject *pObject, const CComBSTR &bsPropertyName){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getStringProperty()"); HRESULT hr; CComVariant vValue; CComBSTR bs; CMyString s = ""; CMyString name; name = bsPropertyName; hr = pObject->Get(bsPropertyName, 0, &vValue, NULL, NULL); if (SUCCEEDED(hr)) { if (VT_NULL != vValue.vt) { // there is a value... if not we will return an empty string... bs = vValue.bstrVal; if (0 != bs.Length()) { s = bs; } } Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMICollector::getStringProperty() - Value for %s is %s", (LPCTSTR)name, (LPCTSTR)s); } else { Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMICollector::getStringProperty() - get result for %s is %x", (LPCTSTR)name, hr); } PEG_METHOD_EXIT(); if (VT_NULL == vValue.vt) { vValue.Clear(); return String::EMPTY; } else { vValue.Clear(); return String((LPCTSTR)s); }}/////////////////////////////////////////////////////////////////////////////// WMICollector::getObjectProperties - retrieves the // object property definitions and values, if any,// and adds them to the CIMObject instance///////////////////////////////////////////////////////////////////////////////bool WMICollector::getObjectProperties(IWbemClassObject *pObject, CIMObject & cimObj, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList, Boolean bGetKeyProperties){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getObjectProperties()"); long lFlags = (localOnly) ? WBEM_FLAG_LOCAL_ONLY : WBEM_FLAG_NONSYSTEM_ONLY; if (propertyList.isNull()) { // we want all the properties... getAllProperties(pObject, lFlags, includeQualifiers, includeClassOrigin, cimObj); } else if (0 != propertyList.size()) { // just get the ones requested getProperties(pObject, localOnly, includeQualifiers, includeClassOrigin, propertyList, cimObj); } // else we have an empty list and don't want any // if being called from getInstance, need to be sure that // the key properties are retrieved... if (bGetKeyProperties) { getAllProperties(pObject, WBEM_FLAG_KEYS_ONLY, includeQualifiers, includeClassOrigin, cimObj); } PEG_METHOD_EXIT(); return true;}/////////////////////////////////////////////////////////////////////////////// WMICollector::getProperty// create a CIMProperty object from// WMI data ///////////////////////////////////////////////////////////////////////////////CIMProperty WMICollector::getProperty(IWbemClassObject *pClass, const CComBSTR &bsName, const CComVariant &vValue, CIMTYPE type, Boolean includeClassOrigin, Boolean includeQualifiers, Boolean bPropagated){ PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getProperty()"); HRESULT hr = S_OK; String sMessage; CIMProperty property;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -