⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stafmonitorservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            }            resolveMessage = (varResult->result).asUInt();                                }            }        if (resolveMessage)    {        STAFResultPtr messageResult =                      resolveOp(pInfo, pData, parsedResult, sMessage);                if (messageResult->rc != 0) return messageResult;        fMessage += messageResult->result;    }    else    {        fMessage += parsedResult->optionValue(sMessage);    }        fMessage = STAFHandle::maskPrivateData(fMessage);    if (fMessage.length() > pData->fMaxRecordSize)     {        fMessage = fMessage.subString(0, pData->fMaxRecordSize,                                       STAFString::kChar);        }    STAFMutexSemLock lock(*pData->fMapSem);        STAFString upperCaseMachine =         ((STAFString)(pInfo->machineNickname)).toUpperCase();    //Write message into the log    if (pData->fMap[upperCaseMachine].realMachineName == "")    {        pData->fMap[upperCaseMachine].realMachineName =             pInfo->machineNickname;    }    if (parsedResult->optionTimes(sName))    {        // Get and resolve NAME option        STAFResultPtr res = resolveOp(pInfo, pData, parsedResult, sName);        if (res->rc != kSTAFOk) return res;        STAFString name = res->result;        pData->fMap[upperCaseMachine].nameMap[name.toUpperCase()].message =            fMessage;        // Store the original case of the name the first time the        // named monitor is logged to        if (pData->fMap[upperCaseMachine].nameMap[name.toUpperCase()].            originalCaseName == "")        {            pData->fMap[upperCaseMachine].nameMap[name.toUpperCase()].                originalCaseName = name;        }    }    else    {        pData->fMap[upperCaseMachine].handleMap[pInfo->handle] = fMessage;    }    return STAFResultPtr(new STAFResult(kSTAFOk, STAFString()),                         STAFResultPtr::INIT);}STAFResultPtr handleQuery(STAFServiceRequestLevel30 *pInfo,                           MonitorServiceData *pData){    // Verify the requesting machine/user has at least trust level 2    VALIDATE_TRUST(2, pData->fShortName, "QUERY", pData->fLocalMachineName);    // Parse the request    STAFCommandParseResultPtr parsedResult = pData->fQueryParser->parse(        pInfo->request);    if (parsedResult->rc != kSTAFOk)    {        return STAFResultPtr(new STAFResult(kSTAFInvalidRequestString,                             parsedResult->errorBuffer), STAFResultPtr::INIT);    }           STAFString result = "";    MachineMap::iterator machineIterator;    HandleMap::iterator handleIterator;    NameMap::iterator nameIterator;    // Get and resolve MACHINE option    STAFResultPtr res = resolveOp(pInfo, pData, parsedResult, sMachine);        if (res->rc != kSTAFOk) return res;        STAFString queryMachine = res->result;    // Create the marshalling context and set its map class definitions    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(pData->fMonitorInfoClass->reference());    // Get a lock    STAFMutexSemLock lock(*pData->fMapSem);    if (parsedResult->optionTimes(sHandle))    {        // Get and resolve HANDLE option        res = resolveOp(pInfo, pData, parsedResult, sHandle);        if (res->rc != kSTAFOk) return res;            STAFString queryHandle = res->result;        STAFError_e errorCode;        if (!queryHandle.isDigits())        {            result = "Entry for handle " + queryHandle + " must be numeric" +                     lineSep;            errorCode = (STAFError_e)kSTAFInvalidValue;            return STAFResultPtr(new STAFResult(errorCode, result),                                 STAFResultPtr::INIT);        }        // Find the entry for the specified machine and handle (if one exists)        if ((machineIterator = pData->fMap.find(queryMachine.toUpperCase())) ==            pData->fMap.end())        {            result = "Entry for machine " + STAFString(queryMachine) +                     " not found" + lineSep;            errorCode = (STAFError_e)kSTAFDoesNotExist;            return STAFResultPtr(new STAFResult(errorCode, result),                                 STAFResultPtr::INIT);        }        else if ((handleIterator =              machineIterator->second.handleMap.find(queryHandle.asUInt())) ==              machineIterator->second.handleMap.end())        {            result = "Entry for handle " + queryHandle + " not found" + lineSep;            errorCode = (STAFError_e)kSTAFDoesNotExist;            return STAFResultPtr(new STAFResult(errorCode, result),                                 STAFResultPtr::INIT);        }        else        {            // Create a map object to contain the query monitor information            STAFObjectPtr monitorInfoMap =                 pData->fMonitorInfoClass->createInstance();            monitorInfoMap->put("timestamp",                                handleIterator->second.subString(0, 17));            monitorInfoMap->put("message",                                handleIterator->second.subString(18));            mc->setRootObject(monitorInfoMap);        }    }    else if (parsedResult->optionTimes(sName))    {        // Get and resolve NAME option        res = resolveOp(pInfo, pData, parsedResult, sName);        if (res->rc != kSTAFOk) return res;        STAFString queryName = res->result;        STAFError_e errorCode;        // Find the entry for the specified machine and name (if one exists)        if ((machineIterator = pData->fMap.find(queryMachine.toUpperCase())) ==            pData->fMap.end())        {            result = "Entry for machine " + STAFString(queryMachine) +                     " not found" + lineSep;            errorCode = (STAFError_e)kSTAFDoesNotExist;            return STAFResultPtr(new STAFResult(errorCode, result),                                 STAFResultPtr::INIT);        }        else if ((nameIterator =               machineIterator->second.nameMap.find(queryName.toUpperCase())) ==               machineIterator->second.nameMap.end())        {            result = "Entry for name " + queryName + " not found" + lineSep;            errorCode = (STAFError_e)kSTAFDoesNotExist;            return STAFResultPtr(new STAFResult(errorCode, result),                                 STAFResultPtr::INIT);        }        else        {            // Create a map object to contain the query monitor information            STAFObjectPtr monitorInfoMap =                 pData->fMonitorInfoClass->createInstance();            monitorInfoMap->put("timestamp",                                nameIterator->second.message.subString(0, 17));            monitorInfoMap->put("message",                                nameIterator->second.message.subString(18));            mc->setRootObject(monitorInfoMap);        }    }    return STAFResultPtr(new STAFResult(kSTAFOk, mc->marshall()),                          STAFResultPtr::INIT);}STAFResultPtr handleList(STAFServiceRequestLevel30 *pInfo,                          MonitorServiceData *pData){    // Verify the requesting machine/user has at least trust level 2    VALIDATE_TRUST(2, pData->fShortName, "LIST", pData->fLocalMachineName);    // Parse the request    STAFCommandParseResultPtr parsedResult =        pData->fListParser->parse(pInfo->request);        if (parsedResult->rc != kSTAFOk)    {        return STAFResultPtr(new STAFResult(kSTAFInvalidRequestString,                             parsedResult->errorBuffer), STAFResultPtr::INIT);    }                    // Create the marshalling context    STAFObjectPtr mc = STAFObject::createMarshallingContext();    STAFString result = "";    // Generate output based on the option(s) specified    if (parsedResult->optionTimes(sSettings))    {        // Set the map class definitions for the marshalling context        mc->setMapClassDefinition(pData->fSettingsClass->reference());        // Create a map object for the marshalled map of monitor settings        STAFObjectPtr settingsMap = pData->fSettingsClass->createInstance();        settingsMap->put("maxRecordSize", STAFString(pData->fMaxRecordSize));        if (pData->fResolveMessage != 0)            settingsMap->put("resolveMessage", "Enabled");        else            settingsMap->put("resolveMessage", "Disabled");        if (pData->fEnableResolveMessageVar != 0)            settingsMap->put("resolveMessageVar", "Enabled");        else            settingsMap->put("resolveMessageVar", "Disabled");        mc->setRootObject(settingsMap);    }    else if (parsedResult->optionTimes(sMachines) != 0)    {        // Create a empty list object for the marshalled list of machines        STAFObjectPtr machineList = STAFObject::createList();        STAFMutexSemLock lock(*pData->fMapSem);        MachineMap::iterator machineIterator;        // Test to see if anything has been logged        if (pData->fMap.begin() == pData->fMap.end())        {            result = "No monitor data found." + lineSep;            return STAFResultPtr(new STAFResult(kSTAFDoesNotExist, result),                                 STAFResultPtr::INIT);        }        else        {            // Write all the machine names to result            for(machineIterator = pData->fMap.begin();                 machineIterator != pData->fMap.end(); ++machineIterator)            {                machineList->append(machineIterator->second.realMachineName);            }                   }        mc->setRootObject(machineList);    }    else if (parsedResult->optionTimes(sMachine) != 0)    {        MachineMap::iterator machineIterator;        STAFMutexSemLock lock(*pData->fMapSem);        STAFString listMachine = parsedResult->optionValue(sMachine);        if(listMachine.count(sLeftCurlyBrace) > 0)        {            STAFResultPtr machineResult = resolveOp(pInfo, pData, parsedResult,                                                    "Machine");            listMachine = machineResult->result;        }        if (parsedResult->optionTimes(sNames))        {            // Set the map class definitions for the marshalling context            mc->setMapClassDefinition(pData->fNameInfoClass->reference());            // Create a empty list object for the marshalled list of names            // for the specified machine            STAFObjectPtr nameList = STAFObject::createList();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -