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.

152 lines
4.3 KiB

  1. /***************************************************************************\
  2. *
  3. * File: BaseObject.cpp
  4. *
  5. * Description:
  6. * BaseObject.cpp implements 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. #include "stdafx.h"
  17. #include "Base.h"
  18. #include "BaseObject.h"
  19. #include "SimpleHeap.h"
  20. /***************************************************************************\
  21. *****************************************************************************
  22. *
  23. * class BaseObject
  24. *
  25. *****************************************************************************
  26. \***************************************************************************/
  27. #if DBG
  28. BaseObject* BaseObject::s_DEBUG_pobjEnsure = NULL;
  29. #endif //DBG
  30. //------------------------------------------------------------------------------
  31. BaseObject::~BaseObject()
  32. {
  33. }
  34. /***************************************************************************\
  35. *
  36. * BaseObject::xwDestroy
  37. *
  38. * In the standard setup, xwDestroy() gets called by xwUnlock() when the lock
  39. * count reaches 0. The object should then call its destructor to free memory
  40. * and resources.
  41. *
  42. * The default implementation will free using the current Context's heap.
  43. * An object MUST override this if it is stored in a pool or uses the
  44. * Process heap.
  45. *
  46. \***************************************************************************/
  47. void
  48. BaseObject::xwDestroy()
  49. {
  50. ClientDelete(BaseObject, this);
  51. }
  52. /***************************************************************************\
  53. *
  54. * BaseObject::xwDeleteHandle
  55. *
  56. * xwDeleteHandle() is called when the application calls ::DeleteHandle() on
  57. * an object.
  58. *
  59. * The default implementation just Unlock's the object. If an object has
  60. * different schemantics, it should override this function.
  61. *
  62. \***************************************************************************/
  63. BOOL
  64. BaseObject::xwDeleteHandle()
  65. {
  66. #if DBG
  67. if (m_DEBUG_fDeleteHandle) {
  68. PromptInvalid("DeleteHandle() was called multiple times on the same object.");
  69. }
  70. m_DEBUG_fDeleteHandle = TRUE;
  71. #endif // DBG
  72. return xwUnlock();
  73. }
  74. /***************************************************************************\
  75. *
  76. * BaseObject::IsStartDelete
  77. *
  78. * IsStartDelete() is called to query an object if it has started its
  79. * destruction process. Most objects will just immediately be destroyed. If
  80. * an object has complicated destruction where it overrides xwDestroy(), it
  81. * should also provide IsStartDelete() to let the application know the state
  82. * of the object.
  83. *
  84. \***************************************************************************/
  85. BOOL
  86. BaseObject::IsStartDelete() const
  87. {
  88. return FALSE;
  89. }
  90. #if DBG
  91. /***************************************************************************\
  92. *
  93. * BaseObject::DEBUG_IsZeroLockCountValid
  94. *
  95. * DEBUG_IsZeroLockCountValid is called to check if an object allows zero
  96. * lock counts, for example during a destruction stage. This is only valid
  97. * if an object has overridden xwDestroy() to provide an implementation that
  98. * checks if the object is currently being destroyed and will return safely.
  99. *
  100. * This is a DEBUG only check because it is used only to Prompt the
  101. * application. The RELEASE code should properly do the "right thing" in its
  102. * xwDestroy() function.
  103. *
  104. * The default implementation is to return FALSE because
  105. * BaseObject::xwDestroy() does not check for existing destruction.
  106. *
  107. \***************************************************************************/
  108. BOOL
  109. BaseObject::DEBUG_IsZeroLockCountValid() const
  110. {
  111. return FALSE;
  112. }
  113. /***************************************************************************\
  114. *
  115. * BaseObject::DEBUG_AssertValid
  116. *
  117. * DEBUG_AssertValid() provides a DEBUG-only mechanism to perform rich
  118. * validation of an object to attempt to determine if the object is still
  119. * valid. This is used during debugging to help track damaged objects
  120. *
  121. \***************************************************************************/
  122. void
  123. BaseObject::DEBUG_AssertValid() const
  124. {
  125. Assert(m_cRef >= 0);
  126. }
  127. #endif // DBG