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.

128 lines
3.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SIMEVENT.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/4/1999
  12. *
  13. * DESCRIPTION: Simple win32 event wrapper class
  14. *
  15. *******************************************************************************/
  16. #ifndef __SIMEVENT_H_INCLUDED
  17. #define __SIMEVENT_H_INCLUDED
  18. #include "simstr.h"
  19. class CSimpleEvent
  20. {
  21. private:
  22. CSimpleString m_strEventName;
  23. HANDLE m_hEvent;
  24. public:
  25. CSimpleEvent( bool bNoCreate = false )
  26. : m_hEvent(NULL)
  27. {
  28. if (!bNoCreate)
  29. Assign( CSimpleString(TEXT("")), NULL );
  30. }
  31. explicit CSimpleEvent( LPCTSTR pszEventName )
  32. : m_hEvent(NULL)
  33. {
  34. Assign( pszEventName, NULL );
  35. }
  36. explicit CSimpleEvent( const CSimpleString &strEventName )
  37. : m_hEvent(NULL)
  38. {
  39. Assign( strEventName, NULL );
  40. }
  41. CSimpleEvent( HANDLE hEvent )
  42. : m_hEvent(NULL)
  43. {
  44. Assign( CSimpleString(TEXT("")), hEvent );
  45. }
  46. CSimpleEvent( const CSimpleEvent &other )
  47. : m_hEvent(NULL)
  48. {
  49. Assign( other.EventName(), other.Event() );
  50. }
  51. CSimpleEvent &operator=( const CSimpleEvent &other )
  52. {
  53. return Assign( other.EventName(), other.Event() );
  54. }
  55. CSimpleEvent &operator=( HANDLE hEvent )
  56. {
  57. return Assign( TEXT(""), hEvent );
  58. }
  59. virtual ~CSimpleEvent(void)
  60. {
  61. Close();
  62. }
  63. bool Create( const CSimpleString &strEventName = TEXT("") )
  64. {
  65. Assign( strEventName, NULL );
  66. return (m_hEvent != NULL);
  67. }
  68. CSimpleEvent &Assign( const CSimpleString &strEventName, const HANDLE hEvent )
  69. {
  70. Close();
  71. if (!strEventName.Length() && !hEvent)
  72. {
  73. m_hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
  74. }
  75. else if (strEventName.Length())
  76. {
  77. m_strEventName = strEventName;
  78. m_hEvent = CreateEvent( NULL, TRUE, FALSE, m_strEventName.String() );
  79. }
  80. else if (hEvent)
  81. {
  82. if (!DuplicateHandle( GetCurrentProcess(), hEvent, GetCurrentProcess(), &m_hEvent, 0, FALSE, DUPLICATE_SAME_ACCESS ))
  83. m_hEvent = NULL;
  84. }
  85. return *this;
  86. }
  87. bool Close(void)
  88. {
  89. if (m_hEvent)
  90. {
  91. CloseHandle(m_hEvent);
  92. m_hEvent = NULL;
  93. }
  94. m_strEventName = TEXT("");
  95. return true;
  96. }
  97. void Reset(void)
  98. {
  99. if (!m_hEvent)
  100. return;
  101. ResetEvent(m_hEvent);
  102. }
  103. bool Signalled(void) const
  104. {
  105. if (!m_hEvent)
  106. return (false);
  107. DWORD dwRes = WaitForSingleObject(m_hEvent,0);
  108. return(WAIT_OBJECT_0 == dwRes);
  109. }
  110. void Signal(void) const
  111. {
  112. if (!m_hEvent)
  113. return;
  114. SetEvent(m_hEvent);
  115. }
  116. CSimpleString EventName(void) const
  117. {
  118. return (m_strEventName);
  119. }
  120. HANDLE Event(void) const
  121. {
  122. return (m_hEvent);
  123. }
  124. };
  125. #endif // #ifndef __SIMEVENT_H_INCLUDED