📄 stafmon.rxp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//****************************************************************************//* STAF_SERVICE_INTERFACE_LEVEL:2 *//****************************************************************************//* REXX Monitor Service for Software Testing Automation Framework (STAF) *//* ------------------------------------------------------------------------ *//* Description: This program provides a means to log and query monitor *//* (status) messages. *//* NOTE: This version hardens the data to the disk. *//* Options: *//* Log - Log a monitor message *//* Args: log <message> *//* Query - query a monitor message *//* Args: query machine <machine> handle <handle> *//* List - List the monitor machines or machine handles *//* Delete - Delete monitor files and directories *//* Refresh - Refresh the STAF/Service/<Name> variables *//* *//* Internal data format: <totlength>YYYYMMDD-HH:MM:SS<message> *//* *//* Note: This program requires RxPP (REXX pre-processor) to be used to *//* generate the executable cmd file. *//* ------------------------------------------------------------------------ *//* History: *//* 0.10 DHR 02/01/1998 Initial implementation *//* 0.20 DHR 02/21/1998 Added variable resolution, unique variable id *//* 0.30 DHR 03/16/1998 Parser changes *//* 0.50 DHR 03/26/1998 Added new API data structure *//* 1.10 DHR 05/05/1998 Fixed DBCS error on totalen field *//* 1.50 DHR 09/15/1998 Add the new INTERFACE_LEVEL, call format, and *//* variable naming convention *//* 1.75 DHR 09/29/1998 New RXThread package, LIST, DELETE, REFRESH *//* and INTERFACE_LEVEL:2 *//* 1.80 DHR 04/07/1999 Remove old variable name support, warn at INIT. *//****************************************************************************/options "EXMODE ETMODE"parse source osType invokeType functionNamecall STAFErrorText /* Set the STAF common error codes and text */ext=".mon" /* Monitor file extension *//* Make sure we are being called correctly */if invokeType \= "FUNCTION" then RETURN MakeSTAFResult(STAFError.!ServiceConfigurationError)/* Call the appropriate function */SIGNAL VALUE TRANSLATE(functionName)/****************************************************************************//* Functions *//****************************************************************************//****************************************************************************//* STAFServiceInit - Initializes the service *//* *//* Accepts: The name of this service *//* The service parameters *//* Returns: 0 *//****************************************************************************/STAFServiceInit: parse arg serviceName, serviceParms /* Load system functions */ call RxFuncAdd "SysLoadFuncs", "REXXUTIL", "SysLoadFuncs" call SysLoadFuncs /* Load STAF functions */ call RxFuncAdd "STAFLoadFuncs", "RXSTAF", "STAFLoadFuncs" call STAFLoadFuncs /* Load the STAF RxThread functions */ call RxFuncAdd "RxThreadLoadFuncs", "RxThread", "RxThreadLoadFuncs" call RxThreadLoadFuncs /* Register Monitor to STAF */ call STAFRegister "STAF/Service/"serviceName if RESULT \= 0 then RETURN MakeSTAFResult(STAFError.!STAFRegistrationError, , STAFError.!STAFRegistrationError.!text || ": " || RESULT) call ProcessVars "SET" if TRANSLATE(serviceParms) = "DELETE" then call DeleteDataRETURN MakeSTAFResult(STAFError.!Ok)/****************************************************************************//* STAFServiceAcceptRequest - Handles a service request from STAF *//* *//* Accepts: The name of this service *//* The name of the originating machine *//* The registered name of the originating process *//* The handle of the originating process *//* The actual request string *//* *//* Returns: 0 , on success *//* >0, otherwise *//****************************************************************************/STAFServiceAcceptRequest: parse arg serviceName, thisMachine, clientMachine, clientEffective, , clientTrust, origName, origHandle, origRequest /* Initialization */ version = "1.80" /* Current version number */ call LogMonErrorText /* Set Monitor error text */ if clientTrust = 0 then RETURN MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) /* Read in the required variables using RxThread */ call ProcessVars "Read" /* Register Monitor to STAF */ call STAFRegister "STAF/Service/"serviceName if RESULT \= 0 then RETURN MakeSTAFResult(STAFError.!STAFRegistrationError, , STAFError.!STAFRegistrationError.!text": "RESULT) /* Process all the parser options */ parse var origRequest type . type = TRANSLATE(type) call InitParser call AddOption "LOG", 1, "NO" call AddOption "QUERY", 1, "NO" call AddOption "LIST", 1, "NO" call AddOption "HELP", 1, "NO" call AddOption "REFRESH", 1, "NO" call AddOption "DELETE", 1, "NO" call AddOption "VERSION", 1, "NO" call AddOptionGroup "LOG QUERY LIST HELP REFRESH DELETE VERSION", 1, 1 select when type = "LOG" then do call AddOption "MESSAGE", 1, "YES" call AddOption "RESOLVEMESSAGE", 1, "NO" call AddOption "NORESOLVEMESSAGE", 1, "NO" call AddOptionNeed "LOG", "MESSAGE" call AddOptionGroup "RESOLVEMESSAGE NORESOLVEMESSAGE", 0, 1 end when type = "QUERY" then do call AddOption "MACHINE", 1, "YES" call AddOption "HANDLE", 1, "YES" call AddOptionNeed "QUERY", "MACHINE" call AddOptionNeed "QUERY", "HANDLE" end when type = "LIST" then do call AddOption "MACHINES", 1, "NO" call AddOption "MACHINE", 1, "YES" call AddOptionGroup "MACHINE MACHINES", 1, 1 end when type = "REFRESH" then do call AddOption "VAR", 1, "NO" call AddOptionNeed "REFRESH", "VAR" end when type = "DELETE" then do call AddOption "CONFIRM", 1, "NO" call AddOption "BEFORE", 1, "YES" call AddOptionNeed "DELETE", "CONFIRM" end otherwise nop end rc = ParseString(origRequest, "errorBuffer") if rc \= 0 then RETURN MakeSTAFResult(STAFError.!InvalidRequestString, , STAFError.!InvalidRequestString.!text || lineSep || errorBuffer) select when type = "QUERY" then do if clientTrust < 2 then RETURN MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) filePath = directory || fileSep || ResolveVariable(optionValue("MACHINE")) || , fileSep || ResolveVariable(optionValue("HANDLE")) || ext rc = FileStatus(filePath, maxRetry, "read") if rc = STAFError.!Ok then /* Make sure file READY */ do dataLen = c2d(charin(filePath, 1, 4),4) if dataLen < 1 then rc = MakeSTAFResult(errorBadLog, errorBadLog.!text) else rc = MakeSTAFResult(STAFError.!Ok, charin(filePath, 5, 8) || "-" || , charin(filePath, 13, 8) || " " || charin(filePath, 21, dataLen - 16)) end else rc = MakeSTAFResult(STAFError.!FileOpenError, "File" filePath "not found") end when type = "LOG" then do if clientTrust < 3 then RETURN MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) directory = directory || fileSep || clientEffective filePath = directory || fileSep || origHandle || ext if \CreatePath(directory, fileSep) then /* Check/Create directory(s) */ do status = FileStatus(filePath, maxRetry, "write") if status \= 2 then do message = OptionValue("MESSAGE") if optionTimes("RESOLVEMESSAGE") > 0 then resolveMessage = 1 else if optionTimes("NORESOLVEMESSAGE") > 0 then resolveMessage = 0 if resolveMessage then do STAFRC = STAFSubmit("LOCAL", "VAR", "RESOLVE" STAFWrapData(message)) if STAFRC = 0 then message = STAFResult end timestamp = date('s')||time() dataLen = DBWIDTH(message) + DBWIDTH(timestamp) if dataLen > maxSize then do message = left(message, maxSize) dataLen = DBWIDTH(message) + DBWIDTH(timestamp) end options "NOEXMODE NOETMODE" data = d2c(dataLen,4) || timestamp || message options "EXMODE ETMODE" rc = charout(filePath, data, 1) if rc = STAFError.!Ok then rc = MakeSTAFResult(STAFError.!Ok) else rc = MakeSTAFResult(STAFError.!FileWriteError, , STAFError.!FileWriteError.!text || ": " filePath) end else rc = MakeSTAFResult(STAFError.!FileOpenError, "File" filePath "not ready") end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -