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

  1. /* $Id: kThreadContainer.cpp,v 1.1 2000/04/29 19:06:35 stknut Exp $
  2.  *
  3.  * kThreadContainer - generic thread container.
  4.  *
  5.  * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  6.  *
  7.  */
  8.  
  9. /*******************************************************************************
  10. *   Defined Constants And Macros                                               *
  11. *******************************************************************************/
  12. #define INCL_WIN
  13. #define INCL_GPI
  14. #define INCL_BASE
  15.  
  16.  
  17. /*******************************************************************************
  18. *   Header Files                                                               *
  19. *******************************************************************************/
  20. #include <os2.h>
  21. #ifdef USE_KLIB
  22.     #include <kAssert.h>
  23.     #include <kLog.h>
  24.     #include <kHeap.h>
  25. #else
  26.     #include <malloc.h>
  27. #endif
  28. #include <memory.h>
  29. #include <string.h>
  30. #include <stddef.h>
  31. #include <stdio.h>
  32.  
  33. #include "kBase.h"
  34. #include "kError.h"
  35. #include "kDlgBase.h"
  36. #include "kMenuBase.h"
  37. #include "kClickDlg.h"
  38. #include "kContainer.h"
  39. #include "kQuerySysState.h"
  40. #include "kThreadRecord.h"
  41. #include "kThreadContainer.h"
  42. #include "kNotebookBase.h"
  43. #include "kTaskMgr.h"
  44. #include "kTaskMgr_defs.h"
  45.  
  46.  
  47. /**
  48.  * Updates the content of the container.
  49.  * @returns   success indicator.
  50.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  51.  */
  52. BOOL   kThreadContainer::insertThreads()
  53. {
  54.     PPROCESSDATA    pProcData;
  55.     int             c;
  56.  
  57.     /*
  58.      * Get process and thread data.
  59.      */
  60.     pProcData = QSGetProcessData(usPid);
  61.     if (pProcData == NULL)
  62.         return FALSE;
  63.  
  64.     /*
  65.      * Process thread information.
  66.      */
  67.     c = pProcData->pProcRec->cTCB;
  68.     if (c > 0 && pProcData->pProcRec->pThrdRec != NULL)
  69.     {
  70.         kThreadRecord  *    pCurCnrRec, *pCnrRec;
  71.         qsTrec_t *          pThread;
  72.         int                 i;
  73.  
  74.         /*
  75.          * Allocate records.
  76.          */
  77.         pCurCnrRec = pCnrRec = (kThreadRecord*)allocMiniRec(sizeof(kThreadRecord), c);
  78.         if (pCurCnrRec == NULL)
  79.             return FALSE;
  80.  
  81.         /*
  82.          * Loop thru the thread data and fill the records.
  83.          */
  84.         pThread = pProcData->pProcRec->pThrdRec;
  85.         for (i = 0; i < c; i++, pCurCnrRec = (kThreadRecord*)pCurCnrRec->getNext(), pThread++)
  86.         {
  87.             //assert(pCurCnrRec != NULL);
  88.             pCurCnrRec->init();
  89.             pCurCnrRec->set(pThread);
  90.         }
  91.  
  92.         /*
  93.          * Insert the records.
  94.          */
  95.         return insertAtBottom(pCnrRec, c);
  96.  
  97.     }
  98.  
  99.     return TRUE;
  100. }
  101.  
  102.  
  103. /**
  104.  * Menu is closing. Remove emphasis.
  105.  * @param     usMenuId  Menu id.
  106.  * @param     hwndMnu   Handle to menu window.
  107.  */
  108. VOID kThreadContainer::menuEnd(USHORT usMenuId, HWND hwndMnu)
  109. {
  110.     setRecordEmphasis(pCurRecord, FALSE, CRA_SOURCE);
  111.     hwndMnu = hwndMnu;
  112.     usMenuId = usMenuId;
  113. }
  114.  
  115.  
  116. /**
  117.  * Command events.
  118.  * @param     usCmd     Control id which send/posted the message.
  119.  * @param     usSource  Source id.
  120.  * @param     fPointer  Mouse pointer flag.
  121.  */
  122. VOID  kThreadContainer::command(USHORT usCmd, USHORT usSource, BOOL fPointer)
  123. {
  124.     switch (usCmd)
  125.     {
  126.         case IDM_CNR_TRD_DETAILS:
  127.             if (pCurRecord)
  128.             {
  129.                 try
  130.                 {
  131.                     //new kThreadDetails(pCurRecord->getPid(), hwndCnr)->show();
  132.                 }
  133.                 catch(kError err)
  134.                 {
  135.                     err.logError();
  136.                     err.showError(kTaskMgr::pszErrorTitle);
  137.                 }
  138.             }
  139.             break;
  140.  
  141.         case IDM_CNR_TRD_ALL_REFRESH:
  142.             update();
  143.             break;
  144.     }
  145.  
  146.     usSource = usSource;
  147.     fPointer = fPointer;
  148. }
  149.  
  150.  
  151.  
  152. /**
  153.  * Constructor.
  154.  * @returns
  155.  * @param     hwndDlg   Handle to dialog window.
  156.  * @param     ulCnrId   ID of the container dialog item in hwndDlg.
  157.  * @param     usPid     Process Indicator for the process we're to get thread information for.
  158.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  159.  */
  160. kThreadContainer::kThreadContainer(HWND hwndDlg, ULONG ulCnrId, USHORT usPid) throw(kError)
  161.     : kDetailCnr(WinWindowFromID(hwndDlg, ulCnrId),
  162.                  0,
  163.                  "Thread Overview",
  164.                  kThreadRecord::cFieldInfo,
  165.                  (PFIELDINFO)&kThreadRecord::aFieldInfo[0]),
  166.     usPid(usPid), pCurRecord(NULL)
  167. {
  168.     /*
  169.      * Create menus.
  170.      */
  171.     pMenuThread = new kMenuBase(IDM_CNR_THREAD, NULLHANDLE, hwndCnr, TRUE);
  172.     pMenuCnrAll = new kMenuBase(IDM_CNR_THREAD_ALL, NULLHANDLE, hwndCnr, TRUE);
  173. }
  174.  
  175.  
  176. /**
  177.  * Destructor.
  178.  */
  179. kThreadContainer::~kThreadContainer()
  180. {
  181.     if (pMenuThread != NULL)
  182.         delete pMenuThread;
  183.     if (pMenuCnrAll != NULL)
  184.         delete pMenuCnrAll;
  185. }
  186.  
  187.  
  188. /**
  189.  * Displays the popup menu for the container.
  190.  * @param     usId     Container id.
  191.  * @param     pRecord  Pointer to the record which is selected by either the key
  192.  */
  193. VOID kThreadContainer::cnrContextMenu(USHORT usId, PRECORDCORE pRecord)
  194. {
  195.     if (pMenuThread && pMenuCnrAll)
  196.     {
  197.         pCurRecord = (kThreadRecord*)pRecord;
  198.         setRecordEmphasis(pCurRecord, TRUE, CRA_SOURCE);
  199.         if (pRecord != NULL)
  200.             pMenuThread->popup();
  201.         else
  202.             pMenuCnrAll->popup();
  203.     }
  204.     usId = usId;
  205. }
  206.  
  207.  
  208. /**
  209.  * Enter or double click on record in the container.
  210.  * This action will bring up the detail dialog for the record - Not Implemented.
  211.  */
  212. VOID kThreadContainer::cnrEnter(USHORT usId, HWND hwndCnr, PRECORDCORE pRecord, ULONG fKey)
  213. {
  214.     if (pRecord != NULL)
  215.     {
  216.         pCurRecord = (kThreadRecord*)pRecord;
  217.         /*
  218.          todo...
  219.          */
  220.     }
  221.     usId = usId;
  222.     fKey = fKey;
  223.     hwndCnr = hwndCnr;
  224. }
  225.  
  226.  
  227.  
  228. /**
  229.  * Updates the contents of the container.
  230.  * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
  231.  */
  232. VOID  kThreadContainer::update()
  233. {
  234.     /*
  235.      * Delete all records in the container!
  236.      */
  237.     removeAllRecords();
  238.  
  239.     /*
  240.      * Insert records
  241.      */
  242.     insertThreads();
  243. }
  244.  
  245.