86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#include "Menu.h"
|
|
|
|
Menu::Menu()
|
|
:
|
|
m_isMenuActive(false),
|
|
m_hasNewNotifications(false),
|
|
m_accountDisabledEvent(NULL),
|
|
m_notificationAvailableEvent(NULL),
|
|
m_shutdownEvent(NULL) {}
|
|
|
|
Menu::~Menu()
|
|
{
|
|
stopEventListener();
|
|
}
|
|
|
|
void Menu::startEventListener()
|
|
{
|
|
if (m_isMenuActive.load())
|
|
{
|
|
return;
|
|
}
|
|
m_isMenuActive.store(true);
|
|
m_hasNewNotifications.store(false);
|
|
m_accountDisabledEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
m_notificationAvailableEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
m_shutdownEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
m_controller.registerEvents(m_accountDisabledEvent, m_notificationAvailableEvent);
|
|
m_eventListenerThread = std::thread(&Menu::eventListenerLoop, this);
|
|
}
|
|
|
|
void Menu::eventListenerLoop()
|
|
{
|
|
HANDLE handles[3];
|
|
handles[0] = m_accountDisabledEvent;
|
|
handles[1] = m_notificationAvailableEvent;
|
|
handles[2] = m_shutdownEvent;
|
|
while (m_isMenuActive.load())
|
|
{
|
|
DWORD result = WaitForMultipleObjects(3, handles, FALSE, INFINITE);
|
|
switch (result)
|
|
{
|
|
case WAIT_OBJECT_0:
|
|
m_isMenuActive.store(false);
|
|
MessageBoxA(
|
|
NULL,
|
|
"Your account has been disabled.",
|
|
"Account Disabled",
|
|
MB_OK | MB_ICONWARNING);
|
|
break;
|
|
case WAIT_OBJECT_0 + 1:
|
|
m_hasNewNotifications.store(true);
|
|
break;
|
|
case WAIT_OBJECT_0 + 2:
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Menu::stopEventListener()
|
|
{
|
|
m_isMenuActive.store(false);
|
|
if (m_shutdownEvent)
|
|
{
|
|
SetEvent(m_shutdownEvent);
|
|
}
|
|
if (m_eventListenerThread.joinable())
|
|
{
|
|
m_eventListenerThread.join();
|
|
}
|
|
if (m_accountDisabledEvent)
|
|
{
|
|
CloseHandle(m_accountDisabledEvent);
|
|
}
|
|
if (m_notificationAvailableEvent)
|
|
{
|
|
CloseHandle(m_notificationAvailableEvent);
|
|
}
|
|
if (m_shutdownEvent)
|
|
{
|
|
CloseHandle(m_shutdownEvent);
|
|
}
|
|
m_accountDisabledEvent = NULL;
|
|
m_notificationAvailableEvent = NULL;
|
|
m_shutdownEvent = NULL;
|
|
}
|