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

📄 stafpool.rxp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 RXP
📖 第 1 页 / 共 3 页
字号:
              requestedTime = DATE('S')'-'TIME()          /* Mark the resource as OWNED  */          call VAL 'POOL.'thePool'.!Resource.'resid'.!Owner',,                   ';Owned;'orgMachine';'orgName';'orgHandle';' ||,                    requestedTime';'DATE('S')'-'TIME()          theEntry = VAL('POOL.'thePool'.!Resource.'resid'.!Entry')          call ReleaseMutexSem          RETURN MakeSTAFResult(STAFError.!Ok, theEntry)      end      else      do          /* No resources available, put me on the pending list */          if \iAmPending then          do              newIndex = VAL('POOL.'thePool'.!Request.0',,                             VAL('POOL.'thePool'.!Request.0') + 1)              call VAL 'POOL.'thePool'.!Request.'newIndex'.!Owner',,                       ';'orgMachine';'orgName';'orgHandle';' ||,                       DATE('S')'-'TIME()              iAmPending = 1          end          /* If timeout, reduce it by the elapsed time */          currTime = TIME('E')          elapsedTime = FORMAT(currTime, , 0) * 1000          if timeout \= '' then timeout = timeout - elapsedTime          /* No timeout specified or some time left on the timeout - so WAIT */          if (timeout > 0) | (timeout = '') then          do              call ReleaseMutexSem              call STAFSubmit "LOCAL", "SEM", "EVENT" eventSemName,                              "WAIT" timeout              if RESULT \= 0 then                  RETURN MakeSTAFResult(RESULT, STAFResult)          end          else          do              /* There is no time left, we timed out */              if iAmPending then call DeletePending              call ReleaseMutexSem              RETURN MakeSTAFResult(STAFError.!Timeout)          end      end /* no resource currently available */  end /* do while */  RETURN MakeSTAFResult(STAFError.!UnknownError)/* End of HandleRequest *//*************************************************************//* HandleAdd - Handles resource pool add entry requests      *//*                                                           *//* Accepts: Nothing                                          *//*                                                           *//* Returns: Preformatted STAF result string                  *//*************************************************************/HandleAdd:  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  dupString = ""  /* Get each entry to be added */  entries.0 = 0  do i = 1 to OptionTimes("ENTRY")      thisEntry = OptionValue("ENTRY", i)      entryFound = 0      do j = 1 to VAL('POOL.'thePool'.!Resource.0') while \entryFound          if thisEntry = VAL('POOL.'thePool'.!Resource.'j'.!Entry') then          do              dupString = dupString || thisEntry || crlf              entryFound = 1          end      end      if \entryFound then call AddToStem "entries.", thisEntry  end  /* Delete the old pool file */  poolFile = poolDir || delimit || poolName || ext  delRC = SysFileDelete(poolFile)  if delRC \= 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFError.!FileDeleteError, delRC':'poolFile)  end  /* Write the new pool file */  call LINEOUT poolFile, poolFileVersion  call LINEOUT poolFile, VAL('POOL.'thePool'.!Name')  call LINEOUT poolFile, VAL('POOL.'thePool'.!Description')  do i = 1 to VAL('POOL.'thePool'.!Resource.0')      call LINEOUT poolFile, VAL('POOL.'thepool'.!Resource.'i'.!Entry')  end  do i = 1 to entries.0      call LINEOUT poolFile, entries.i  end  call STREAM poolFile, 'C', 'CLOSE'  /* Add each entry that is not a duplicate to in-memory data */  do i = (VAL('POOL.'thePool'.!Resource.0') + 1) for entries.0      index = i - VAL('POOL.'thepool'.!Resource.0')      call VAL 'POOL.'thePool'.!Resource.'i'.!Entry', entries.index      call VAL 'POOL.'thePool'.!Resource.'i'.!Owner', ';Available'  end  call VAL 'POOL.'thePool'.!Resource.0', i - 1  /* Pulse the event semaphore                                       */  /* Note: We don't check this RC, as we wouldn't return this to the */  /*       caller anyway                                             */  STAFRC = STAFSubmit("LOCAL", "SEM", "EVENT" eventSemName "PULSE")  call ReleaseMutexSem  if dupString \= "" then      RETURN MakeSTAFResult(STAFPoolError.!EntryAlreadyExists, dupString)  RETURN MakeSTAFResult(STAFError.!Ok)/* End of HandleAdd *//**************************************************************//* HandleRemove - Handles resource pool remove entry requests *//*                                                            *//* Accepts: Nothing                                           *//*                                                            *//* Returns: Preformatted STAF result string                   *//**************************************************************/HandleRemove:  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  if VAL('POOL.'thePool'.!Resource.0') = 0 then  do      /* XXX: This doesn't seem to be the correct behaviour */      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFError.!Ok)  end  /* Get each of the enties to be removed */  notHere = ""  do i = 1 to OptionTimes("ENTRY")      thisEntry = OptionValue("ENTRY", i)      theEntry = 0      do j = 1 to VAL('POOL.'thePool'.!Resource.0') while theEntry = 0          if thisEntry = VAL('POOL.'thePool'.!Resource.'j'.!Entry') then              theEntry = j      end      if (theEntry \= 0) &,         ((VAL('POOL.'thePool'.!Resource.'theEntry'.!Owner') =,              ';Available') | (OptionTimes("FORCE") \= 0)) then      do          numResources = VAL('POOL.'thePool'.!Resource.0')          if theEntry \= numResources then          do              /* Move all the entries below up one */              do j = theEntry to (VAL('POOL.'thePool'.!Resource.0') - 1)                  call VAL 'POOL.'thePool'.!Resource.'j'.!Entry',,                            VAL('POOL.'thePool'.!Resource.'j+1'.!Entry')                  call VAL 'POOL.'thePool'.!Resource.'j'.!Owner',,                            VAL('POOL.'thePool'.!Resource.'j+1'.!Owner')              end          end          call VAL 'POOL.'thePool'.!Resource.0', numResources - 1      end      else      do          notHere = notHere || thisEntry || crlf      end  end  /* do for each entry specified */  /* Delete the old pool file */  poolFile = poolDir || delimit || poolName || ext  /* XXX: Should check this retCode, but we have already updated in-memory */  /*      data                                                             */  call SysFileDelete poolFile  /* Write the new pool file */  call LINEOUT poolFile, poolFileVersion  call LINEOUT poolFile, VAL('POOL.'thePool'.!Name')  call LINEOUT poolFile, VAL('POOL.'thePool'.!Description')  do i = 1 to VAL('POOL.'thePool'.!Resource.0')      call LINEOUT poolFile, VAL('POOL.'thePool'.!Resource.'i'.!Entry')  end  call STREAM poolFile, 'C', 'CLOSE'  call ReleaseMutexSem  if notHere \= "" then      RETURN MakeSTAFResult(STAFPoolError.!EntryDoesNotExist, notHere)  RETURN MakeSTAFResult(STAFError.!Ok)/* End of HandleRemove *//****************************************************************//* HandleRelease - Handles resource pool release entry requests *//*                                                              *//* Accepts: Nothing                                             *//*                                                              *//* Returns: Preformatted STAF result string                     *//****************************************************************/HandleRelease:  if trustLevel < 3 then      RETURN MakeSTAFResult(STAFError.!AccessDenied)  poolName = ResolveVariable(OptionValue("POOL"))  releaseEntry = ResolveVariable(OptionValue("ENTRY"))  call RequestMutexSem  thePool = GetPoolIndex(poolName)  if thePool = 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFPoolError.!PoolDoesNotExist, poolName)  end  /*  Find the entry */  theEntry = 0  do i = 1 to VAL('POOL.'thePool'.!Resource.0') while theEntry = 0      if releaseEntry = VAL('POOL.'thePool'.!Resource.'i'.!Entry') then          theEntry = i  end  if theEntry = 0 then  do      call ReleaseMutexSem      RETURN MakeSTAFResult(STAFPoolError.!EntryDoesNotExist, releaseEntry)  end  /* Isolate the owner section of the resource entry data */  tempString = VAL('POOL.'thePool'.!Resource.'theEntry'.!Owner')  if tempString \= ';Available' then  do      parse var tempString . ';' . ';' oMachine ';' oName ';' oHandle ';' rest      resourceOwner = oMachine';'oName';'oHandle      /* To release, you must be the owner or FORCE must be specified */      if (resourceOwner = orgMachine';'orgName';'orgHandle) |,         (optionTimes("FORCE") > 0) then      do          /* Mark the resource as available */          call VAL 'POOL.'thePool'.!Resource.'theEntry'.!Owner', ';Available'          /* Pulse the event semaphore */          STAFRC = STAFSubmit("LOCAL","SEM", "EVENT" eventSemName "PULSE")          if STAFRC \= 0 then          do              call ReleaseMutexSem              RETURN MakeSTAFResult(STAFRC, STAFResult)          end      end      else      do          call ReleaseMutexSem          RETURN MakeSTAFResult(STAFPoolError.!NotEntryOwner, releaseEntry)      end  end  /* if entry not available */  call ReleaseMutexSem  RETURN MakeSTAFResult(STAFError.!Ok)/* End of HandleRelease *//****************************************************************//* HandleList - Handles resource pool list requests             *//*                                                              *//* Accepts: Nothing                                             *//*                                                              *//* Returns: Preformatted STAF result string                     *//****************************************************************/HandleList:  if trustLevel < 4 then RETURN MakeSTAFResult(STAFError.!AccessDenied)  call RequestMutexSem  out = ""  do i = 1 to VAL('POOL.0')      out = out || VAL('POOL.'i'.!Name') '-' VAL('POOL.'i'.!Description') ||,            crlf  end  call ReleaseMutexSem  RETURN MakeSTAFResult(STAFError.!Ok, out)/* End of HandleList *//****************************************************************//* HandleHelp - Handles resource pool help requests             *//*                                                              *//* Accepts: Nothing                                             *//*                                                              *//* Returns: Preformatted STAF result string                     *//****************************************************************/HandleHelp:  RETURN MakeSTAFResult(STAFError.!Ok,,         "STAF Resource Pool Help"crlf || crlf ||,         "CREATE  POOL <PoolName> DESCRIPTION <Pooltext>"crlf ||,         "DELETE  POOL <PoolName> CONFIRM [FORCE]"crlf ||,         "QUERY   POOL <PoolName>"crlf ||,         "REQUEST POOL <PoolName> [TIMEOUT <Timeout>] [FIRST | RANDOM]"crlf ||,         "ADD     POOL <PoolName> ENTRY <Value> [ENTRY <Value>]"crlf ||,         "REMOVE  POOL <PoolName> ENTRY <Value> [ENTRY <Value>] CONFIRM [FORCE]"crlf ||,         "RELEASE POOL <PoolName> ENTRY <Value> [FORCE]"crlf ||,         "LIST"crlf ||,         "HELP")/* End of HandleHelp *//********************************//* Now import needed functions. *//********************************/#From STAFPool Import STAFPoolErrorText#From STAFUtil Import All#From STAFCPar Import All#From Misc     Import CreatePath AddToStem OpenFile#From LogMon   Import ResolveVariable

⌨️ 快捷键说明

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