in src/InstrumentationEngine.Lib/ConfigurationLoader.cpp [88:196]
HRESULT CConfigurationLoaderHelper::ProcessInstrumentationMethodNode(_In_ BSTR bstrInstrumentationMethodFolder, _In_ CXmlNode* pNode, _In_ std::vector<CInstrumentationMethod*>& methods)
{
HRESULT hr = S_OK;
IfNullRetPointer(pNode);
CComPtr<CXmlNode> pChildNode;
IfFailRet(pNode->GetChildNode(&pChildNode));
tstring name;
tstring description;
tstring module;
tstring classGuid;
DWORD dwPriority = (DWORD)-1;
while (pChildNode != nullptr)
{
tstring currNodeName;
IfFailRet(pChildNode->GetName(currNodeName));
if (wcscmp(currNodeName.c_str(), _T("Name")) == 0)
{
CComPtr<CXmlNode> pChildValue;
IfFailRet(pChildNode->GetChildNode(&pChildValue));
if (pChildValue != nullptr)
{
IfFailRet(pChildValue->GetStringValue(name));
}
}
else if (wcscmp(currNodeName.c_str(), _T("Description")) == 0)
{
CComPtr<CXmlNode> pChildValue;
IfFailRet(pChildNode->GetChildNode(&pChildValue));
if (pChildValue != nullptr)
{
pChildValue->GetStringValue(description);
}
}
else if (wcscmp(currNodeName.c_str(), _T("Module")) == 0)
{
CComPtr<CXmlNode> pChildValue;
IfFailRet(pChildNode->GetChildNode(&pChildValue));
if (pChildValue != nullptr)
{
IfFailRet(pChildValue->GetStringValue(module));
}
}
else if (wcscmp(currNodeName.c_str(), _T("ClassGuid")) == 0)
{
CComPtr<CXmlNode> pChildValue;
IfFailRet(pChildNode->GetChildNode(&pChildValue));
if (pChildValue != nullptr)
{
IfFailRet(pChildValue->GetStringValue(classGuid));
}
}
else if (wcscmp(currNodeName.c_str(), _T("Priority")) == 0)
{
CComPtr<CXmlNode> pChildValue;
pChildNode->GetChildNode(&pChildValue);
if (pChildValue != nullptr)
{
tstring strNodeValue;
IfFailRet(pChildValue->GetStringValue(strNodeValue));
dwPriority = (DWORD)(_wtoi(strNodeValue.c_str()));
if (errno == ERANGE)
{
CLogging::LogError(_T("Invalid configuration. Priority should be a positive number"));
return E_FAIL;
}
}
}
else
{
CLogging::LogError(_T("Invalid configuration. Unknown Element"));
return E_FAIL;
}
CXmlNode* next = pChildNode->Next();
pChildNode.Release();
pChildNode.Attach(next);
}
if ((name.length() == 0) ||
(description.length() == 0) ||
(module.length() == 0) ||
(classGuid.length() == 0))
{
CLogging::LogError(_T("Invalid configuration. Missing child element"));
return E_FAIL;
}
GUID guidClassId;
CComBSTR bstrClassGuid = classGuid.c_str();
hr = IIDFromString(bstrClassGuid, (LPCLSID)&guidClassId);
if (FAILED(hr))
{
CLogging::LogError(_T("CInstrumentationMethod::Initialize - Bad classid for instrumentation method"));
return E_INVALIDARG;
}
CInstrumentationMethod* method = new CInstrumentationMethod(bstrInstrumentationMethodFolder, name.c_str(), description.c_str(), module.c_str(), guidClassId, dwPriority);
methods.push_back(method);
return S_OK;
}