Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.5 KiB

  1. /***************************************************************************\
  2. *
  3. * File: BaseObject.h
  4. *
  5. * Description:
  6. * BaseObject.h defines the "basic object" that provides handle-support
  7. * for all items exposed outside DirectUser.
  8. *
  9. *
  10. * History:
  11. * 11/05/1999: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(BASE__BaseObject_h__INCLUDED)
  17. #define BASE__BaseObject_h__INCLUDED
  18. #pragma once
  19. enum HandleType
  20. {
  21. htNone = 0,
  22. htContext = 1,
  23. htHWndContainer = 2,
  24. htParkContainer = 3,
  25. htNcContainer = 4,
  26. htDxContainer = 5,
  27. htVisual = 6,
  28. htListener = 7,
  29. htTransition = 8,
  30. htAction = 9,
  31. htMsgClass = 10,
  32. htMsgObject = 11,
  33. htMAX
  34. };
  35. enum HandleMask
  36. {
  37. hmMsgObject = 0x00000001,
  38. hmEventGadget = 0x00000002,
  39. hmVisual = 0x00000004,
  40. hmContainer = 0x00000008,
  41. };
  42. /***************************************************************************\
  43. *
  44. * class BaseObject defines an internally referenced counted object that
  45. * provides conversions from HANDLE's to internal pointers.
  46. *
  47. * NOTE: If created objects are ever exposed as reference counted objects,
  48. * they MUST provide a separate reference count for their "handles". There
  49. * is substantial internal code that relies on internal-only reference
  50. * counting.
  51. *
  52. \***************************************************************************/
  53. class BaseObject
  54. {
  55. // Construction
  56. public:
  57. inline BaseObject();
  58. virtual ~BaseObject();
  59. virtual BOOL xwDeleteHandle();
  60. protected:
  61. virtual void xwDestroy();
  62. // Operations
  63. public:
  64. inline HANDLE GetHandle() const;
  65. inline static
  66. BaseObject* ValidateHandle(HANDLE h);
  67. virtual BOOL IsStartDelete() const;
  68. virtual HandleType GetHandleType() const PURE;
  69. virtual UINT GetHandleMask() const PURE;
  70. inline void Lock();
  71. inline BOOL xwUnlock();
  72. typedef void (CALLBACK * FinalUnlockProc)(BaseObject * pobj, void * pvData);
  73. inline BOOL xwUnlockNL(FinalUnlockProc pfnFinal, void * pvData);
  74. // Implementation
  75. protected:
  76. #if DBG
  77. inline void DEBUG_CheckValidLockCount() const;
  78. virtual BOOL DEBUG_IsZeroLockCountValid() const;
  79. public:
  80. virtual void DEBUG_AssertValid() const;
  81. #endif // DBG
  82. // Data
  83. protected:
  84. long m_cRef; // Outstanding locks against object
  85. #if DBG
  86. BOOL m_DEBUG_fDeleteHandle;
  87. static BaseObject* s_DEBUG_pobjEnsure;
  88. #endif // DBG
  89. };
  90. /***************************************************************************\
  91. *****************************************************************************
  92. *
  93. * ObjectLock provides a convenient mechanism of locking a generic Object and
  94. * automatically unlocking when finished.
  95. *
  96. *****************************************************************************
  97. \***************************************************************************/
  98. class ObjectLock
  99. {
  100. public:
  101. inline ObjectLock(BaseObject * pobjLock);
  102. inline ~ObjectLock();
  103. BaseObject * pobj;
  104. };
  105. #include "BaseObject.inl"
  106. #endif // BASE__BaseObject_h__INCLUDED