📄 stafrexxservice.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001, 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAF_fstream.h"#include <string>#include "STAFServiceInterface.h"#include "STAFRefPtr.h"#include "STAFUtil.h"#include "STAF_rexx.h"struct RexxServiceData{ unsigned int fDebugMode; unsigned int fInterfaceLevel; STAFString fCommand; STAFString fName; std::string fTokenImage;};typedef STAFRefPtr<RexxServiceData> RexxServiceDataPtr;static unsigned int callRexx(RexxServiceData *pData, std::string function, unsigned int numParms, RXSTRING *parms, STAFString &result);unsigned int STAFServiceGetLevelBounds(unsigned int levelID, unsigned int *minimum, unsigned int *maximum){ switch (levelID) { case kServiceInfo: case kServiceInit: case kServiceAcceptRequest: { *minimum = 30; *maximum = 30; break; } case kServiceTerm: case kServiceDestruct: { *minimum = 0; *maximum = 0; break; } default: { return kSTAFInvalidAPILevel; } } return 0;}unsigned int STAFServiceConstruct(STAFServiceHandle_t *pServiceHandle, void *pServiceInfo, unsigned int infoLevel, STAFString_t *pErrorBuffer){ try { if (infoLevel != 30) return kSTAFInvalidAPILevel; STAFServiceInfoLevel30 *pInfo = reinterpret_cast<STAFServiceInfoLevel30 *>(pServiceInfo); RexxServiceData data; data.fDebugMode = 0; data.fCommand = pInfo->exec; data.fName = pInfo->name; data.fInterfaceLevel = 0; // Walk through and verify the config options for (unsigned int i = 0; i < pInfo->numOptions; ++i) { if (STAFString(pInfo->pOptionName[i]).upperCase() == "DEBUG") { data.fDebugMode = 1; } else { STAFString optionError(pInfo->pOptionName[i]); *pErrorBuffer = optionError.adoptImpl(); return kSTAFServiceConfigurationError; } } // Verify that it is using the official interface level specification ifstream fileText(data.fCommand.toCurrentCodePage()->buffer()); if (!fileText) { STAFString openError("Error opening file: " + data.fCommand); *pErrorBuffer = openError.adoptImpl(); return kSTAFServiceConfigurationError; } unsigned int done = 0; for(; !done && (data.fInterfaceLevel == 0);) { char buffer[256] = { 0 }; fileText.getline(buffer, 255); STAFString line = STAFString(buffer).strip(); // Make sure this is a comment line if (line.find("/*") != 0) { done = 1; continue; } // Make sure there are at least two words on the first line if (line.numWords() < 2) continue; // Make sure the second word is in the format <string>:<string> STAFString specifier = line.subWord(1, 1); unsigned int colonPos = specifier.find(kUTF8_COLON); if (colonPos == STAFString::kNPos) continue; if (specifier.length() < (colonPos + 1)) continue; // Make sure the correct marker is there and the second string is a // number STAFString interfaceString = specifier.subString(0, colonPos).toUpperCase(); STAFString interfaceLevelString = specifier.subString(colonPos + 1); if (interfaceString != "STAF_SERVICE_INTERFACE_LEVEL") continue; if (!interfaceLevelString.isDigits()) continue; data.fInterfaceLevel = interfaceLevelString.asUInt(); } // Check to see if we found a valid REXX inteface level specifier if (done) { STAFString levelError("No valid REXX service interface level " "specifier found"); *pErrorBuffer = levelError.adoptImpl(); return kSTAFInvalidAPILevel; } // Make sure it specifies a supported interface level if ((data.fInterfaceLevel != 30)) { STAFString levelError("Unsupported REXX interface level"); *pErrorBuffer = levelError.adoptImpl(); return kSTAFInvalidAPILevel; } if (!data.fDebugMode) { SHORT rexxRC = 0; LONG rc = 0; RXSTRING arg = { 3, "//T" }; RXSTRING result = { 0 }; RXSTRING inStore[2] = { 0 }; // First open the file fstream sourceFile(data.fCommand.toCurrentCodePage()->buffer(), ios::binary | ios::in); if (!sourceFile) { STAFString openError("Error opening file: " + data.fCommand); *pErrorBuffer = openError.adoptImpl(); return kSTAFFileOpenError; } // Figure out how big it is sourceFile.seekg(0, std::ios::end); unsigned int fileLength = (unsigned int)sourceFile.tellg(); // Initialize the source buffer inStore[0].strlength = fileLength; inStore[0].strptr = new char[fileLength]; sourceFile.seekg(0, std::ios::beg); sourceFile.read(inStore[0].strptr, fileLength); // Now call RexxStart to tokenize the source rc = RexxStart(1, &arg, const_cast<char *>( data.fCommand.toCurrentCodePage()->buffer()), inStore, 0, RXCOMMAND, 0, &rexxRC, &result); // Free up the source image delete [] inStore[0].strptr; if (rc != 0) { STAFString tokenizeError("Error tokenizing file: " + data.fCommand); *pErrorBuffer = tokenizeError.adoptImpl(); return kSTAFREXXError; } // Copy the image into an std::string for ease of use later data.fTokenImage = std::string(inStore[1].strptr, (unsigned int)inStore[1].strlength); // Free up the sytem memory for the tokenized image STAFUtilFreeSystemMemory(inStore[1].strptr); } // Set service handle *pServiceHandle = new RexxServiceData(data); return kSTAFOk; } catch (STAFException &e) { e.trace(); } catch (...) { /* Do Nothing */ } return kSTAFUnknownError;}unsigned int STAFServiceInit(STAFServiceHandle_t serviceHandle, void *pInitInfo, unsigned int initLevel, STAFString_t *pErrorBuffer){ try { if (initLevel != 30) return kSTAFInvalidAPILevel; RexxServiceData *pData = reinterpret_cast<RexxServiceData *>(serviceHandle); STAFServiceInitLevel30 *pInfo = reinterpret_cast<STAFServiceInitLevel30 *>(pInitInfo); STAFString result; unsigned int rc = kSTAFUnknownError;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -