home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Profiler / heapmon / objview.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  7.7 KB  |  263 lines

  1. // objview.hpp
  2. //
  3. // Created 10/08/98
  4. //
  5. // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. #ifndef __OBJVIEW_HPP__
  9. #define __OBJVIEW_HPP__
  10.  
  11. #include "baseview.hpp"
  12.  
  13. class ANSIStringBuffer;
  14.  
  15.  
  16. #define WC_HEAPMONITOR_OBJVIEWER "JavaHeapMonitor_ObjectViewerClass"
  17.  
  18.  
  19. enum ObjectViewerEvents
  20. {
  21.     WM_OVEVENT_FIRST = WM_BC_LAST,
  22.     
  23.     WM_OVEVENT_OBJECT_CHANGE = WM_OVEVENT_FIRST,
  24.  
  25.     WM_OVEVENT_PERMIT_EXPANSION,
  26.  
  27.     WM_OVEVENT_CLEAR_TRANSIENTS,
  28.  
  29.     WM_OVEVENT_LAST
  30. };
  31.  
  32.  
  33. // Displays a suspended heap in a split-pane window: a tree control allows
  34. // navigation of the heap, while a text pane displays details about the
  35. // selected object.  The heap is navigated a single level at a time using
  36. // GetObjectField, as the user expands the node for the object.  The 'iImage'
  37. // tree item field is overloaded to also be an enumeration indicating the
  38. // underlying type of the node.  This enumeration is used to interpret the
  39. // associated lParam.
  40. //
  41. // Derivatives must populate the tree.  This class only deals with object
  42. // and ID nodes - any other types are ignored.
  43.  
  44. class ObjectViewer : public BasicClient
  45. {
  46. protected:
  47.  
  48.     static BOOL s_fRegisteredClass;
  49.  
  50.     // TreeView, left pane
  51.     HWND m_htree;
  52.     // right pane, contains description of selected item in left pane
  53.     HWND m_htext;
  54.     // client area of mdi client between panes
  55.     LONG m_sliderleft;
  56.     LONG m_sliderright;
  57.     LONG m_sliderwid;
  58.  
  59.  
  60.     //------------------------------------------------------------------------
  61.     // UI manipulation
  62.  
  63.     BOOL MoveSlider (LPARAM lParam);
  64.     VOID ClearText ();
  65.  
  66.     static LRESULT CALLBACK _WndProc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
  67.  
  68.     virtual LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
  69.  
  70.     BOOL OnCreateWindow ();
  71.  
  72.     virtual BOOL OnRightClickItem (ID id, UniqueID vmid, HWND wnd, DWORD screenpos);
  73.     virtual BOOL GetItemText (HTREEITEM hti, PSTR &psztext, int &cchmaxtext);
  74.     virtual BOOL GetItemDetailText (HTREEITEM hti, ANSIStringBuffer *pbuf);
  75.  
  76.  
  77.     //------------------------------------------------------------------------
  78.     // Tree-specific stuff
  79.  
  80.     VOID RedrawTree ()
  81.     {
  82.         InvalidateRect(m_htree, NULL, TRUE);
  83.         UpdateWindow(m_htree);
  84.     }
  85.  
  86.     // These are the indices into IDB_TREEIMAGES, and also serve to identify
  87.     // the type of the tree item's lParam.
  88.     enum ObjectViewerTreeItemTypes
  89.     {
  90.         // ObjectID (default if no image set)
  91.         HVTII_OBJECT                    = 0,
  92.         
  93.         // OBJID
  94.         HVTII_OBJID                     = 1,
  95.         
  96.         // OBJID, OID_FL_TRACKED set
  97.         HVTII_TRACKED_OBJID             = 2,
  98.         
  99.         // OBJID, OID_FL_MULTIPLE_REFERENCES set
  100.         HVTII_MULTIREF_OBJID            = 3,
  101.         
  102.         // OBJID, both OID_FL_MULTIPLE_REFERENCES and OID_FL_TRACKED set
  103.         HVTII_MULTIREF_TRACKED_OBJID    = 4,
  104.  
  105.         // OBJID
  106.         HVTII_DEAD_OBJID                = 5,
  107.  
  108.         HVTII_LAST_OBJID                = HVTII_DEAD_OBJID,
  109.         
  110.         // (none)
  111.         HVTII_FOLDER                    = 6,
  112.  
  113.         // PSTR
  114.         HVTII_UNLOADED_CLASS            = 7,
  115.  
  116.         // PSTR
  117.         HVTII_DEAD_THREAD               = 8,
  118.  
  119.         // ID
  120.         HVTII_FIRST_ID                  = 9,
  121.  
  122.         // Remaining images are for HVTII_FIRST_ID + IDType.
  123.     };
  124.  
  125.     static BOOL IsObjectType (ObjectViewerTreeItemTypes type)
  126.     {
  127.         return type <= HVTII_DEAD_OBJID;
  128.     }
  129.  
  130.     static ObjectViewerTreeItemTypes GetTreeItemTypeForID (ID id);
  131.  
  132.     BOOL GetTreeItemTypeInfo (HTREEITEM hti, ObjectViewerTreeItemTypes *ptype, PVOID *ptoken);
  133.  
  134.     HTREEITEM AddTreeItem (HTREEITEM htiParent, HTREEITEM htiafter, ObjectViewerTreeItemTypes type, PVOID token);
  135.     HTREEITEM AddTreeItem (HTREEITEM htiParent, ObjectViewerTreeItemTypes type, PVOID token);
  136.     HTREEITEM AddTreeItemForID (HTREEITEM htiParent, ID id, BOOL fPermitDuplicates = FALSE);
  137.     HTREEITEM AddTreeItemForID (HTREEITEM htiParent, HTREEITEM htiAfter, ID id, BOOL fPermitDuplicates = FALSE);
  138.     HTREEITEM AddTreeItemForReferencedID (HTREEITEM htiParent, ID id);
  139.     HTREEITEM AddTreeItemForReferencedID (HTREEITEM htiParent, HTREEITEM htiAfter, ID id, BOOL fPermitDuplicates = FALSE);
  140.     HTREEITEM AddStaticTreeItem (HTREEITEM htiParent, PCSTR text, ObjectViewerTreeItemTypes img);
  141.     HTREEITEM AddTreeItemForObject (HTREEITEM htiParent, ObjectID vmid);
  142.  
  143.     VOID DeleteTreeItem (HTREEITEM hti);
  144.  
  145.     BOOL WalkTree (DWORD flags, PWALKTREECBFN pfn, PVOID token);
  146.  
  147.     HTREEITEM FindChildItemForID (HTREEITEM htiParent, ID id);
  148.  
  149.     HTREEITEM FindNextSiblingForID (HTREEITEM htichild, ID id);
  150.  
  151.     HTREEITEM CreateRoot (HTREEITEM *proot, PCSTR name, ObjectViewerTreeItemTypes img);
  152.  
  153.     // Subclasses override to decide whether or not a node for the given
  154.     // object should be retained after execution resumes.  If returns FALSE,
  155.     // the node will be kept, but its expand button will be removed.
  156.     virtual BOOL ShouldDeleteTransientObject (HTREEITEM hti, OBJID obj);
  157.  
  158.  
  159.     //------------------------------------------------------------------------
  160.     // Object node operations
  161.  
  162.     // callback data for AddObjectIDReferences and AddOBJIDReferences
  163.     struct AddReferencesInfo
  164.     {
  165.         ObjectViewer *ov;
  166.         HTREEITEM hti;
  167.     };
  168.  
  169.     static int AddObjectIDReferences (ObjectID vmid, PVOID /*AddReferencesInfo*/ token);
  170.     static int AddOBJIDReferences (OBJID id, PVOID /*AddReferencesInfo*/ token);
  171.  
  172.     static WalkTreeCBResults UpdateObjectStatusCB (HWND htree, HTREEITEM hti, PVOID token);
  173.  
  174.     BOOL FindObjectReferences (ObjectID vmid);
  175.  
  176.     VOID ToggleObjectTracking (OBJID obj, ObjectID vmid);
  177.  
  178.     VOID TagObject (ObjectID vmid);
  179.  
  180.  
  181.     //------------------------------------------------------------------------
  182.  
  183.     // IHeapMonitorClient methods
  184.  
  185.     static WalkTreeCBResults DeleteTransientItemsCB (HWND htree, HTREEITEM hti, PVOID token);
  186.     static WalkTreeCBResults PermitItemExpansionCB (HWND htree, HTREEITEM hti, PVOID token);
  187.  
  188.     STDMETHODIMP OnStoppedExecution ()
  189.     {
  190.         SendMessage(m_hwnd, WM_OVEVENT_PERMIT_EXPANSION, 0, 0);
  191.         return S_OK;
  192.     }
  193.  
  194.     STDMETHODIMP OnResumeExecution ()
  195.     {
  196.         SendMessage(m_hwnd, WM_OVEVENT_CLEAR_TRANSIENTS, 0, 0);
  197.         return S_OK;
  198.     }
  199.     
  200.     STDMETHODIMP OnThreadCreated (THREADID thread)
  201.     {
  202.         return S_OK;
  203.     }
  204.  
  205.     STDMETHODIMP OnDestroyThread (THREADID thread)
  206.     {
  207.         return S_OK;
  208.     }
  209.  
  210.     STDMETHODIMP OnPackageCreated (PKGID pkg)
  211.     {
  212.         return S_OK;
  213.     }
  214.  
  215.     STDMETHODIMP OnClassLoaded (CLASSID cls)
  216.     {
  217.         return S_OK;
  218.     }
  219.     
  220.     STDMETHODIMP OnUnloadClass (CLASSID cls)
  221.     {
  222.         return S_OK;
  223.     }
  224.  
  225.     STDMETHODIMP RootReferences (RootReferencesEventInfo *pinfo)
  226.     {
  227.         return S_OK;
  228.     }
  229.  
  230.     STDMETHODIMP OnObjectStatusChange (OBJID id)
  231.     {
  232.         SendMessage(m_hwnd, WM_OVEVENT_OBJECT_CHANGE, 0, (LPARAM)id);
  233.         return S_OK;
  234.     }
  235.  
  236.     STDMETHODIMP RootDiscoveryComplete ()
  237.     {
  238.         return S_OK;
  239.     }
  240.  
  241.     STDMETHODIMP ObjectDiscoveryComplete ()
  242.     {
  243.         return S_OK;
  244.     }
  245.  
  246.  
  247.     //------------------------------------------------------------------------
  248.     // Initialization
  249.  
  250.     BOOL OVPreInitialize (HeapMonitorManager *mgr, PCSTR wndtitle);
  251.     BOOL OVPostInitialize (HeapMonitorClientRegistrationInfo *preginfo);
  252.  
  253.     BOOL OVInitialize (HeapMonitorManager *mgr, PCSTR wndtitle, HeapMonitorClientRegistrationInfo *preginfo = NULL)
  254.     {
  255.         return    OVPreInitialize(mgr, wndtitle)
  256.                && OVPostInitialize(preginfo);
  257.     }
  258. };
  259.  
  260.  
  261. #endif /* __OBJVIEW_HPP__ */
  262.  
  263.