home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxprior.zip / rxprior.c < prev    next >
Text File  |  1994-01-18  |  6KB  |  172 lines

  1. /*--------------------------------------------------------------------
  2.    Copyright IBM Corp., 1993,1994.  All Rights Reserved.
  3.  
  4.    OS/2 is a registered trademark of the IBM Corp.
  5.  
  6.    While the information provided herein is believed to be accurate, IBM
  7.    does not warrant the information, and the information is provided "as
  8.    is".
  9. ---------------------------------------------------------------------*/
  10.  
  11. /*------------------------------------------------------------------
  12.  * rxprior.c : external rexx function to set priority
  13.  *------------------------------------------------------------------*/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #define INCL_BASE
  20. #include <os2.h>
  21.  
  22. #define INCL_REXXSAA
  23. #include <rexxsaa.h>
  24.  
  25. /*------------------------------------------------------------------
  26.  * prototypes for rexx functions, to make sure we declared everything
  27.  * correctly
  28.  *------------------------------------------------------------------*/
  29.  
  30. RexxFunctionHandler SysSetPriority;
  31. RexxFunctionHandler SysGetPriority;
  32.  
  33. #pragma linkage(SysSetPriority, system)
  34. #pragma linkage(SysGetPriority, system)
  35.  
  36. /*------------------------------------------------------------------
  37.  * this function is called when user invokes SysGetPriority() in REXX
  38.  *
  39.  * expects no parameters
  40.  *------------------------------------------------------------------*/
  41. ULONG APIENTRY SysGetPriority(
  42.    PUCHAR     pszName,
  43.    ULONG      ulArgc,
  44.    PRXSTRING  prxArgv,
  45.    PSZ        pszQueueName,
  46.    PRXSTRING  prxRet
  47.    )
  48.    {
  49.    PPIB   ppib;
  50.    PTIB   ptib;
  51.    APIRET rc;
  52.  
  53.    /*---------------------------------------------------------------
  54.     * call DosGetInfoBlocks()
  55.     *---------------------------------------------------------------*/
  56.    rc = DosGetInfoBlocks(&ptib,&ppib);
  57.  
  58.    /*---------------------------------------------------------------
  59.     * put priority in return code
  60.     *---------------------------------------------------------------*/
  61.    sprintf(prxRet->strptr,"%08.8lx",ptib->tib_ptib2->tib2_ulpri);
  62.    prxRet->strlength = strlen(prxRet->strptr);
  63.  
  64.    return 0;
  65.    }
  66.  
  67. /*------------------------------------------------------------------
  68.  * this function is called when user invokes SysSetPriority() in REXX
  69.  *
  70.  * expects the following parameters
  71.  *    1 - number between -31 and 31, the delta of the priority to set
  72.  *    2 - optional class: "NOCHANGE", "IDLETIME", "REGULAR",
  73.  *                        "TIMECRITICAL", "FOREGROUNDSERVER"
  74.  *    3 - option scope: "PROCESS", "PROCESSTREE", "THREAD"
  75.  *
  76.  *------------------------------------------------------------------*/
  77. ULONG APIENTRY SysSetPriority(
  78.    PUCHAR     pszName,
  79.    ULONG      ulArgc,
  80.    PRXSTRING  prxArgv,
  81.    PSZ        pszQueueName,
  82.    PRXSTRING  prxRet
  83.    )
  84.    {
  85.    APIRET     rc;
  86.    PSZ        pszDelta;
  87.    PSZ        pszClass;
  88.    PSZ        pszScope;
  89.    ULONG      ulScope;
  90.    ULONG      ulClass;
  91.    LONG       lDelta;
  92.  
  93.    /*---------------------------------------------------------------
  94.     * make sure there are 1, 2 or 3 parameters
  95.     *---------------------------------------------------------------*/
  96.    if ((ulArgc < 1) || (ulArgc > 3))
  97.       return 40;
  98.  
  99.    /*---------------------------------------------------------------
  100.     * apply default parameters
  101.     *---------------------------------------------------------------*/
  102.    if (RXVALIDSTRING(prxArgv[0]))
  103.       pszDelta = prxArgv[0].strptr;
  104.    else
  105.       pszDelta = "0";
  106.  
  107.    if ((ulArgc >= 2) && RXVALIDSTRING(prxArgv[1]))
  108.       pszClass = prxArgv[1].strptr;
  109.    else
  110.       pszClass = "NOCHANGE";
  111.  
  112.    if ((ulArgc >= 3) && RXVALIDSTRING(prxArgv[2]))
  113.       pszScope = prxArgv[2].strptr;
  114.    else
  115.       pszScope = "PROCESS";
  116.  
  117.    /*---------------------------------------------------------------
  118.     * convert delta to a number
  119.     *---------------------------------------------------------------*/
  120.    lDelta = strtol(pszDelta,NULL,10);
  121.  
  122.    /*---------------------------------------------------------------
  123.     * convert class to a pre-defined constant
  124.     *---------------------------------------------------------------*/
  125.    if      (!stricmp(pszClass, "NOCHANGE"))
  126.       ulClass =           PRTYC_NOCHANGE;
  127.  
  128.    else if (!stricmp(pszClass, "IDLETIME"))
  129.       ulClass =           PRTYC_IDLETIME;
  130.  
  131.    else if (!stricmp(pszClass, "REGULAR"))
  132.       ulClass =           PRTYC_REGULAR;
  133.  
  134.    else if (!stricmp(pszClass, "TIMECRITICAL"))
  135.       ulClass =           PRTYC_TIMECRITICAL;
  136.  
  137.    else if (!stricmp(pszClass, "FOREGROUNDSERVER"))
  138.       ulClass =           PRTYC_FOREGROUNDSERVER;
  139.  
  140.    else
  141.       ulClass = PRTYC_NOCHANGE;
  142.  
  143.    /*---------------------------------------------------------------
  144.     * convert scope to a pre-defined constant
  145.     *---------------------------------------------------------------*/
  146.    if      (!stricmp(pszScope, "PROCESS"))
  147.       ulScope =           PRTYS_PROCESS;
  148.  
  149.    else if (!stricmp(pszScope, "PROCESSTREE"))
  150.       ulScope =           PRTYS_PROCESSTREE;
  151.  
  152.    else if (!stricmp(pszScope, "THREAD"))
  153.       ulScope =           PRTYS_THREAD;
  154.  
  155.    else
  156.       ulScope = PRTYS_PROCESS;
  157.  
  158.    /*---------------------------------------------------------------
  159.     * call the DosSetPriority() function
  160.     *---------------------------------------------------------------*/
  161.    rc = DosSetPriority(ulScope,ulClass,lDelta,0);
  162.  
  163.    /*---------------------------------------------------------------
  164.     * set return value
  165.     *---------------------------------------------------------------*/
  166.    sprintf(prxRet->strptr,"%ld",rc);
  167.    prxRet->strlength = strlen(prxRet->strptr);
  168.  
  169.    return 0;
  170.    }
  171.  
  172.