Compare commits

..

2 Commits

Author SHA1 Message Date
joelthomastrenser e054076175 events 2026-06-16 01:54:17 +05:30
joelthomastrenser 329fc6e23f Move sharedmemory/ to core/ 2026-06-15 23:51:21 +05:30
15 changed files with 10 additions and 350 deletions
@@ -149,7 +149,6 @@
<ClCompile Include="utilities\Validator.cpp" /> <ClCompile Include="utilities\Validator.cpp" />
<ClCompile Include="views\AdminMenu.cpp" /> <ClCompile Include="views\AdminMenu.cpp" />
<ClCompile Include="views\CustomerMenu.cpp" /> <ClCompile Include="views\CustomerMenu.cpp" />
<ClCompile Include="views\Menu.cpp" />
<ClCompile Include="views\TechnicianMenu.cpp" /> <ClCompile Include="views\TechnicianMenu.cpp" />
<ClCompile Include="views\UserInterface.cpp" /> <ClCompile Include="views\UserInterface.cpp" />
</ItemGroup> </ItemGroup>
@@ -194,7 +193,6 @@
<ClInclude Include="utilities\Vector.h" /> <ClInclude Include="utilities\Vector.h" />
<ClInclude Include="views\AdminMenu.h" /> <ClInclude Include="views\AdminMenu.h" />
<ClInclude Include="views\CustomerMenu.h" /> <ClInclude Include="views\CustomerMenu.h" />
<ClInclude Include="views\Menu.h" />
<ClInclude Include="views\MenuHelper.h" /> <ClInclude Include="views\MenuHelper.h" />
<ClInclude Include="views\TechnicianMenu.h" /> <ClInclude Include="views\TechnicianMenu.h" />
<ClInclude Include="views\UserInterface.h" /> <ClInclude Include="views\UserInterface.h" />
@@ -153,12 +153,9 @@
<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="core\events\EventManager.cpp"> <ClCompile Include="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">
@@ -290,8 +287,5 @@
<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>
@@ -622,16 +622,3 @@ void Controller::shutdown()
auto& dataStore = DataStore::getInstance(); auto& dataStore = DataStore::getInstance();
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)
{
m_authenticationManagementService.registerEvents(accountDisabledEvent, notificationAvailableEvent);
}
@@ -8,7 +8,6 @@ Date:19-May-2026
*/ */
#pragma once #pragma once
#include <windows.h>
#include <string> #include <string>
#include "AuthenticationManagementService.h" #include "AuthenticationManagementService.h"
#include "Enums.h" #include "Enums.h"
@@ -73,5 +72,4 @@ public:
void configureNotifications(bool paymentNotifications, bool serviceNotifications); void configureNotifications(bool paymentNotifications, bool serviceNotifications);
bool initialize(); bool initialize();
void shutdown(); void shutdown();
void registerEvents(HANDLE accountDisabledEvent, HANDLE notificationAvailableEvent);
}; };
@@ -8,6 +8,7 @@ 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"
@@ -15,8 +16,6 @@ Date:19-May-2026
User* AuthenticationManagementService::m_authenticatedUser = nullptr; User* AuthenticationManagementService::m_authenticatedUser = nullptr;
EventManager AuthenticationManagementService::m_eventManager; EventManager AuthenticationManagementService::m_eventManager;
HANDLE AuthenticationManagementService::m_accountDisabledEvent = NULL;
HANDLE AuthenticationManagementService::m_notificationsAvailableEvent = NULL;
/* /*
Function: login Function: login
@@ -44,17 +43,11 @@ bool AuthenticationManagementService::login(const std::string& username, const s
user->getId(), user->getId(),
[]() []()
{ {
if (m_accountDisabledEvent) std::cout << "USER_DISABLED event received" << std::endl;
{
SetEvent(m_accountDisabledEvent);
}
}, },
[]() []()
{ {
if (m_notificationsAvailableEvent) std::cout << "NOTIFICATION_AVAILABLE event received" << std::endl;
{
SetEvent(m_notificationsAvailableEvent);
}
}); });
return true; return true;
} }
@@ -86,8 +79,6 @@ void AuthenticationManagementService::logout()
{ {
m_eventManager.shutdown(); m_eventManager.shutdown();
m_authenticatedUser = nullptr; m_authenticatedUser = nullptr;
m_accountDisabledEvent = NULL;
m_notificationsAvailableEvent = NULL;
} }
/* /*
@@ -114,17 +105,3 @@ void AuthenticationManagementService::changePassword(const std::string& newPassw
trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED; trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED;
m_dataStore.saveUsers(); m_dataStore.saveUsers();
} }
/*
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_notificationsAvailableEvent = notificationAvailableEvent;
}
@@ -9,7 +9,6 @@ Date:19-May-2026
#pragma once #pragma once
#include <string> #include <string>
#include <windows.h>
#include "EventManager.h" #include "EventManager.h"
#include "DataStore.h" #include "DataStore.h"
@@ -20,8 +19,6 @@ class AuthenticationManagementService
private: private:
static User* m_authenticatedUser; static User* m_authenticatedUser;
static EventManager m_eventManager; static EventManager m_eventManager;
static HANDLE m_accountDisabledEvent;
static HANDLE m_notificationsAvailableEvent;
DataStore& m_dataStore; DataStore& m_dataStore;
public: public:
AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {} AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {}
@@ -29,5 +26,4 @@ public:
void logout(); void logout();
void changePassword(const std::string& newPassword); void changePassword(const std::string& newPassword);
User* getAuthenticatedUser(); User* getAuthenticatedUser();
void registerEvents(HANDLE accountDisabledEvent, HANDLE notificationAvailableEvent);
}; };
@@ -30,16 +30,10 @@ Return type: void
*/ */
void AdminMenu::showMenu() void AdminMenu::showMenu()
{ {
startEventListener();
while (true) while (true)
{ {
try try
{ {
if (!m_isMenuActive)
{
logout();
break;
}
int choice; int choice;
util::clear(); util::clear();
std::cout << "Admin Menu" std::cout << "Admin Menu"
@@ -74,7 +68,6 @@ void AdminMenu::showMenu()
util::pressEnter(); util::pressEnter();
} }
} }
stopEventListener();
} }
/* /*
@@ -85,11 +78,6 @@ Return type: bool - true if menu continues, false if logout
*/ */
bool AdminMenu::handleOperation(int choice) bool AdminMenu::handleOperation(int choice)
{ {
if (!m_isMenuActive)
{
logout();
return false;
}
switch (choice) switch (choice)
{ {
case 1: case 1:
@@ -153,19 +141,6 @@ 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()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated admin user. Description: Logs out the currently authenticated admin user.
@@ -9,13 +9,12 @@ Date:19-May-2026
#pragma once #pragma once
#include "Controller.h" #include "Controller.h"
#include "Menu.h"
class AdminMenu : public Menu class AdminMenu
{ {
private: private:
Controller m_controller;
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent() override;
public: public:
void showMenu(); void showMenu();
void logout(); void logout();
@@ -32,17 +32,10 @@ Return type: void
*/ */
void CustomerMenu::showMenu() void CustomerMenu::showMenu()
{ {
startEventListener();
while (true) while (true)
{ {
try try
{ {
if (!m_isMenuActive)
{
logout();
break;
}
int choice; int choice;
util::clear(); util::clear();
std::cout << "Customer Menu" std::cout << "Customer Menu"
@@ -69,7 +62,6 @@ void CustomerMenu::showMenu()
util::pressEnter(); util::pressEnter();
} }
} }
stopEventListener();
} }
/* /*
@@ -80,11 +72,6 @@ Return type: bool - true if menu continues, false if logout
*/ */
bool CustomerMenu::handleOperation(int choice) bool CustomerMenu::handleOperation(int choice)
{ {
if (!m_isMenuActive)
{
logout();
return false;
}
switch (choice) switch (choice)
{ {
case 1: case 1:
@@ -124,19 +111,6 @@ 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()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated customer user. Description: Logs out the currently authenticated customer user.
@@ -9,14 +9,13 @@ Date:19-May-2026
*/ */
#pragma once #pragma once
#include "Menu.h"
#include "Controller.h" #include "Controller.h"
class CustomerMenu : public Menu class CustomerMenu
{ {
private: private:
Controller m_controller;
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent();
public: public:
void showMenu(); void showMenu();
void logout(); void logout();
@@ -1,144 +0,0 @@
/*
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];
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);
MessageBoxA(
GetConsoleWindow(),
"Your account has been disabled.",
"Account Disabled",
MB_OK |
MB_ICONWARNING |
MB_SETFOREGROUND |
MB_TOPMOST);
}
@@ -1,33 +0,0 @@
/*
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>
#include "Controller.h"
class Menu
{
protected:
Controller m_controller;
std::atomic<bool> m_isMenuActive;
HANDLE m_accountDisabledEvent;
HANDLE m_notificationAvailableEvent;
HANDLE m_shutdownEvent;
std::thread m_eventListenerThread;
void startEventListener();
void stopEventListener();
void eventListenerLoop();
void handleAccountDisabledEvent();
virtual void handleNotificationEvent() = 0;
public:
Menu();
virtual ~Menu();
};
@@ -1408,37 +1408,3 @@ inline std::string selectComboPackage(util::Map<std::string, const ComboPackage*
return ""; return "";
} }
} }
/*
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)
{
const Notification* notification = nullptr;
size_t numberOfNotifications = notifications.getSize();
for (int index = 0; index < numberOfNotifications; index++)
{
if (!notification)
{
notification = notifications[index];
}
else
{
if (notification->getId() < notifications[index]->getId())
{
notification = notifications[index];
}
}
}
MessageBoxA(
GetConsoleWindow(),
notification->getMessage().c_str(),
notification->getTitle().c_str(),
MB_OK |
MB_ICONINFORMATION);
}
@@ -27,16 +27,10 @@ Returns:
*/ */
void TechnicianMenu::showMenu() void TechnicianMenu::showMenu()
{ {
startEventListener();
while (true) while (true)
{ {
try try
{ {
if (!m_isMenuActive)
{
logout();
break;
}
int choice; int choice;
util::clear(); util::clear();
std::cout << "Technician Menu" std::cout << "Technician Menu"
@@ -58,7 +52,6 @@ void TechnicianMenu::showMenu()
util::pressEnter(); util::pressEnter();
} }
} }
stopEventListener();
} }
/* /*
@@ -69,11 +62,6 @@ Return type: bool - true if menu continues, false if logout
*/ */
bool TechnicianMenu::handleOperation(int choice) bool TechnicianMenu::handleOperation(int choice)
{ {
if (!m_isMenuActive)
{
logout();
return false;
}
switch (choice) switch (choice)
{ {
case 1: case 1:
@@ -98,19 +86,6 @@ 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()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: displayJobs Function: displayJobs
Description: Displays all Jobs assigned to a Technician Description: Displays all Jobs assigned to a Technician
@@ -9,13 +9,12 @@ Date:19-May-2026
#pragma once #pragma once
#include "Controller.h" #include "Controller.h"
#include "Menu.h"
class TechnicianMenu : public Menu class TechnicianMenu
{ {
private: private:
Controller m_controller;
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent();
public: public:
void showMenu(); void showMenu();
void displayJobs(); void displayJobs();