📄 stafrespoolservice.cpp
字号:
if (status == kReadEndOfFile) { STAFString error( "STAFResPoolService.cpp: STAFServiceInit: " "Invalid file contents in resource pool " + fileName); cout << error << endl; *pErrorBuffer = error.adoptImpl(); return kSTAFResPoolInvalidFileFormat; } else if (status == kReadInvalidFormat) { STAFString error = "STAFResPoolService.cpp: STAFServiceInit: " "Invalid file format (" + poolData.fileFormat; error += ") in resource pool file " + fileName; cout << error << endl; *pErrorBuffer = error.adoptImpl(); return kSTAFResPoolInvalidFileFormat; } else if (status == kFileOpenError) { STAFString error( "STAFResPoolService.cpp: STAFServiceInit: " "Error opening resource pool file " + fileName); cout << error << endl; *pErrorBuffer = error.adoptImpl(); return kSTAFFileOpenError; } // Add the pool data to the Pool Map pData->fPoolMap.insert(PoolMap::value_type( poolData.poolName.toUpperCase(), PoolDataPtr(new PoolData(poolData), PoolDataPtr::INIT))); } } else { // Create the pool directory try { STAFFSEntryPtr pooldir = poolFilePath.createDirectory(kSTAFFSCreatePath); } catch (...) { STAFString error("STAFResPoolService.cpp: STAFServiceInit: " "Invalid ResPool Directory: " + pData->fPoolDir); cout << error << endl; *pErrorBuffer = error.adoptImpl(); return kSTAFResPoolCreatePoolPathError; } } pData->fPoolMapRWSem = STAFRWSemPtr(new STAFRWSem, STAFRWSemPtr::INIT); } catch (STAFException &e) { *pErrorBuffer = getExceptionString(e, "STAFResPoolService.cpp: STAFServiceInit").adoptImpl(); } catch (...) { STAFString error( "STAFResPoolService.cpp: STAFServiceInit: Caught unknown " "exception in STAFServiceServiceInit()"); *pErrorBuffer = error.adoptImpl(); } return retCode;}STAFRC_t STAFServiceAcceptRequest(STAFServiceHandle_t serviceHandle, void *pRequestInfo, unsigned int reqLevel, STAFString_t *pResultBuffer){ if (reqLevel != 30) return kSTAFInvalidAPILevel; STAFRC_t retCode = kSTAFUnknownError; try { STAFResultPtr result(new STAFResult(kSTAFOk, STAFString()), STAFResultPtr::INIT); STAFServiceRequestLevel30 *pInfo = reinterpret_cast<STAFServiceRequestLevel30 *>(pRequestInfo); ResPoolServiceData *pData = reinterpret_cast<ResPoolServiceData *>(serviceHandle); STAFString request(pInfo->request); STAFString action = request.subWord(0, 1).toLowerCase(); // Call functions for the request if (action == "create") result = handleCreate(pInfo, pData); else if (action == "delete") result = handleDelete(pInfo, pData); else if (action == "query") result = handleQuery(pInfo, pData); else if (action == "request") result = handleRequest(pInfo, pData); else if (action == "add") result = handleAdd(pInfo, pData); else if (action == "remove") result = handleRemove(pInfo, pData); else if (action == "release") result = handleRelease(pInfo, pData); else if (action == "list") result = handleList(pInfo, pData); else if (action == "staf_callback") result = handleSTAFCallback(pInfo, pData); else if (action == "help") result = handleHelp(pInfo, pData); else if (action == "version") result = handleVersion(pInfo, pData); else { result = STAFResultPtr(new STAFResult(kSTAFInvalidRequestString, request.subWord(0, 1)), STAFResultPtr::INIT); } *pResultBuffer = result->result.adoptImpl(); retCode = result->rc; } catch (STAFException &e) { *pResultBuffer = getExceptionString(e, "STAFResPoolService.cpp: " "STAFServiceAcceptRequest").adoptImpl(); } catch (...) { STAFString error( "STAFResPoolService.cpp: STAFServiceAcceptRequest: Caught " "unknown exception in STAFServiceAcceptRequest()"); *pResultBuffer = error.adoptImpl(); } return retCode;}STAFRC_t STAFServiceTerm(STAFServiceHandle_t serviceHandle, void *pTermInfo, unsigned int termLevel, STAFString_t *pErrorBuffer){ if (termLevel != 0) return kSTAFInvalidAPILevel; STAFRC_t retCode = kSTAFUnknownError; try { retCode = kSTAFOk; ResPoolServiceData *pData = reinterpret_cast<ResPoolServiceData *>(serviceHandle); // Un-register Help Data unregisterHelpData(pData, kSTAFResPoolNotEntryOwner); unregisterHelpData(pData, kSTAFResPoolHasPendingRequests); unregisterHelpData(pData, kSTAFResPoolNoEntriesAvailable); unregisterHelpData(pData, kSTAFResPoolCreatePoolPathError); unregisterHelpData(pData, kSTAFResPoolInvalidFileFormat); unregisterHelpData(pData, kSTAFResPoolEntryIsOwned); } catch (STAFException &e) { *pErrorBuffer = getExceptionString(e, "STAFResPoolService.cpp: STAFServiceTerm").adoptImpl(); } catch (...) { STAFString error( "STAFResPoolService.cpp: STAFServiceTerm: Caught unknown " "exception in STAFServiceTerm()"); *pErrorBuffer = error.adoptImpl(); } return retCode;}STAFRC_t STAFServiceDestruct(STAFServiceHandle_t *serviceHandle, void *pDestructInfo, unsigned int destructLevel, STAFString_t *pErrorBuffer){ if (destructLevel != 0) return kSTAFInvalidAPILevel; STAFRC_t retCode = kSTAFUnknownError; try { ResPoolServiceData *pData = reinterpret_cast<ResPoolServiceData *>(*serviceHandle); delete pData; *serviceHandle = 0; retCode = kSTAFOk; } catch (STAFException &e) { *pErrorBuffer = getExceptionString(e, "STAFResPoolService.cpp: STAFServiceDestruct").adoptImpl(); } catch (...) { STAFString error( "STAFResPoolService.cpp: STAFServiceDestruct: Caught " "unknown exception in STAFServiceDestruct()"); *pErrorBuffer = error.adoptImpl(); } return retCode;}// Handles resource pool creation requestsSTAFResultPtr handleCreate(STAFServiceRequestLevel30 *pInfo, ResPoolServiceData *pData){ // Verify the requester has at least trust level 4 VALIDATE_TRUST(4, pData->fShortName, "CREATE", pData->fLocalMachineName); // Parse the result STAFCommandParseResultPtr parsedResult = pData->fCreateParser->parse(pInfo->request); if (parsedResult->rc != kSTAFOk) { return STAFResultPtr(new STAFResult(kSTAFInvalidRequestString, parsedResult->errorBuffer), STAFResultPtr::INIT); } // Set the poolName variable (resolve the pool name) STAFResultPtr resultPtr = resolveOp(pInfo, pData, parsedResult, sPool); if (resultPtr->rc != 0) return resultPtr; STAFString poolName = resultPtr->result; // Set the poolDescription variable (resolve the pool description) resultPtr = resolveOp(pInfo, pData, parsedResult, sDescription); if (resultPtr->rc != 0) return resultPtr; STAFString poolDescription = resultPtr->result; // Get a write lock on the Pool Map for the duration of this block STAFRWSemWLock wLock(*pData->fPoolMapRWSem); // Verify that the resource pool does not already exist in the Pool Map if ((pData->fPoolMap.find(poolName.toUpperCase())) != pData->fPoolMap.end()) { return STAFResultPtr(new STAFResult(kSTAFAlreadyExists, poolName), STAFResultPtr::INIT); } // Set the path for the resource pool file STAFFSPath poolFilePath; poolFilePath.setRoot(pData->fPoolDir); poolFilePath.setName(poolName); poolFilePath.setExtension(sPoolExt); PoolData poolData(poolName, poolDescription); // Write the pool data STAFString fileName = poolFilePath.asString(); if (writePoolFile(fileName, poolData) != kReadorWriteOk) { return STAFResultPtr(new STAFResult(kSTAFFileWriteError, fileName), STAFResultPtr::INIT); } // Update in memory data structures pData->fPoolMap.insert(PoolMap::value_type(poolData.poolName.toUpperCase(), PoolDataPtr(new PoolData(poolData), PoolDataPtr::INIT))); // Return an OK result return STAFResultPtr(new STAFResult(kSTAFOk, STAFString()), STAFResultPtr::INIT);}// Handles resource pool deletion requestsSTAFResultPtr handleDelete(STAFServiceRequestLevel30 *pInfo, ResPoolServiceData *pData){ STAFString result; STAFRC_t rc = kSTAFOk; // Verify the requester has at least trust level 4 VALIDATE_TRUST(4, pData->fShortName, "DELETE", pData->fLocalMachineName); // Parse the request STAFCommandParseResultPtr parsedResult = pData->fDeleteParser->parse( pInfo->request); if (parsedResult->rc != kSTAFOk) { return STAFResultPtr(new STAFResult(kSTAFInvalidRequestString, parsedResult->errorBuffer), STAFResultPtr::INIT); } // Set the poolName variable (resolve the pool name) STAFResultPtr resultPtr = resolveOp(pInfo, pData, parsedResult, sPool); if (resultPtr->rc != 0) return resultPtr; STAFString poolName = resultPtr->result; // Get a write lock on the Pool Map for the duration of this block. // Don't need a lock on Pool Data because I have a write lock on Pool Map. STAFRWSemWLock wLock(*pData->fPoolMapRWSem); // Make sure the resource pool is in the Pool Map and get a pointer to it PoolMap::iterator poolIterator; PoolDataPtr poolPtr; if ((poolIterator = pData->fPoolMap.find(poolName.toUpperCase())) == pData->fPoolMap.end()) { return STAFResultPtr(new STAFResult(kSTAFDoesNotExist, poolName), STAFResultPtr::INIT); } // Set a pointer to the resource pool to be deleted poolPtr = (*poolIterator).second; // Check if there are any pending requests and if FORCE is not specified. if ((poolPtr->requestList.size() != 0) && (parsedResult->optionTimes(sForce) == 0))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -