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

📄 stafpool.rxp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 RXP
📖 第 1 页 / 共 3 页
字号:
  RETURN 0/* End of ReleaseMutexSem *//****************************************************************************//* Val - Returns a named variable's value, or updates the variables value   *//*       with a new value before returning the previous value               *//*                                                                          *//* Accepts: varName - The name of the variable                              *//*          varValue - The new variable value                               *//*                                                                          *//* Returns: The current value of the named variable.                        *//*          If a value is input, the named variable is updated with this    *//*          new value prior to returning its previous value                 *//****************************************************************************/Val: PROCEDURE EXPOSE self  parse arg varName, varValue  if varValue = '' then      RETURN RxThreadValue(self, varName)  else      RETURN RxThreadValue(self, varName, varValue)  RETURN ""/* End of Val *//****************************************************************************//* DeletePending - Deletes a pending request                                *//*                                                                          *//* Accepts: No formal parameters (pending_save is set during a request      *//*          for a resource and no resources are available. pending_save     *//*          contains the information used to search for the pending request *//*          among all the pending requests for the pool.                    *//*                                                                          *//* Returns: The time stamp of the pending request                           *//****************************************************************************/DeletePending: PROCEDURE EXPOSE self thePool orgMachine orgName orgHandle  numPending = VAL('POOL.'thePool'.!Request.0')  do i = 1 to numPending      pendingRecord = VAL('POOL.'thePool'.!Request.'i'.!Owner')      parse var pendingRecord . ';' pMach ';' pName ';' pHandle ';' rest      if (pMach = orgMachine) & (pName = orgName) & (pHandle = orgHandle) then          LEAVE  end  tempOwner = VAL('POOL.'thePool'.!Request.'i'.!Owner')  delPos = LASTPOS(';', tempOwner)  timeOfRequest = SUBSTR(tempOwner, delPos + 1)  if i \= numPending then  do      do j = i to (VAL('POOL.'thePool'.!Request.0') - 1)          call VAL 'POOL.'thePool'.!Request.'j'.!Owner',,                   VAL('POOL.'thePool'.!Request.'j+1'.!Owner')      end  end  call VAL 'POOL.'thePool'.!Request.0', numPending - 1  RETURN timeOfRequest/* End of DeletePending *//**************************************************************************//* ResolveStandardVariables - Determines the standard variables needed by *//*                            this service                                *//*                                                                        *//* Accepts: Nothing                                                       *//*                                                                        *//* Returns: 0 , if successful                                             *//*          >0, if not successful (errorBuffer will be set)               *//**************************************************************************/ResolveStandardVariables: PROCEDURE EXPOSE STAFHandle self poolDir bootDrive,                                           delimit crlf errorBuffer serviceName  call STAFSubmit "LOCAL", "VAR", "RESOLVE {"self"/Directory} RESOLVE",                  "{STAF/Config/BootDrive} RESOLVE {STAF/Config/Sep/File}",                  "RESOLVE {STAF/Config/Sep/Line}"  if RESULT \= 0 then  do      errorBuffer = STAFResult      RETURN RESULT  end  parse var STAFResult poolDirRC ':' poolDir '00'x bootDriveRC ':',                       bootDrive '00'x delimitRC ':' delimit '00'x,                       crlfRC ':' crlf '00'x  if bootDriveRC \= 0 then  do      errorBuffer = bootDrive      RETURN bootDriveRC  end  if poolDirRC \= 0 then      poolDir = bootDrive || delimit"STAF"delimit || serviceName  if delimitRC \= 0 then delimit = '\'  if crlfRC \= 0 then crlf = "0D0A"x  RETURN 0/* End of ResolveStandardVariables *//**************************************************************************//* GetPoolIndex - Returns the index of the specified pool                 *//*                                                                        *//* Accepts: The name of the pool to find                                  *//*                                                                        *//* Returns: The index of the pool (0, if pool no found)                   *//**************************************************************************/GetPoolIndex: PROCEDURE EXPOSE self  parse arg poolName  checkName = TRANSLATE(poolName)  do i = 1 to VAL('POOL.0')      if TRANSLATE(VAL('POOL.'i'.!Name')) = checkName then RETURN i  end  RETURN 0/* End of GetPoolIndex *//*************************************************************//* HandleCreate - Handles resource pool creation requests    *//*                                                           *//* Accepts: Nothing                                          *//*                                                           *//* Returns: Preformatted STAF result string                  *//*************************************************************/HandleCreate:  if trustLevel < 4 then      RETURN MakeSTAFResult(STAFError.!AccessDenied)  poolName = ResolveVariable(OptionValue("POOL"))  poolFile = poolDir || delimit || poolName || ext  description = ResolveVariable(OptionValue("DESCRIPTION"))  /* Verify does not exist */  if STREAM(poolFile, "C", "QUERY DATETIME") \= "" then      RETURN MakeSTAFResult(STAFPoolError.!PoolAlreadyExists, poolName)  /* Create the directory path if needed */  if CreatePath(poolDir, delimit) \= 0 then      RETURN MakeSTAFResult(STAFPoolError.!CreatePoolPath, poolDir)  /* Write the pool data */  call OpenFile poolFile, "write"  if RESULT \= 0 then      RETURN MakeSTAFResult(STAFError.!FileOpenError, poolFile)  call LINEOUT poolFile, poolFileVersion  call LINEOUT poolFile, description  call LINEOUT poolFile, poolName  call STREAM poolFile, "C", "CLOSE"  /* Now update in memory data structures */  call RequestMutexSem  newIndex = VAL('POOL.0', VAL('POOL.0') + 1)  call VAL 'POOL.'newIndex'.!Name', poolName  call VAL 'POOL.'newIndex'.!Description', description  call VAL 'POOL.'newIndex'.!Resource.0', 0  call VAL 'POOL.'newIndex'.!Request.0', 0  call ReleaseMutexSem  RETURN MakeSTAFResult(STAFError.!Ok)/* End of HandleCreate *//*************************************************************//* HandleDelete - Handles resource pool deletion requests    *//*                                                           *//* Accepts: Nothing                                          *//*                                                           *//* Returns: Preformatted STAF result string                  *//*************************************************************/HandleDelete:  if trustLevel < 4 then      RETURN MakeSTAFResult(STAFError.!AccessDenied)  poolName = ResolveVariable(OptionValue("POOL"))  call RequestMutexSem  thePool = GetPoolIndex(poolName)  if thePool = 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFPoolError.!PoolDoesNotExist, poolName)  end  /* Only delete if no pending requests or FORCE specified */  if (VAL('POOL.'thePool'.!Request.0') \= 0) & (OptionTimes("FORCE") = 0) then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFPoolError.!PoolHasPendingRequests, poolName)  end  /* Now delete the pool file */  poolFile = poolDir || delimit || poolName || ext  delRC = SysFileDelete(poolFile)  if delRC \= 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFError.!FileDeleteError, delRC':'poolFile)  end  /* Now move all the data up one index */  do i = thePool to (VAL('POOL.0') - 1)      call VAL 'POOL.'i'.!Name', VAL('POOL.'i+1'.!Name')      call VAL 'POOL.'i'.!Description', VAL('POOL.'i+1'.!Description')      call VAL 'POOL.'i'.!Resource.0', VAL('POOL.'i+1'.!Resource.0')      do j = 1 to VAL('POOL.'i+1'.!Resource.0')          call VAL 'POOL.'i'.!Resource.'j'.!Entry',,                   VAL('POOL.'i+1'.!Resource.'j'.!Entry')          call VAL 'POOL.'i'.!Resource.'j'.!Owner',,                   VAL('POOL.'i+1'.!Resource.'j'.!Owner')      end      call VAL 'POOL.'i'.!Request.0', VAL('POOL.'i+1'.!Request.0')      do j = 1 to VAL('POOL.'i+1'.!Request.0')          call VAL 'POOL.'i'.!Request.'j'.!Owner',,                   VAL('POOL.'i+1'.!Request.'j'.!Owner')      end  end  /* do for each pool index */  call VAL 'POOL.0', VAL('POOL.0') - 1  /* Pulse the EVENT semaphore and release the mutex sem */  STAFRC = STAFSubmit("LOCAL", "SEM", "EVENT" eventSemName "PULSE")  call ReleaseMutexSem  RETURN MakeSTAFResult(STAFRC, STAFResult)/* End of HandleDelete *//*************************************************************//* HandleQuery - Handles resource pool query requests        *//*                                                           *//* Accepts: Nothing                                          *//*                                                           *//* Returns: Preformatted STAF result string                  *//*************************************************************/HandleQuery:  if trustLevel < 2 then      RETURN MakeSTAFResult(STAFError.!AccessDenied)  poolName = ResolveVariable(OptionValue("POOL"))  call RequestMutexSem  thePool = GetPoolIndex(poolName)  if thePool = 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFPoolError.!PoolDoesNotExist, poolName)  end  POOLResult = crlf  POOLResult = crlf'Description:',               VAL('POOL.'thePool'.!Description') || crlf || crlf  POOLResult = POOLResult'Pending requests:',               VAL('POOL.'thePool'.!Request.0') || crlf || crlf  do i = 1 to VAL('POOL.'thePool'.!Request.0')      POOLResult = POOLResult'Request' i':',                   SUBSTR(VAL('POOL.'thePool'.!Request.'i'.!Owner'), 2) || crlf  end  if VAL('POOL.'thePool'.!Request.0') > 0 then      POOLResult = POOLResult || crlf  POOLResult = POOLResult'Resources:' crlf || crlf  do i = 1 to VAL('POOL.'thePool'.!Resource.0')      POOLResult = POOLResult || VAL('POOL.'thePool'.!Resource.'i'.!Entry') ||,                   VAL('POOL.'thePool'.!Resource.'i'.!Owner') || crlf  end  call ReleaseMutexSem  RETURN MakeSTAFResult(STAFError.!Ok, POOLResult)/* End of HandleQuery *//*************************************************************//* HandleRequest - Handles resource pool request requests    *//*                                                           *//* Accepts: Nothing                                          *//*                                                           *//* Returns: Preformatted STAF result string                  *//*************************************************************/HandleRequest:  if trustLevel < 3 then      RETURN MakeSTAFResult(STAFError.!AccessDenied)  poolName = ResolveVariable(OptionValue("POOL"))  if OptionTimes("FIRST") > 0 then first = 'yes'  else first = 'no'  /* set the timeout variable and, if appropriate, start elapsed timer */  if OptionTimes("TIMEOUT") > 0 then  do      timeout = ResolveVariable(OptionValue("TIMEOUT"))      call TIME 'E'  end  else timeout = ''  iAmPending = 0  /* Begin loop to get an available resource or wait for release event */  do forever      call RequestMutexSem      thePool = GetPoolIndex(poolName)      if thePool = 0 then      do          call ReleaseMutexSem          RETURN MakeSTAFResult(STAFPoolError.!PoolDoesNotExist, poolName)      end      /* Save any available resource indexes in an array ----------------*/      available.0 = 0      if VAL('POOL.'thePool'.!Resource.0') = 0 then      do          call ReleaseMutexSem          RETURN MakeSTAFResult(STAFPoolError.!NoEntriesAvailable, poolName)      end      do i = 1 to VAL('POOL.'thePool'.!Resource.0')          if VAL('POOL.'thePool'.!Resource.'i'.!Owner') = ";Available" then          do              call AddToStem "available.", i              if first = 'yes' then leave  /* only need first available */          end      end      /* We found some available resources */      if available.0 > 0 then      do          /* Get index of random resource */          rindex = RANDOM(1, available.0)          resid = available.rindex          /* I got a resource, so remove me from the pending list */          if iAmPending then              requestedTime = DeletePending()          else

⌨️ 快捷键说明

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