Somewhat working
This commit is contained in:
+2
@@ -149,6 +149,7 @@
|
||||
<ClCompile Include="utilities\Validator.cpp" />
|
||||
<ClCompile Include="views\AdminMenu.cpp" />
|
||||
<ClCompile Include="views\CustomerMenu.cpp" />
|
||||
<ClCompile Include="views\Menu.cpp" />
|
||||
<ClCompile Include="views\TechnicianMenu.cpp" />
|
||||
<ClCompile Include="views\UserInterface.cpp" />
|
||||
</ItemGroup>
|
||||
@@ -193,6 +194,7 @@
|
||||
<ClInclude Include="utilities\Vector.h" />
|
||||
<ClInclude Include="views\AdminMenu.h" />
|
||||
<ClInclude Include="views\CustomerMenu.h" />
|
||||
<ClInclude Include="views\Menu.h" />
|
||||
<ClInclude Include="views\MenuHelper.h" />
|
||||
<ClInclude Include="views\TechnicianMenu.h" />
|
||||
<ClInclude Include="views\UserInterface.h" />
|
||||
|
||||
+12
-2
@@ -43,11 +43,21 @@ bool AuthenticationManagementService::login(const std::string& username, const s
|
||||
user->getId(),
|
||||
[]()
|
||||
{
|
||||
std::cout << "USER_DISABLED event received" << std::endl;
|
||||
HANDLE eventHandle = OpenEventA(EVENT_MODIFY_STATE, FALSE, "VehicleServiceSystem_AccountDisabled");
|
||||
if (eventHandle)
|
||||
{
|
||||
SetEvent(eventHandle);
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
},
|
||||
[]()
|
||||
{
|
||||
std::cout << "NOTIFICATION_AVAILABLE event received" << std::endl;
|
||||
HANDLE eventHandle = OpenEventA(EVENT_MODIFY_STATE, FALSE, "VehicleServiceSystem_NotificationAvailable");
|
||||
if (eventHandle)
|
||||
{
|
||||
SetEvent(eventHandle);
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,10 +30,16 @@ Return type: void
|
||||
*/
|
||||
void AdminMenu::showMenu()
|
||||
{
|
||||
startEventListener();
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!m_isMenuActive)
|
||||
{
|
||||
logout();
|
||||
break;
|
||||
}
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Admin Menu"
|
||||
@@ -68,6 +74,7 @@ void AdminMenu::showMenu()
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
stopEventListener();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,8 +9,9 @@ Date:19-May-2026
|
||||
|
||||
#pragma once
|
||||
#include "Controller.h"
|
||||
#include "Menu.h"
|
||||
|
||||
class AdminMenu
|
||||
class AdminMenu : Menu
|
||||
{
|
||||
private:
|
||||
Controller m_controller;
|
||||
|
||||
@@ -32,10 +32,17 @@ Return type: void
|
||||
*/
|
||||
void CustomerMenu::showMenu()
|
||||
{
|
||||
|
||||
startEventListener();
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!m_isMenuActive)
|
||||
{
|
||||
logout();
|
||||
break;
|
||||
}
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Customer Menu"
|
||||
@@ -62,6 +69,7 @@ void CustomerMenu::showMenu()
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
stopEventListener();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,9 +9,10 @@ Date:19-May-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Menu.h"
|
||||
#include "Controller.h"
|
||||
|
||||
class CustomerMenu
|
||||
class CustomerMenu : Menu
|
||||
{
|
||||
private:
|
||||
Controller m_controller;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#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, "VehicleServiceSystem_AccountDisabled");
|
||||
m_notificationAvailableEvent = CreateEventA(NULL, FALSE, FALSE, "VehicleServiceSystem_NotificationAvailable");
|
||||
m_shutdownEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
File: Menu.h
|
||||
Description: Base class providing common event listener functionality
|
||||
for all menu implementations.
|
||||
Author: Trenser
|
||||
Date:16-Jun-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
class Menu
|
||||
{
|
||||
protected:
|
||||
std::atomic<bool> m_isMenuActive;
|
||||
std::atomic<bool> m_hasNewNotifications;
|
||||
HANDLE m_accountDisabledEvent;
|
||||
HANDLE m_notificationAvailableEvent;
|
||||
HANDLE m_shutdownEvent;
|
||||
std::thread m_eventListenerThread;
|
||||
void startEventListener();
|
||||
void stopEventListener();
|
||||
void eventListenerLoop();
|
||||
public:
|
||||
Menu();
|
||||
virtual ~Menu();
|
||||
};
|
||||
@@ -27,10 +27,16 @@ Returns:
|
||||
*/
|
||||
void TechnicianMenu::showMenu()
|
||||
{
|
||||
startEventListener();
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!m_isMenuActive)
|
||||
{
|
||||
logout();
|
||||
break;
|
||||
}
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Technician Menu"
|
||||
@@ -45,6 +51,7 @@ void TechnicianMenu::showMenu()
|
||||
{
|
||||
break;
|
||||
}
|
||||
stopEventListener();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -52,6 +59,7 @@ void TechnicianMenu::showMenu()
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
stopEventListener();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,8 +9,9 @@ Date:19-May-2026
|
||||
|
||||
#pragma once
|
||||
#include "Controller.h"
|
||||
#include "Menu.h"
|
||||
|
||||
class TechnicianMenu
|
||||
class TechnicianMenu : Menu
|
||||
{
|
||||
private:
|
||||
Controller m_controller;
|
||||
|
||||
Reference in New Issue
Block a user