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

📄 stafrespoolservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                "STAFResPoolService.cpp: STAFServiceConstruct").adoptImpl();    }    catch (...)    {        STAFString error(                    "STAFResPoolService.cpp: STAFServiceConstruct: Caught "                    "unknown exception in STAFServiceConstruct()");        *pErrorBuffer = error.adoptImpl();    }        return kSTAFUnknownError;}STAFRC_t STAFServiceInit(STAFServiceHandle_t serviceHandle,                         void *pInitInfo, unsigned int initLevel,                         STAFString_t *pErrorBuffer){    STAFRC_t retCode = kSTAFUnknownError;    try    {            if (initLevel != 30) return kSTAFInvalidAPILevel;        ResPoolServiceData *pData =            reinterpret_cast<ResPoolServiceData *>(serviceHandle);                STAFServiceInitLevel30 *pInfo =            reinterpret_cast<STAFServiceInitLevel30 *>(pInitInfo);                retCode = STAFHandle::create(pData->fName, pData->fHandlePtr);                if (retCode != kSTAFOk)            return retCode;                //CREATE options        pData->fCreateParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fCreateParser->addOption("CREATE", 1,                                       STAFCommandParser::kValueNotAllowed);        pData->fCreateParser->addOption("POOL", 1,                                       STAFCommandParser::kValueRequired);        pData->fCreateParser->addOption("DESCRIPTION", 1,                                       STAFCommandParser::kValueRequired);        pData->fCreateParser->addOptionNeed("CREATE", "POOL");        pData->fCreateParser->addOptionNeed("CREATE", "DESCRIPTION");                //DELETE options        pData->fDeleteParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fDeleteParser->addOption("DELETE", 1,                                        STAFCommandParser::kValueNotAllowed);        pData->fDeleteParser->addOption("POOL", 1,                                        STAFCommandParser::kValueRequired);        pData->fDeleteParser->addOption("CONFIRM",  1,                                        STAFCommandParser::kValueNotAllowed);        pData->fDeleteParser->addOption("FORCE",  1,                                        STAFCommandParser::kValueNotAllowed);        pData->fDeleteParser->addOptionNeed("DELETE", "POOL");        pData->fDeleteParser->addOptionNeed("DELETE", "CONFIRM");                //QUERY options        pData->fQueryParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fQueryParser->addOption("QUERY", 1,                                       STAFCommandParser::kValueNotAllowed);        pData->fQueryParser->addOption("POOL", 1,                                       STAFCommandParser::kValueRequired);        pData->fQueryParser->addOptionNeed("QUERY", "POOL");        //REQUEST options        pData->fRequestParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fRequestParser->addOption("REQUEST", 1,                                         STAFCommandParser::kValueNotAllowed);        pData->fRequestParser->addOption("POOL", 1,                                         STAFCommandParser::kValueRequired);        pData->fRequestParser->addOption("TIMEOUT", 1,                                         STAFCommandParser::kValueRequired);        pData->fRequestParser->addOption("FIRST", 1,                                         STAFCommandParser::kValueNotAllowed);        pData->fRequestParser->addOption("RANDOM", 1,                                         STAFCommandParser::kValueNotAllowed);        pData->fRequestParser->addOptionGroup("FIRST RANDOM", 0, 1);        pData->fRequestParser->addOptionNeed("REQUEST", "POOL");        //ADD options        pData->fAddParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fAddParser->addOption("ADD", 1,                                     STAFCommandParser::kValueNotAllowed);        pData->fAddParser->addOption("POOL", 1,                                     STAFCommandParser::kValueRequired);        pData->fAddParser->addOption("ENTRY", 0,                                     STAFCommandParser::kValueRequired);        pData->fAddParser->addOptionNeed("ADD", "POOL");        pData->fAddParser->addOptionNeed("ADD", "ENTRY");        //REMOVE options        pData->fRemoveParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fRemoveParser->addOption("REMOVE", 1,                                        STAFCommandParser::kValueNotAllowed);        pData->fRemoveParser->addOption("POOL", 1,                                        STAFCommandParser::kValueRequired);        pData->fRemoveParser->addOption("ENTRY", 0,                                        STAFCommandParser::kValueRequired);        pData->fRemoveParser->addOption("CONFIRM", 1,                                        STAFCommandParser::kValueNotAllowed);        pData->fRemoveParser->addOption("FORCE", 1,                                        STAFCommandParser::kValueNotAllowed);        pData->fRemoveParser->addOptionNeed("REMOVE", "POOL");        pData->fRemoveParser->addOptionNeed("REMOVE", "ENTRY");        pData->fRemoveParser->addOptionNeed("REMOVE", "CONFIRM");        //RELEASE options        pData->fReleaseParser = STAFCommandParserPtr(new STAFCommandParser,                                                 STAFCommandParserPtr::INIT);        pData->fReleaseParser->addOption("RELEASE", 1,                                         STAFCommandParser::kValueNotAllowed);        pData->fReleaseParser->addOption("POOL", 1,                                         STAFCommandParser::kValueRequired);        pData->fReleaseParser->addOption("ENTRY", 1,                                         STAFCommandParser::kValueRequired);        pData->fReleaseParser->addOption("FORCE", 1,                                         STAFCommandParser::kValueNotAllowed);        pData->fReleaseParser->addOptionNeed("RELEASE", "POOL");        pData->fReleaseParser->addOptionNeed("RELEASE", "ENTRY");        //LIST options        pData->fListParser = STAFCommandParserPtr(new STAFCommandParser,                                                  STAFCommandParserPtr::INIT);        pData->fListParser->addOption("LIST", 1,                                      STAFCommandParser::kValueNotAllowed);        pData->fListParser->addOption("POOLS", 1,                                      STAFCommandParser::kValueNotAllowed);        pData->fListParser->addOption("SETTINGS", 1,                                      STAFCommandParser::kValueNotAllowed);        pData->fListParser->addOptionNeed("POOLS SETTINGS", "LIST");        pData->fListParser->addOptionGroup("POOLS SETTINGS", 0, 1);                                              //STAF_CALLBACK options        pData->fSTAFCallbackParser = STAFCommandParserPtr(new             STAFCommandParser, STAFCommandParserPtr::INIT);        pData->fSTAFCallbackParser->addOption("STAF_CALLBACK", 1,                                      STAFCommandParser::kValueNotAllowed);        pData->fSTAFCallbackParser->addOption("HANDLEDELETED", 1,                                      STAFCommandParser::kValueNotAllowed);        pData->fSTAFCallbackParser->addOption("HANDLE", 1,                                      STAFCommandParser::kValueRequired);        pData->fSTAFCallbackParser->addOption("UUID", 1,                                      STAFCommandParser::kValueRequired);        pData->fSTAFCallbackParser->addOption("MACHINE", 1,                                      STAFCommandParser::kValueRequired);        pData->fSTAFCallbackParser->addOption("KEY", 1,                                      STAFCommandParser::kValueRequired);        //HELP options        pData->fHelpParser = STAFCommandParserPtr(new STAFCommandParser,                                                  STAFCommandParserPtr::INIT);        pData->fHelpParser->addOption("HELP", 1,                                      STAFCommandParser::kValueNotAllowed);        //VERSION options        pData->fVersionParser = STAFCommandParserPtr(new STAFCommandParser,                                                  STAFCommandParserPtr::INIT);        pData->fVersionParser->addOption("VERSION", 1,                                         STAFCommandParser::kValueNotAllowed);        // PARMS                pData->fParmsParser = STAFCommandParserPtr(new STAFCommandParser,                                                   STAFCommandParserPtr::INIT);        pData->fParmsParser->addOption("DIRECTORY", 1,                                       STAFCommandParser::kValueRequired);        STAFCommandParseResultPtr parsedResult =             pData->fParmsParser->parse(pInfo->parms);        if (parsedResult->rc != kSTAFOk)         {            *pErrorBuffer = parsedResult->errorBuffer.adoptImpl();            return parsedResult->rc;        }        if (parsedResult->optionTimes(sDirectory))        {            STAFResultPtr dirResult = resolveOpLocal(pData, parsedResult,                                                     sDirectory);            if (dirResult->rc != kSTAFOk)            {                *pErrorBuffer = dirResult->result.adoptImpl();                return dirResult->rc;            }            pData->fPoolDir = dirResult->result;        }                // Construct the map class for general pool information output        pData->fPoolClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/Pool");        pData->fPoolClass->addKey("poolName",    "Pool Name");        pData->fPoolClass->addKey("description", "Description");                // Construct the map class for listing service settings        pData->fSettingsClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/Settings");        pData->fSettingsClass->addKey("directory",  "Directory");        // Construct the map class for detailed pool information output        pData->fPoolInfoClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/PoolInfo");        pData->fPoolInfoClass->addKey("description",  "Description");        pData->fPoolInfoClass->addKey("requestList",  "Pending Requests");        pData->fPoolInfoClass->addKey("resourceList", "Resources");        // Construct map class for a pending request        pData->fRequestClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/Request");        pData->fRequestClass->addKey("machine",    "Machine");        pData->fRequestClass->addKey("handleName", "Handle Name");        pData->fRequestClass->addKey("handle",     "Handle");        pData->fRequestClass->addKey("user",       "User");        pData->fRequestClass->addKey("endpoint",   "Endpoint");        pData->fRequestClass->addKey("requestedTimestamp",                                     "Date-Time Requested");        // Construct map class for a resource owner        pData->fResourceOwnerClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/ResourceOwner");        pData->fResourceOwnerClass->addKey("machine",    "Machine");        pData->fResourceOwnerClass->addKey("handleName", "Handle Name");        pData->fResourceOwnerClass->addKey("handle",     "Handle");        pData->fResourceOwnerClass->addKey("user",       "User");        pData->fResourceOwnerClass->addKey("endpoint",   "Endpoint");        pData->fResourceOwnerClass->addKey("requestedTimestamp",                                           "Date-Time Requested");        pData->fResourceOwnerClass->addKey("acquiredTimestamp",                                           "Date-Time Acquired");                // Construct map class for a resource        pData->fResourceClass = STAFMapClassDefinition::create(            "STAF/Service/ResPool/Resource");        pData->fResourceClass->addKey("entry", "Entry");        pData->fResourceClass->addKey("owner", "Owner");        // Get line separator        STAFResultPtr result = pData->fHandlePtr->submit(            "local", "VAR", "RESOLVE STRING {STAF/Config/Sep/Line}");        if (result->rc != 0)        {            *pErrorBuffer = result->result.adoptImpl();            return result->rc;        }        else sLineSep = result->result;        // Get local machine name (logical identifier)        result = pData->fHandlePtr->submit(            "local", "VAR", "RESOLVE STRING {STAF/Config/Machine}");        if (result->rc != 0)        {            *pErrorBuffer = result->result.adoptImpl();            return result->rc;        }        else pData->fLocalMachineName = result->result;        // Register Help Data        registerHelpData(pData, kSTAFResPoolNotEntryOwner,            STAFString("Not resource pool entry owner"),            STAFString("You are not the owner of the entry you are trying to "                       "RELEASE.  Use the FORCE option if you are sure that "                       "the correct entry is specified."));        registerHelpData(pData, kSTAFResPoolHasPendingRequests,            STAFString("Resource pool has pending requests"),            STAFString("The resource pool you are trying to DELETE has pending"                       " requests.  If necessary, use the FORCE option."));        registerHelpData(pData, kSTAFResPoolNoEntriesAvailable,            STAFString("Resource pool has no entries available"),            STAFString("The resource pool has no entries."));        registerHelpData(pData, kSTAFResPoolCreatePoolPathError,            STAFString("Error creating pool path"),            STAFString("The directory specified by the DIRECTORY parameter "                       "when registering the service or the default "                       "directory could not be created."));        registerHelpData(pData, kSTAFResPoolInvalidFileFormat,            STAFString("Invalid pool file format"),            STAFString("An error occurred reading the resource pool file "                       "due to an error in the file format.  If you are "                       "using the latest version of the Resource Pool "                       "service, contact the STAF authors."));        registerHelpData(pData, kSTAFResPoolEntryIsOwned,            STAFString("Resource pool entry is owned"),            STAFString("A resource pool entry you specified to REMOVE is "                       "owned.  Use the FORCE option if you are sure that "                       "the correct entry is specified."));        // Determine the pool directory        STAFFSPath poolFilePath;        if (pData->fPoolDir != STAFString())        {            // Set to pool directory using DIRECTORY parameter from RESPOOL            // Service Configuration            poolFilePath.setRoot(pData->fPoolDir);        }        else        {   // Assign Default Pool Directory value if no DIRECTORY parameter            // -  Use <pInfo->writeLocation>/<lower-case service name>                        poolFilePath.setRoot(pInfo->writeLocation);            poolFilePath.addDir("service");            poolFilePath.addDir(pData->fShortName.toLowerCase());            pData->fPoolDir = poolFilePath.asString();        }        // Find all the pools (*.rpl files) in the pool directory                STAFFSEntryType_t entryType = kSTAFFSFile;                if (poolFilePath.exists())        {            STAFFSEnumPtr dirEnum =                 poolFilePath.getEntry()->enumerate(kUTF8_STAR, sPoolExt,                                                    entryType);            // Initialize each pool            for (; dirEnum->isValid(); dirEnum->next())            {                STAFFSEntryPtr entry = dirEnum->entry();                STAFString fileName = entry->path().asString();                // Read the pool file and store its data in PoolData                PoolData poolData;                                unsigned int status = readPoolFile(fileName, poolData);

⌨️ 快捷键说明

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