home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / taman002.zip / TASKMANA.ZIP / src / kProcessPriority.cpp < prev    next >
C/C++ Source or Header  |  2000-04-29  |  8KB  |  258 lines

  1. /* $Id: kProcessPriority.cpp,v 1.1 2000/04/29 19:06:35 stknut Exp $
  2.  *
  3.  * kProcessPriority (kTaskMgr) - Change Process Priority dialog.
  4.  *
  5.  * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  6.  *
  7.  */
  8. /*******************************************************************************
  9. *   Defined Constants And Macros                                               *
  10. *******************************************************************************/
  11. #define INCL_DOS
  12. #define INCL_DOSERRORS
  13. #define INCL_WIN
  14.  
  15.  
  16. /*******************************************************************************
  17. *   Header Files                                                               *
  18. *******************************************************************************/
  19. #include <os2.h>
  20. #ifdef USE_KLIB
  21.     #include <kAssert.h>
  22.     #include <kLog.h>
  23.     #include <kHeap.h>
  24. #endif
  25. #include <stdio.h>
  26.  
  27. #include "kBase.h"
  28. #include "kError.h"
  29. #include "kDlgBase.h"
  30. #include "kMenuBase.h"
  31. #include "kContainer.h"
  32. #include "kNotebookPageBase.h"
  33. #include "kNotebookBase.h"
  34.  
  35. #include "kQuerySysState.h"
  36.  
  37. #include "kThreadRecord.h"
  38. #include "kThreadContainer.h"
  39. #include "kProcessPriority.h"
  40. #include "kTaskMgr_Defs.h"
  41. #include "kTaskMgr.h"
  42.  
  43.  
  44.  
  45. /**
  46.  * Forwards this event to the correct container.
  47.  * @param     usId     Container id.
  48.  * @param     pRecord  Pointer to the record which is selected by either the key
  49.  */
  50. VOID kProcessPriority::cnrContextMenu(USHORT usId, PRECORDCORE pRecord)
  51. {
  52.     if (usId == KPROCPRTY_CNR_THREADS)
  53.         pCnrThreads->cnrContextMenu(usId, pRecord);
  54. }
  55.  
  56.  
  57. /**
  58.  * Forwards this event to the correct container.
  59.  */
  60. VOID kProcessPriority::cnrEnter(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, ULONG fKey)
  61. {
  62.     if (usId == KPROCPRTY_CNR_THREADS)
  63.         pCnrThreads->cnrEnter(usId, hwndCnr, pRecord, fKey);
  64. }
  65.  
  66.  
  67. /**
  68.  * WM_DESTROY.
  69.  * We'll simply delete this object.
  70.  */
  71. VOID  kProcessPriority::destroy()
  72. {
  73.     delete this;
  74. }
  75.  
  76.  
  77. /**
  78.  * Command event handler.
  79.  * This method processes the DID_OK and DID_CANCEL command events.
  80.  * @param     usCmd     Control id which send/posted the message.
  81.  * @param     usSource  Source id.
  82.  * @param     fPointer  Mouse pointer flag.
  83.  */
  84. VOID kProcessPriority::command(USHORT usCmd, USHORT usSource, BOOL fPointer)
  85. {
  86.     switch (usCmd)
  87.     {
  88.         case DID_OK:
  89.         {
  90.             APIRET  rc;
  91.             LONG    lDelta;
  92.             ULONG   ulClass;
  93.             CHAR    szBuffer[256];
  94.  
  95.             /*
  96.              * Start off by collecting data.
  97.              */
  98.             ulClass = (ULONG)WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_QUERYSELECTION, (MPARAM)LIT_FIRST, NULL);
  99.             if (ulClass == (ULONG)LIT_NONE)
  100.             {
  101.                 //TODO: complain!
  102.                 break;
  103.             }
  104.  
  105.             if (!(BOOL)WinSendDlgItemMsg(hwnd, KPROCPRTY_SPB_DELTA, SPBM_QUERYVALUE, &lDelta, 0))
  106.             {
  107.                 //TODO: complain!
  108.                 break;
  109.             }
  110.  
  111.  
  112.             /*
  113.              * ARG! TODO! FIXME!
  114.              *
  115.              * This didn't seem to work as we're only allowed to change priority on child processes.
  116.              * But, this might turn out as a feature in win32k.sys some time the future.
  117.              *
  118.              * ARG! TODO! FIXME!
  119.              */
  120.             rc = DosSetPriority(PRTYS_PROCESSTREE, ulClass, lDelta, usPid);
  121.             sprintf(szBuffer, "Changed priority to: ulClass=%d, lDelta=%d, rc=%d\n",
  122.                     ulClass, lDelta, rc);
  123.             WinMessageBox(HWND_DESKTOP, hwnd,szBuffer, "kTaskMgr - Info", 0, MB_OK | MB_INFORMATION);
  124.             break;
  125.         }
  126.  
  127.         case DID_CANCEL:
  128.             close();
  129.             break;
  130.     }
  131.  
  132.     /* unreferenced */
  133.     usSource = usSource;
  134.     fPointer = fPointer;
  135. }
  136.  
  137.  
  138. /**
  139.  * Process change priority dialog.
  140.  * NOTE: This dialog is currently an simple interface to DosSetPriority.
  141.  * @param     usPid        Process identifier of the process requested priority change for.
  142.  * @param     hwndOwner    Handle of the owner.
  143.  */
  144. kProcessPriority::kProcessPriority(USHORT usPid, HWND hwndOwner) throw(kError)
  145.   : kDlgBase(DL_KPROCESS_CHANGE_PRIORITY, NULLHANDLE, NULLHANDLE, HWND_DESKTOP),
  146.     hwndOwner(hwndOwner), pCnrThreads(NULL), usPid(usPid)
  147. {
  148.     CHAR            szBuffer[256];
  149.     PPROCESSDATA    pProcData;
  150.     qsLrec_t *      pMteRec;
  151.  
  152.     /* Find process data. */
  153.     pProcData = QSGetProcessData(usPid);
  154.     if (pProcData == NULL)
  155.         throw(kError(ERROR_INVALID_PARAMETER, kError::dos));
  156.  
  157.     /* Find hMte record */
  158.     pMteRec = QSGetMteData(pProcData->pProcRec->hMte);
  159.     if (pMteRec == NULL)
  160.         throw(kError(ERROR_INVALID_PARAMETER, kError::dos));
  161.  
  162.     /*
  163.      * Set title.
  164.      */
  165.     sprintf(&szBuffer[0], "PID %04x - %.240s",
  166.             usPid, pMteRec->pName);
  167.     setTitle(&szBuffer[0]);
  168.  
  169.  
  170.     /*
  171.      * Initiate combo box.
  172.      */
  173.     WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_INSERTITEM, (MPARAM)PRTYC_NOCHANGE,          "No change");
  174.     WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_INSERTITEM, (MPARAM)PRTYC_IDLETIME,          "Idletime Priority Class");
  175.     WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_INSERTITEM, (MPARAM)PRTYC_REGULAR,           "Regular Priority Class");
  176.     WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_INSERTITEM, (MPARAM)PRTYC_TIMECRITICAL,      "Timecritical Priority Class");
  177.     WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_INSERTITEM, (MPARAM)PRTYC_FOREGROUNDSERVER,  "Foregroundserver Priority Class");
  178.     if (pProcData->pProcRec->pThrdRec != NULL)
  179.         WinSendDlgItemMsg(hwnd, KPROCPRTY_CB_CLASS, LM_SELECTITEM,
  180.                           (MPARAM)(pProcData->pProcRec->pThrdRec->priority >> 8),
  181.                           (MPARAM)TRUE);
  182.     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, KPROCPRTY_CB_CLASS));
  183.  
  184.  
  185.     /*
  186.      * Initiate spinbutton.
  187.      */
  188.     WinSendDlgItemMsg(hwnd, KPROCPRTY_SPB_DELTA, SPBM_SETLIMITS, (MPARAM)PRTYD_MAXIMUM, (MPARAM)PRTYD_MINIMUM);
  189.     if (pProcData->pProcRec->pThrdRec != NULL)
  190.         WinSendDlgItemMsg(hwnd, KPROCPRTY_SPB_DELTA, SPBM_SETCURRENTVALUE,
  191.                           (MPARAM)(pProcData->pProcRec->pThrdRec->priority & 0xFF), NULL);
  192.  
  193.  
  194.     /*
  195.      * Create the container
  196.      */
  197.     pCnrThreads     = new kThreadContainer(hwnd, KPROCPRTY_CNR_THREADS, usPid);
  198.  
  199.     /*
  200.      * Set dialog data.
  201.      */
  202.     update();
  203. }
  204.  
  205.  
  206. /**
  207.  * Destructor stub.
  208.  */
  209. kProcessPriority::~kProcessPriority()
  210. {
  211.     if (pCnrThreads)
  212.         delete pCnrThreads;
  213. }
  214.  
  215.  
  216.  
  217. /**
  218.  * Update function - update dialog contents.
  219.  * @returns   Success indicator.
  220.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  221.  */
  222. BOOL kProcessPriority::update()
  223. {
  224.     PPROCESSDATA    pProcData;
  225.     qsLrec_t *      pMteRec;
  226.  
  227.  
  228.     /* Find process data. */
  229.     pProcData = QSGetProcessData(usPid);
  230.     if (pProcData == NULL)
  231.         throw(kError(ERROR_INVALID_PARAMETER, kError::dos));
  232.  
  233.     /* Find hMte record */
  234.     pMteRec = QSGetMteData(pProcData->pProcRec->hMte);
  235.     if (pMteRec == NULL)
  236.         throw(kError(ERROR_INVALID_PARAMETER, kError::dos));
  237.  
  238.  
  239.     /*
  240.      * Set field contents
  241.      */
  242.     /*
  243.     setDlgItemText(KMODDTL_TXT_HMTE,        "0x%04x",   hMTE);
  244.     setDlgItemText(KMODDTL_TXT_MODEL,       pMteRec->fFlat ? "32-bit (LX)" : "16-bit (NE)");
  245.     setDlgItemText(KMODDTL_TXT_COBJECTS,    "%d (0x%x)", pMteRec->ctObj, pMteRec->ctObj);
  246.     setDlgItemText(KMODDTL_TXT_CIMPMODULES, "%d (0x%x)", pMteRec->ctImpMod, pMteRec->ctImpMod);
  247.     setDlgItemText(KMODDTL_TXT_NAME,        "%s",        pMteRec->pName != NULL ? (char*)pMteRec->pName : "<unknown>");
  248.     */
  249.  
  250.     /*
  251.      * Fill the containers.
  252.      */
  253.     pCnrThreads->update();
  254.  
  255.     return TRUE;
  256. }
  257.  
  258.