xref: /reactos/sdk/lib/cicero/cicevent.h (revision de5c4720)
1 /*
2  * PROJECT:     ReactOS Cicero
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Cicero event object handling
5  * COPYRIGHT:   Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #pragma once
9 
10 #include "cicbase.h"
11 
12 class CicEvent
13 {
14     HANDLE m_hEvent;
15     LPCTSTR m_pszName;
16 
17 public:
18     CicEvent() : m_hEvent(NULL), m_pszName(NULL)
19     {
20     }
21     ~CicEvent()
22     {
23         Close();
24     }
25 
26     BOOL Create(LPSECURITY_ATTRIBUTES lpSA, LPCTSTR pszName)
27     {
28         if (pszName)
29             m_pszName = pszName;
30         if (!m_pszName)
31             return FALSE;
32         m_hEvent = ::CreateEvent(lpSA, FALSE, FALSE, m_pszName);
33         return (m_hEvent != NULL);
34     }
35     BOOL Open(LPCTSTR pszName)
36     {
37         if (pszName)
38             m_pszName = pszName;
39         m_hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, m_pszName);
40         return (m_hEvent != NULL);
41     }
42     void Close()
43     {
44         if (m_hEvent)
45         {
46             ::CloseHandle(m_hEvent);
47             m_hEvent = NULL;
48         }
49     }
50 
51     BOOL Wait(DWORD dwMilliseconds)
52     {
53         return (::WaitForSingleObject(m_hEvent, dwMilliseconds) == WAIT_OBJECT_0);
54     }
55 };
56