4fa143946e
- Added null checks in combo package display/selection flows - Replaced unnecessary copies with references - Zero-initialized SerializedObserver - Initialized event handle array
151 lines
3.7 KiB
C++
151 lines
3.7 KiB
C++
/*
|
|
File: Menu.cpp
|
|
Description: Implementation file containing common menu event listener
|
|
functionality, account disable handling, and notification
|
|
event dispatching for all menu types.
|
|
Author: Trenser
|
|
Date:16-Jun-2026
|
|
*/
|
|
|
|
#include "Menu.h"
|
|
|
|
/*
|
|
Function: Menu
|
|
Description: Constructs a Menu object and initializes event handles
|
|
and menu state.
|
|
Parameter: None
|
|
Return type: None
|
|
*/
|
|
Menu::Menu()
|
|
:
|
|
m_isMenuActive(false),
|
|
m_accountDisabledEvent(NULL),
|
|
m_notificationAvailableEvent(NULL),
|
|
m_shutdownEvent(NULL) {}
|
|
|
|
/*
|
|
Function: ~Menu
|
|
Description: Destroys the Menu object and performs event listener
|
|
cleanup.
|
|
Parameter: None
|
|
Return type: None
|
|
*/
|
|
Menu::~Menu()
|
|
{
|
|
stopEventListener();
|
|
}
|
|
|
|
/*
|
|
Function: startEventListener
|
|
Description: Creates menu event handles, registers them with the
|
|
authentication service, and starts the event listener
|
|
thread.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
void Menu::startEventListener()
|
|
{
|
|
if (m_isMenuActive.load())
|
|
{
|
|
return;
|
|
}
|
|
m_isMenuActive.store(true);
|
|
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);
|
|
}
|
|
|
|
/*
|
|
Function: eventListenerLoop
|
|
Description: Waits for account disabled, notification available,
|
|
and shutdown events and dispatches them to the
|
|
appropriate handlers.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
void Menu::eventListenerLoop()
|
|
{
|
|
HANDLE handles[3] = { NULL, NULL, NULL };
|
|
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:
|
|
handleAccountDisabledEvent();
|
|
break;
|
|
case WAIT_OBJECT_0 + 1:
|
|
handleNotificationEvent();
|
|
break;
|
|
case WAIT_OBJECT_0 + 2:
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
Function: stopEventListener
|
|
Description: Stops the event listener thread and releases all
|
|
associated event handles.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/*
|
|
Function: handleAccountDisabledEvent
|
|
Description: Handles an account disabled event by marking the menu
|
|
inactive and notifying the user.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
void Menu::handleAccountDisabledEvent()
|
|
{
|
|
m_isMenuActive.store(false);
|
|
const User* authenticatedUser = m_controller.getAuthenticatedUser();
|
|
std::string messageTitle = "Account Disabled";
|
|
if (authenticatedUser)
|
|
{
|
|
messageTitle += " - " + authenticatedUser->getName();
|
|
}
|
|
MessageBoxA(
|
|
GetConsoleWindow(),
|
|
"Your account has been disabled.",
|
|
messageTitle.c_str(),
|
|
MB_OK |
|
|
MB_ICONWARNING |
|
|
MB_SETFOREGROUND |
|
|
MB_TOPMOST);
|
|
}
|