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

📄 stafmiscservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/#include "STAF.h"#include "STAFProc.h"#include "STAFProcUtil.h"#include "STAFUtil.h"#include "STAFServiceManager.h"#include "STAFMiscService.h"#include "STAFThreadManager.h"#include "STAFConnectionManager.h"#include "STAFProcessService.h"// VERSION// WHOAMI// WHOAREYOU// LIST INTERFACES | SETTINGS | ENDPOINTCACHE// QUERY INTERFACE <Interface>// SET   [CONNECTATTEMPTS <Number>]//       [CONNECTRETRYDELAY <Number>]//       [MAXQUEUESIZE <Number>]//       [DEFAULTINTERFACE <Name>]//       [RESULTCOMPATIBILITYMODE <Mode>]// THREAD INFO                       Note: This is an undocumented request// TEST MARSHALLING DATA <X>         Note: This is an undocumented request// Note: This is an  undocumented request// DEBUG MEMORY <CHECKPOINT | DUMP [ALL] | STATS | STATSDIFF | LEAKS>// HELPstatic STAFMutexSem sConnectAttemptsSem;static STAFMutexSem sConnectRetryDelaySem;static STAFMutexSem sMaxQueueSizeSem;static STAFMutexSem sDefaultInterfaceSem;static STAFMutexSem sDefaultAuthenticatorSem;static STAFMutexSem sResultCompatibilityModeSem;STAFMiscService::STAFMiscService() : STAFService("MISC"){    // thread options    fThreadParser.addOption("THREAD", 1,        STAFCommandParser::kValueNotAllowed);    fThreadParser.addOption("INFO", 1,        STAFCommandParser::kValueNotAllowed);    // thread groups    fThreadParser.addOptionGroup("THREAD", 1, 1);    fThreadParser.addOptionGroup("INFO", 1, 1);    // list options        fListParser.addOption("LIST", 1,                          STAFCommandParser::kValueNotAllowed);    fListParser.addOption("INTERFACES", 1,                          STAFCommandParser::kValueNotAllowed);    fListParser.addOption("SETTINGS", 1,                          STAFCommandParser::kValueNotAllowed);    fListParser.addOption("ENDPOINTCACHE", 1,                          STAFCommandParser::kValueNotAllowed);    // list groups/needs    fListParser.addOptionGroup(        "INTERFACES SETTINGS ENDPOINTCACHE", 1, 1);    // query options        fQueryParser.addOption("QUERY", 1,                           STAFCommandParser::kValueNotAllowed);    fQueryParser.addOption("INTERFACE", 1,                           STAFCommandParser::kValueRequired);    // query groups/needs    fQueryParser.addOptionGroup("INTERFACE", 1, 1);    // purge options    fPurgeParser.addOption("PURGE", 1,                           STAFCommandParser::kValueNotAllowed);    fPurgeParser.addOption("ENDPOINTCACHE", 1,                           STAFCommandParser::kValueNotAllowed);    fPurgeParser.addOption("ENDPOINT", 0,                           STAFCommandParser::kValueRequired);    fPurgeParser.addOption("CONFIRM", 1,                           STAFCommandParser::kValueNotAllowed);    // purge groups/needs    fPurgeParser.addOptionNeed("ENDPOINTCACHE", "PURGE");    fPurgeParser.addOptionGroup("ENDPOINTCACHE", 1, 1);    fPurgeParser.addOptionGroup("ENDPOINT CONFIRM", 1, 1);        // set options    fSetParser.addOption("SET", 1,                         STAFCommandParser::kValueNotAllowed);    fSetParser.addOption("CONNECTATTEMPTS", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("CONNECTRETRYDELAY", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("INTERFACECYCLING", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("MAXQUEUESIZE", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("DEFAULTINTERFACE", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("DEFAULTAUTHENTICATOR", 1,                         STAFCommandParser::kValueRequired);    fSetParser.addOption("RESULTCOMPATIBILITYMODE", 1,                         STAFCommandParser::kValueRequired);        // test options    fDebugParser.addOption("DEBUG", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("MEMORY", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("CHECKPOINT", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("STATS", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("STATSDIFF", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("DUMP", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("LEAKS", 1,                           STAFCommandParser::kValueNotAllowed);    fDebugParser.addOption("ALL", 1,                           STAFCommandParser::kValueNotAllowed);    // debug groups/needs    fDebugParser.addOptionGroup("CHECKPOINT DUMP STATS STATSDIFF LEAKS", 1, 1);    fDebugParser.addOptionNeed("DEBUG", "MEMORY");    fDebugParser.addOptionNeed("ALL", "DUMP");    // test options    fTestParser.addOption("TEST", 1,                           STAFCommandParser::kValueNotAllowed);    fTestParser.addOption("MARSHALLING", 1,                           STAFCommandParser::kValueNotAllowed);    fTestParser.addOption("DATA", 1,                           STAFCommandParser::kValueRequired);    // test groups/needs    fTestParser.addOptionNeed("TEST", "MARSHALLING");    // Initialize debug memory structures    #if defined(STAF_OS_TYPE_WIN32) && defined(_DEBUG)    _CrtMemCheckpoint(&fFromMemState);      // Send all reports to STDOUT    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);    _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);    _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);    #endif    // Create the map class definition for "test marshalling" data    fLogRecordClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/SampleLogRecord");    fLogRecordClass->addKey("timestamp", "Date-time");    fLogRecordClass->addKey("level", "Level");    fLogRecordClass->addKey("machine", "Machine");    fLogRecordClass->addKey("message", "Message");    // Create a map of lists    STAFObjectPtr innerList1 = STAFObject::createList();    innerList1->append("String 1");    innerList1->append("String 2");    STAFObjectPtr innerList2 = STAFObject::createList();    innerList2->append("String 3");    innerList2->append("String 4");    fMapOfLists = STAFObject::createMap();    fMapOfLists->put("List1", innerList1);    fMapOfLists->put("List2", innerList2);    // Create a list of maps    STAFObjectPtr innerMap1 = STAFObject::createMap();    innerMap1->put("Key1", "Value1");    innerMap1->put("Key2", "Value2");    STAFObjectPtr innerMap2 = STAFObject::createMap();    innerMap2->put("Key3", "Value3");    innerMap2->put("Key4", "Value4");    fListOfMaps = STAFObject::createList();    fListOfMaps->append(innerMap1);    fListOfMaps->append(innerMap2);    // Construct map class for whoami information    fWhoamiClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/Whoami");     fWhoamiClass->addKey("instanceName",    "Instance Name");    fWhoamiClass->addKey("instanceUUID",    "Instance UUID");    fWhoamiClass->addKey("requestNumber",   "Request Number");    fWhoamiClass->addKey("interface",       "Interface");    fWhoamiClass->addKey("logicalID",       "Logical ID");    fWhoamiClass->addKey("physicalID",      "Physical ID");    fWhoamiClass->addKey("endpoint",        "Endpoint");    fWhoamiClass->addKey("machine",         "Machine");    fWhoamiClass->addKey("machineNickname", "Machine Nickname");    fWhoamiClass->addKey("isLocalRequest",  "Local Request");    fWhoamiClass->addKey("handle",          "Handle");    fWhoamiClass->addKey("handleName",      "Handle Name");        fWhoamiClass->addKey("user",            "User");    fWhoamiClass->addKey("trustLevel",      "Trust Level");    // Construct map class for whoAreYou information    fWhoAreYouClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/WhoAreYou");     fWhoAreYouClass->addKey("instanceName",    "Instance Name");    fWhoAreYouClass->addKey("instanceUUID",    "Instance UUID");    fWhoAreYouClass->addKey("machine",         "Machine");    fWhoAreYouClass->addKey("machineNickname", "Machine Nickname");    fWhoAreYouClass->addKey("isLocalRequest",  "Local Request");    // Construct map class for interface information    fInterfaceClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/Interface");     fInterfaceClass->addKey("name",      "Interface Name");    fInterfaceClass->addKey("library",   "Library");    fInterfaceClass->addKey("optionMap", "Options");    // Construct map class for settings information    fSettingsClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/Settings");    fSettingsClass->addKey("connectAttempts", "Connection Attempts");    fSettingsClass->addKey("connectRetryDelay", "Connect Retry Delay");    fSettingsClass->addKey("interfaceCycling", "Interface Cycling");    fSettingsClass->addKey("maxQueueSize", "Maximum Queue Size");    fSettingsClass->addKey("initialThreads", "Initial Threads");    fSettingsClass->addKey("threadGrowthDelta", "Thread Growth Delta");    fSettingsClass->addKey("dataDir", "Data Directory");    fSettingsClass->addKey("defaultInterface","Default Interface");    fSettingsClass->addKey("defaultAuthenticator", "Default Authenticator");    fSettingsClass->addKey("resultCompatibilityMode",                           "Result Compatibility Mode");    // Construct map class for listing the endpoint cache    fListCacheClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/EndpointCache");    fListCacheClass->addKey("endpoint", "Endpoint");    fListCacheClass->addKey("interface", "Interface");    fListCacheClass->addKey("createdTimestamp", "Date-Time");    // Construct map class for purging the endpoint cache    fPurgeCacheClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/PurgeStats");    fPurgeCacheClass->addKey("numPurged",    "Purged Endpoints");    fPurgeCacheClass->addKey("numRemaining", "Remaining Endpoints");    // Construct map class for thread information    fThreadClass = STAFMapClassDefinition::create(        "STAF/Service/Misc/Thread");     fThreadClass->addKey("totalThreads",   "Total Threads");    fThreadClass->addKey("workingThreads", "Working Threads");    fThreadClass->addKey("idleThreads" ,   "Idle Threads");}STAFServiceResult STAFMiscService::acceptRequest(    const STAFServiceRequest &requestInfo){    STAFString action = requestInfo.fRequest.subWord(0, 1).lowerCase();    if      (action == "version")   return handleVersion(requestInfo);    else if (action == "whoami")    return handleWhoAmI(requestInfo);    else if (action == "whoareyou") return handleWhoAreYou(requestInfo);    else if (action == "thread")    return handleThread(requestInfo);    else if (action == "list")      return handleList(requestInfo);    else if (action == "query")     return handleQuery(requestInfo);    else if (action == "purge")     return handlePurge(requestInfo);    else if (action == "set")       return handleSet(requestInfo);    else if (action == "test")      return handleTest(requestInfo);    else if (action == "debug")     return handleDebug(requestInfo);    else if (action == "help")      return handleHelp(requestInfo);    else return kSTAFInvalidRequestString;}STAFServiceResult STAFMiscService::handleVersion(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "VERSION");        return STAFServiceResult(kSTAFOk, gVersion);}STAFServiceResult STAFMiscService::handleWhoAmI(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "WHOAMI");    // Create a marshalled map containing whoami information    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fWhoamiClass->reference());    STAFObjectPtr whoamiMap = fWhoamiClass->createInstance();    whoamiMap->put("instanceName",    *gSTAFInstanceNamePtr);    whoamiMap->put("instanceUUID",    requestInfo.fSTAFInstanceUUID);    whoamiMap->put("requestNumber",   STAFString(requestInfo.fRequestNumber));    whoamiMap->put("machine",         requestInfo.fMachine);    whoamiMap->put("machineNickname", requestInfo.fMachineNickname);    whoamiMap->put("interface",       requestInfo.fInterface);    whoamiMap->put("physicalID",      requestInfo.fPhysicalInterfaceID);    whoamiMap->put("logicalID",       requestInfo.fLogicalInterfaceID);    whoamiMap->put("endpoint",        requestInfo.fEndpoint);    whoamiMap->put("isLocalRequest",                   requestInfo.fIsLocalRequest ? "Yes" : "No");    whoamiMap->put("handle",          STAFString(requestInfo.fHandle));    whoamiMap->put("handleName",      requestInfo.fHandleName);    whoamiMap->put("user",            requestInfo.fUser);    // This is safe to give them, as they can deduce it anyway    whoamiMap->put("trustLevel",    STAFString(requestInfo.fTrustLevel));    mc->setRootObject(whoamiMap);    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFMiscService::handleWhoAreYou(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "WHOAREYOU");    // Create a marshalled map containing whoareyou information    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fWhoAreYouClass->reference());    STAFObjectPtr whoAreYouMap = fWhoAreYouClass->createInstance();    whoAreYouMap->put("instanceName",    *gSTAFInstanceNamePtr);    whoAreYouMap->put("instanceUUID",    *gSTAFInstanceUUIDPtr);    whoAreYouMap->put("machine",         *gMachinePtr);    whoAreYouMap->put("machineNickname", *gMachineNicknamePtr);    whoAreYouMap->put("isLocalRequest",                      requestInfo.fIsLocalRequest ? "Yes" : "No");    mc->setRootObject(whoAreYouMap);    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFMiscService::handleThread(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 3    IVALIDATE_TRUST(3, "THREAD");    // Create a marshalled map containing whoami information    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fThreadClass->reference());    STAFObjectPtr threadMap = fThreadClass->createInstance();    threadMap->put("totalThreads",                   STAFString(gThreadManagerPtr->getThreadPoolSize()));    threadMap->put("workingThreads",                   STAFString(gThreadManagerPtr->getNumWorkingThreads()));    threadMap->put("idleThreads",                   STAFString(gThreadManagerPtr->getNumReadyThreads()));    mc->setRootObject(threadMap);    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFMiscService::handleList(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 2

⌨️ 快捷键说明

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