Compare commits

..

2 Commits

Author SHA1 Message Date
joelthomastrenser ae37b83cbc Implement review fixes 2026-06-16 11:29:00 +05:30
joelthomastrenser 8aaa4eeec0 Implement interprocess event handling for notifications and account disable
Changes:
- Implements #2061
- Introduce EventManager for user-specific Windows event publishing/listening
- Add real-time notification and account-disabled event propagation
- Register authentication events through Controller and AuthenticationManagementService
- Trigger notification events from Inventory, Payment, and Service Management modules
- Trigger account-disabled events when users are deactivated
- Extract common menu event listener logic into Menu base class
- Add notification popup handling for Admin, Customer, and Technician menus
- Refactor shared memory components into core/sharedmemory
- Update project structure and include paths for events and shared memory modules
2026-06-16 11:10:13 +05:30
11 changed files with 110 additions and 9 deletions
@@ -153,9 +153,12 @@
<ClCompile Include="core\sharedmemory\SharedMemory.cpp"> <ClCompile Include="core\sharedmemory\SharedMemory.cpp">
<Filter>Source Files\Core\SharedMemory</Filter> <Filter>Source Files\Core\SharedMemory</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="EventManager.cpp"> <ClCompile Include="core\events\EventManager.cpp">
<Filter>Source Files\Core\Events</Filter> <Filter>Source Files\Core\Events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="views\Menu.cpp">
<Filter>Source Files\Views</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="utilities\InputHelper.h"> <ClInclude Include="utilities\InputHelper.h">
@@ -287,5 +290,8 @@
<ClInclude Include="core\events\EventManager.h"> <ClInclude Include="core\events\EventManager.h">
<Filter>Header Files\Core\Events</Filter> <Filter>Header Files\Core\Events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="views\Menu.h">
<Filter>Header Files\Views</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -623,6 +623,14 @@ void Controller::shutdown()
dataStore.shutdown(); dataStore.shutdown();
} }
/*
Function: registerEvents
Description: Registers menu event handles with the authentication
service.
Parameter: HANDLE accountDisabledEvent - account disabled event handle
HANDLE notificationAvailableEvent - notification event handle
Return type: void
*/
void Controller::registerEvents(HANDLE accountDisabledEvent, HANDLE notificationAvailableEvent) void Controller::registerEvents(HANDLE accountDisabledEvent, HANDLE notificationAvailableEvent)
{ {
m_authenticationManagementService.registerEvents(accountDisabledEvent, notificationAvailableEvent); m_authenticationManagementService.registerEvents(accountDisabledEvent, notificationAvailableEvent);
@@ -8,7 +8,6 @@ Date:19-May-2026
*/ */
#include <stdexcept> #include <stdexcept>
#include <iostream>
#include "AuthenticationManagementService.h" #include "AuthenticationManagementService.h"
#include "User.h" #include "User.h"
#include "Utility.h" #include "Utility.h"
@@ -52,7 +51,6 @@ bool AuthenticationManagementService::login(const std::string& username, const s
}, },
[]() []()
{ {
HANDLE eventHandle = OpenEventA(EVENT_MODIFY_STATE, FALSE, "VehicleServiceSystem_NotificationAvailable");
if (m_notificationsAvailableEvent) if (m_notificationsAvailableEvent)
{ {
SetEvent(m_notificationsAvailableEvent); SetEvent(m_notificationsAvailableEvent);
@@ -117,8 +115,16 @@ void AuthenticationManagementService::changePassword(const std::string& newPassw
m_dataStore.saveUsers(); m_dataStore.saveUsers();
} }
void AuthenticationManagementService::registerEvents(HANDLE accountDisabledEvent, HANDLE notifictionAvailableEvent) /*
Function: registerEvents
Description: Registers menu event handles used to notify the active
menu of account disable and notification events.
Parameter: HANDLE accountDisabledEvent - account disabled event handle
HANDLE notificationAvailableEvent - notification event handle
Return type: void
*/
void AuthenticationManagementService::registerEvents(HANDLE accountDisabledEvent, HANDLE notificationAvailableEvent)
{ {
m_accountDisabledEvent = accountDisabledEvent; m_accountDisabledEvent = accountDisabledEvent;
m_notificationsAvailableEvent = notifictionAvailableEvent; m_notificationsAvailableEvent = notificationAvailableEvent;
} }
@@ -153,6 +153,13 @@ bool AdminMenu::handleOperation(int choice)
return true; return true;
} }
/*
Function: handleNotificationEvent
Description: Retrieves and displays the latest notification for the
currently logged in admin.
Parameter: None
Return type: void
*/
void AdminMenu::handleNotificationEvent() void AdminMenu::handleNotificationEvent()
{ {
auto notifications = m_controller.getNotifications(); auto notifications = m_controller.getNotifications();
@@ -11,7 +11,7 @@ Date:19-May-2026
#include "Controller.h" #include "Controller.h"
#include "Menu.h" #include "Menu.h"
class AdminMenu : Menu class AdminMenu : public Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);
@@ -124,6 +124,13 @@ bool CustomerMenu::handleOperation(int choice)
return true; return true;
} }
/*
Function: handleNotificationEvent
Description: Retrieves and displays the latest notification for the
currently logged in admin.
Parameter: None
Return type: void
*/
void CustomerMenu::handleNotificationEvent() void CustomerMenu::handleNotificationEvent()
{ {
auto notifications = m_controller.getNotifications(); auto notifications = m_controller.getNotifications();
@@ -12,7 +12,7 @@ Date:19-May-2026
#include "Menu.h" #include "Menu.h"
#include "Controller.h" #include "Controller.h"
class CustomerMenu : Menu class CustomerMenu : public Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);
@@ -1,5 +1,21 @@
/*
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" #include "Menu.h"
/*
Function: Menu
Description: Constructs a Menu object and initializes event handles
and menu state.
Parameter: None
Return type: None
*/
Menu::Menu() Menu::Menu()
: :
m_isMenuActive(false), m_isMenuActive(false),
@@ -7,11 +23,26 @@ Menu::Menu()
m_notificationAvailableEvent(NULL), m_notificationAvailableEvent(NULL),
m_shutdownEvent(NULL) {} m_shutdownEvent(NULL) {}
/*
Function: ~Menu
Description: Destroys the Menu object and performs event listener
cleanup.
Parameter: None
Return type: None
*/
Menu::~Menu() Menu::~Menu()
{ {
stopEventListener(); 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() void Menu::startEventListener()
{ {
if (m_isMenuActive.load()) if (m_isMenuActive.load())
@@ -26,6 +57,14 @@ void Menu::startEventListener()
m_eventListenerThread = std::thread(&Menu::eventListenerLoop, this); 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() void Menu::eventListenerLoop()
{ {
HANDLE handles[3]; HANDLE handles[3];
@@ -49,6 +88,13 @@ void Menu::eventListenerLoop()
} }
} }
/*
Function: stopEventListener
Description: Stops the event listener thread and releases all
associated event handles.
Parameter: None
Return type: void
*/
void Menu::stopEventListener() void Menu::stopEventListener()
{ {
m_isMenuActive.store(false); m_isMenuActive.store(false);
@@ -77,6 +123,13 @@ void Menu::stopEventListener()
m_shutdownEvent = 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() void Menu::handleAccountDisabledEvent()
{ {
m_isMenuActive.store(false); m_isMenuActive.store(false);
@@ -1409,6 +1409,14 @@ inline std::string selectComboPackage(util::Map<std::string, const ComboPackage*
} }
} }
/*
Function: displayNewNotification
Description: Displays the most recent notification from the supplied
notification collection.
Parameter: util::Vector<const Notification*> notifications -
collection of notifications
Return type: void
*/
inline void displayNewNotification(util::Vector<const Notification*> notifications) inline void displayNewNotification(util::Vector<const Notification*> notifications)
{ {
const Notification* notification = nullptr; const Notification* notification = nullptr;
@@ -51,7 +51,6 @@ void TechnicianMenu::showMenu()
{ {
break; break;
} }
stopEventListener();
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@@ -99,6 +98,13 @@ bool TechnicianMenu::handleOperation(int choice)
return true; return true;
} }
/*
Function: handleNotificationEvent
Description: Retrieves and displays the latest notification for the
currently logged in admin.
Parameter: None
Return type: void
*/
void TechnicianMenu::handleNotificationEvent() void TechnicianMenu::handleNotificationEvent()
{ {
auto notifications = m_controller.getNotifications(); auto notifications = m_controller.getNotifications();
@@ -11,7 +11,7 @@ Date:19-May-2026
#include "Controller.h" #include "Controller.h"
#include "Menu.h" #include "Menu.h"
class TechnicianMenu : Menu class TechnicianMenu : public Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);