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.

170 lines
3.6 KiB

  1. //******************************************************************************
  2. //
  3. // EVTOOLS.H
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #ifndef __WMI_ESS_TOOLS__H_
  9. #define __WMI_ESS_TOOLS__H_
  10. #include <sync.h>
  11. #include <deque>
  12. #include <malloc.h>
  13. #include <newnew.h>
  14. #include <eventrep.h>
  15. #include <wstlallc.h>
  16. class CUpdateLockable
  17. {
  18. public:
  19. virtual HRESULT LockForUpdate() = 0;
  20. virtual HRESULT UnlockForUpdate() = 0;
  21. };
  22. class CInUpdate
  23. {
  24. protected:
  25. CUpdateLockable* m_p;
  26. public:
  27. CInUpdate(CUpdateLockable* p) : m_p(p)
  28. {
  29. p->LockForUpdate();
  30. }
  31. ~CInUpdate()
  32. {
  33. m_p->UnlockForUpdate();
  34. }
  35. };
  36. template<class TLockable>
  37. class CInLock
  38. {
  39. protected:
  40. TLockable* m_p;
  41. public:
  42. CInLock(TLockable* p) : m_p(p)
  43. {
  44. //
  45. // Do not return until the lock is held!
  46. //
  47. while(FAILED(m_p->Lock())) Sleep(1000);
  48. }
  49. ~CInLock()
  50. {
  51. m_p->Unlock();
  52. }
  53. };
  54. class CExecLine
  55. {
  56. public:
  57. class CTurn;
  58. CExecLine();
  59. virtual ~CExecLine();
  60. CTurn* GetInLine();
  61. DWORD WaitForTurn(CTurn* pTurn, DWORD dwTimeout = INFINITE);
  62. BOOL EndTurn(ACQUIRE CTurn* pTurn);
  63. BOOL DiscardTurn(ACQUIRE CTurn* pTurn);
  64. public:
  65. class CTurn
  66. {
  67. public:
  68. protected:
  69. long m_lRef;
  70. HANDLE m_hEvent;
  71. DWORD m_dwOwningThreadId;
  72. protected:
  73. CTurn();
  74. ~CTurn();
  75. long AddRef();
  76. long Release();
  77. BOOL Init();
  78. INTERNAL HANDLE GetEvent() {return m_hEvent;}
  79. void* operator new(size_t nSize);
  80. void operator delete(void* p);
  81. friend CExecLine;
  82. };
  83. class CInTurn
  84. {
  85. protected:
  86. CExecLine* m_pLine;
  87. CTurn* m_pTurn;
  88. public:
  89. CInTurn(CExecLine* pLine, CTurn* pTurn) : m_pLine(pLine), m_pTurn(pTurn)
  90. {
  91. m_pLine->WaitForTurn(m_pTurn);
  92. }
  93. ~CInTurn()
  94. {
  95. m_pLine->EndTurn(m_pTurn);
  96. }
  97. };
  98. protected:
  99. CCritSec m_cs;
  100. std::deque<CTurn*,wbem_allocator<CTurn*> > m_qTurns;
  101. typedef std::deque<CTurn*,wbem_allocator<CTurn*> >::iterator TTurnIterator;
  102. CTurn* m_pCurrentTurn;
  103. CTurn* m_pLastIssuedTurn;
  104. DWORD m_dwLastIssuedTurnThreadId;
  105. protected:
  106. BOOL ReleaseFirst();
  107. };
  108. /*
  109. class CTemporaryHeap
  110. {
  111. public:
  112. class CHeapHandle
  113. {
  114. protected:
  115. HANDLE m_hHeap;
  116. public:
  117. CHeapHandle();
  118. ~CHeapHandle();
  119. HANDLE GetHandle() {return m_hHeap;}
  120. void* Alloc(int nSize) {return HeapAlloc(m_hHeap, 0, nSize);}
  121. void Free(void* p) {HeapFree(m_hHeap, 0, p);}
  122. void Compact() {HeapCompact(m_hHeap, 0);}
  123. };
  124. protected:
  125. static CHeapHandle mstatic_HeapHandle;
  126. public:
  127. static void* Alloc(int nSize) {return mstatic_HeapHandle.Alloc(nSize);}
  128. static void Free(void* p) {mstatic_HeapHandle.Free(p);}
  129. static void Compact() {mstatic_HeapHandle.Compact();}
  130. };
  131. */
  132. class CTemporaryHeap
  133. {
  134. protected:
  135. static CTempMemoryManager mstatic_Manager;
  136. public:
  137. static void* Alloc(int nSize) {return mstatic_Manager.Allocate(nSize);}
  138. static void Free(void* p, int nSize) {mstatic_Manager.Free(p, nSize);}
  139. static void Compact() {}
  140. };
  141. INTERNAL const SECURITY_DESCRIPTOR* GetSD(IWbemEvent* pEvent, ULONG* pcEvent);
  142. HRESULT SetSD(IWbemEvent* pEvent, const SECURITY_DESCRIPTOR* pSD);
  143. #endif