Compare commits

...

2 Commits

Author SHA1 Message Date
joelthomastrenser d41b9da4e2 changes 2026-06-11 18:06:14 +05:30
Jissin Mathew 0bef16e82c Added file headers and updated the readpassword utility functionality 2026-06-11 18:02:09 +05:30
20 changed files with 221 additions and 76 deletions
@@ -6,6 +6,7 @@ Description: Implementation file containing the method definitions of the
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include "ComboPackage.h" #include "ComboPackage.h"
#include "Controller.h" #include "Controller.h"
#include "Enums.h" #include "Enums.h"
@@ -38,78 +38,106 @@ bool DataStore::initialize()
{ {
return false; return false;
} }
util::ensureDirectoryExists(config::file::DIRECTORY); if (!lockDataStore())
m_users.fileName = config::file::USER_FILE;
m_users.recordSize = sizeof(SerializedUser);
m_notifications.fileName = config::file::NOTIFICATION_FILE;
m_notifications.recordSize = sizeof(SerializedNotification);
m_services.fileName = config::file::SERVICE_FILE;
m_services.recordSize = sizeof(SerializedService);
m_comboPackages.fileName = config::file::COMBOPACKAGE_FILE;
m_comboPackages.recordSize = sizeof(SerializedComboPackage);
m_inventoryItems.fileName = config::file::INVENTORYITEM_FILE;
m_inventoryItems.recordSize = sizeof(SerializedInventoryItem);
m_serviceBookings.fileName = config::file::SERVICEBOOKING_FILE;
m_serviceBookings.recordSize = sizeof(SerializedServiceBooking);
m_jobCards.fileName = config::file::JOBCARD_FILE;
m_jobCards.recordSize = sizeof(SerializedJobCard);
m_invoices.fileName = config::file::INVOICE_FILE;
m_invoices.recordSize = sizeof(SerializedInvoice);
m_serviceManagementObservers.fileName = config::file::SERVICEMANAGEMENTOBSERVERS;
m_serviceManagementObservers.recordSize = sizeof(SerializedObserver);
m_paymentManagementObservers.fileName = config::file::PAYMENTMANAGEMENTOBSERVERS;
m_paymentManagementObservers.recordSize = sizeof(SerializedObserver);
m_inventoryManagementObservers.fileName = config::file::INVENTORYMANAGEMENTOBSERVERS;
m_inventoryManagementObservers.recordSize = sizeof(SerializedObserver);
if (!SharedMemory::createOrOpenMapping(m_users))
{ {
CloseHandle(m_globalMutex);
m_globalMutex = NULL;
return false; return false;
} }
if (!SharedMemory::createOrOpenMapping(m_notifications)) bool success = true;
do
{ {
return false; util::ensureDirectoryExists(config::file::DIRECTORY);
} m_users.fileName = config::file::USER_FILE;
if (!SharedMemory::createOrOpenMapping(m_services)) m_users.recordSize = sizeof(SerializedUser);
m_notifications.fileName = config::file::NOTIFICATION_FILE;
m_notifications.recordSize = sizeof(SerializedNotification);
m_services.fileName = config::file::SERVICE_FILE;
m_services.recordSize = sizeof(SerializedService);
m_comboPackages.fileName = config::file::COMBOPACKAGE_FILE;
m_comboPackages.recordSize = sizeof(SerializedComboPackage);
m_inventoryItems.fileName = config::file::INVENTORYITEM_FILE;
m_inventoryItems.recordSize = sizeof(SerializedInventoryItem);
m_serviceBookings.fileName = config::file::SERVICEBOOKING_FILE;
m_serviceBookings.recordSize = sizeof(SerializedServiceBooking);
m_jobCards.fileName = config::file::JOBCARD_FILE;
m_jobCards.recordSize = sizeof(SerializedJobCard);
m_invoices.fileName = config::file::INVOICE_FILE;
m_invoices.recordSize = sizeof(SerializedInvoice);
m_serviceManagementObservers.fileName = config::file::SERVICEMANAGEMENTOBSERVERS;
m_serviceManagementObservers.recordSize = sizeof(SerializedObserver);
m_paymentManagementObservers.fileName = config::file::PAYMENTMANAGEMENTOBSERVERS;
m_paymentManagementObservers.recordSize = sizeof(SerializedObserver);
m_inventoryManagementObservers.fileName = config::file::INVENTORYMANAGEMENTOBSERVERS;
m_inventoryManagementObservers.recordSize = sizeof(SerializedObserver);
if (!SharedMemory::createOrOpenMapping(m_users))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_notifications))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_services))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_comboPackages))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_inventoryItems))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_serviceBookings))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_jobCards))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_invoices))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_payments))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_serviceManagementObservers))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_paymentManagementObservers))
{
success = false;
break;
}
if (!SharedMemory::createOrOpenMapping(m_inventoryManagementObservers))
{
success = false;
break;
}
} while (false);
unlockDataStore();
if (!success)
{ {
return false; shutdown();
} }
if (!SharedMemory::createOrOpenMapping(m_comboPackages)) return success;
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_inventoryItems))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_serviceBookings))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_jobCards))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_invoices))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_payments))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_serviceManagementObservers))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_paymentManagementObservers))
{
return false;
}
if (!SharedMemory::createOrOpenMapping(m_inventoryManagementObservers))
{
return false;
}
return true;
} }
/* /*
@@ -1,3 +1,12 @@
/*
File: FileHeader.h
Description: Defines the FileHeader structure used to store
metadata for binary record files, including
record count and capacity.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
#include <cstddef> #include <cstddef>
@@ -1,3 +1,13 @@
/*
File: MappingInfo.h
Description: Defines the MappingInfo structure used for
managing Windows file mapping operations.
Stores handles, mapped view pointer,
file metadata, and capacity information.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
#include <windows.h> #include <windows.h>
#include <string> #include <string>
@@ -1,3 +1,12 @@
/*
File: RecordState.h
Description: Defines the RecordState enumeration used to
represent the state of a record in storage.
States include CLEAN, NEW_RECORD, and MODIFIED.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
enum class RecordState : int enum class RecordState : int
@@ -1,3 +1,15 @@
/*
File: SerializedRecords.h
Description: Defines serialized structures for persistent storage
and retrieval of system entities including User,
Notification, Service, ComboPackage, InventoryItem,
ServiceBooking, JobCard, Invoice, and Observer.
These structures use fixed-size character arrays
and primitive types for binary serialization.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
#include "Utility.h" #include "Utility.h"
#include "Enums.h" #include "Enums.h"
@@ -1,3 +1,14 @@
/*
File: SharedMemory.cpp
Description: Implements shared memory utilities for managing
Windows file mapping operations. Provides functions
to create, open, resize, and close mappings, as well
as access headers, records, and ensure synchronization
across processes.
Author: Trenser
Created: 11-June-2026
*/
#include "SharedMemory.h" #include "SharedMemory.h"
#include "Config.h" #include "Config.h"
@@ -1,3 +1,14 @@
/*
File: SharedMemory.h
Description: Declares functions for managing Windows file
mapping and shared memory operations. Provides
utilities for creating, resizing, and closing
mappings, as well as accessing headers and
record data.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include "MappingInfo.h" #include "MappingInfo.h"
@@ -1,3 +1,13 @@
/*
File: TrackedRecord.h
Description: Defines the TrackedRecord template structure used
to manage objects with associated record state and
slot index. Supports tracking of CLEAN, NEW_RECORD,
and MODIFIED states for persistence and synchronization.
Author: Trenser
Created: 10-June-2026
*/
#pragma once #pragma once
#include "RecordState.h" #include "RecordState.h"
@@ -520,4 +520,4 @@ Invoice* Invoice::deserialize(const SerializedInvoice& serializedInvoice)
serializedInvoice.paymentDate, serializedInvoice.paymentDate,
serializedInvoice.paymentMethod, serializedInvoice.paymentMethod,
serializedInvoice.status); serializedInvoice.status);
} }
@@ -6,7 +6,6 @@ Author: Trenser
Date: 19-May-2026 Date: 19-May-2026
*/ */
#pragma once #pragma once
#include <string> #include <string>
#include "Map.h" #include "Map.h"
@@ -6,6 +6,7 @@ Description: Implementation file containing the method definitions of the
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include "SerializedRecords.h" #include "SerializedRecords.h"
@@ -6,6 +6,7 @@ Description: Header file declaring the ServiceBooking class, which represents
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#pragma once #pragma once
#include <string> #include <string>
#include "Map.h" #include "Map.h"
@@ -6,6 +6,7 @@ Description: Header file declaring the UserManagementService class, which manage
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#pragma once #pragma once
#include <string> #include <string>
#include "Map.h" #include "Map.h"
@@ -106,4 +106,4 @@ namespace util
file << records[index] << '\n'; file << records[index] << '\n';
} }
} }
} }
@@ -10,6 +10,7 @@
#include <limits> #include <limits>
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include <conio.h>
namespace util namespace util
{ {
@@ -54,6 +55,48 @@ namespace util
value = cleanedValue; value = cleanedValue;
} }
/*
* Function: readPassword
* Description: Reads a password from console without echoing characters;
* displays '*' for each character typed, handles backspace,
* and cleans commas from the result.
* Parameters:
* value - reference to a string where the password will be stored
* Returns:
* void - no return value
*/
inline void readPassword(std::string& value)
{
value.clear();
char currentCharacter;
while ((currentCharacter = _getch()) != '\r')
{
if (currentCharacter == '\b')
{
if (!value.empty())
{
value.pop_back();
std::cout << "\b \b";
}
}
else
{
value += currentCharacter;
std::cout << '*';
}
}
std::cout << std::endl;
std::string cleanedValue;
for (int iterator = 0; iterator < value.length(); iterator++)
{
if (value[iterator] != ',')
{
cleanedValue += value[iterator];
}
}
value = cleanedValue;
}
/* /*
* Function: pressEnter * Function: pressEnter
* Description: Pauses execution until the user presses Enter. * Description: Pauses execution until the user presses Enter.
@@ -30,7 +30,6 @@ Description: Displays the customer menu and handles user input until logout is s
Parameter: None Parameter: None
Return type: void Return type: void
*/ */
void CustomerMenu::showMenu() void CustomerMenu::showMenu()
{ {
while (true) while (true)
@@ -914,7 +914,7 @@ inline void changePasswordHelper(Controller& controller)
util::clear(); util::clear();
std::cout << "Change Password\n"; std::cout << "Change Password\n";
std::cout << "Enter new password: "; std::cout << "Enter new password: ";
util::read(newPassword); util::readPassword(newPassword);
if (!util::isPasswordValid(newPassword)) if (!util::isPasswordValid(newPassword))
{ {
std::cout << "Error: Password is not strong enough!\n"; std::cout << "Error: Password is not strong enough!\n";
@@ -928,7 +928,7 @@ inline void changePasswordHelper(Controller& controller)
continue; continue;
} }
std::cout << "Confirm new password: "; std::cout << "Confirm new password: ";
util::read(confirmedPassword); util::readPassword(confirmedPassword);
if (confirmedPassword != newPassword) if (confirmedPassword != newPassword)
{ {
std::cout << "Passwords are different. Try again\n"; std::cout << "Passwords are different. Try again\n";
@@ -22,4 +22,4 @@ public:
void viewNotifications(); void viewNotifications();
void logout(); void logout();
void changePassword(); void changePassword();
}; };
@@ -106,7 +106,7 @@ void UserInterface::login()
std::cout << "Enter username: "; std::cout << "Enter username: ";
util::read(username); util::read(username);
std::cout << "Enter password: "; std::cout << "Enter password: ";
util::read(password); util::readPassword(password);
if (m_controller.login(username, password)) if (m_controller.login(username, password))
{ {
const User* authenticatedUser = m_controller.getAuthenticatedUser(); const User* authenticatedUser = m_controller.getAuthenticatedUser();
@@ -167,7 +167,7 @@ void UserInterface::registerCustomer()
return; return;
} }
std::cout << "Enter password: "; std::cout << "Enter password: ";
util::read(password); util::readPassword(password);
if (!util::isPasswordValid(password)) if (!util::isPasswordValid(password))
{ {
std::cout << "Error: Password is invalid!"; std::cout << "Error: Password is invalid!";
@@ -185,4 +185,4 @@ void UserInterface::registerCustomer()
m_controller.createCustomer(username, name, password, email, phone); m_controller.createCustomer(username, name, password, email, phone);
std::cout << "Registration is successful"; std::cout << "Registration is successful";
util::pressEnter(); util::pressEnter();
} }