diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp index 3419f44..0efc02d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp @@ -9,6 +9,137 @@ Date: 19-May-2026 */ #include "DataStore.h" +#include "Config.h" +#include "SerializedRecords.h" + +DataStore::DataStore() : + m_globalMutex(NULL) {} + +/* +Function: initialize +Description: Initializes the shared-memory datastore. + Creates or opens the global datastore mutex, + configures all mapping metadata, and creates + or opens the file mappings used to persist + application data. After successful completion, + all datastore files are mapped into memory and + ready for use by the application. +Parameter: None +Return type: bool + - true : Initialization completed successfully. + - false : Failed to create the mutex or open + one or more file mappings. +*/ +bool DataStore::initialize() +{ + m_globalMutex = CreateMutexA(NULL, FALSE, "VehicleServiceSystemMutex"); + if (m_globalMutex == NULL) + { + return false; + } + 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)) + { + return false; + } + if (!SharedMemory::createOrOpenMapping(m_notifications)) + { + return false; + } + if (!SharedMemory::createOrOpenMapping(m_services)) + { + return false; + } + if (!SharedMemory::createOrOpenMapping(m_comboPackages)) + { + 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; +} + +/* +Function: shutdown +Description: Releases all shared-memory resources owned by the + datastore. Closes every file mapping, unmaps all + mapped views, and releases the datastore mutex. + After this call, the datastore must be initialized + again before use. +Parameter: None +Return type: void +*/ +void DataStore::shutdown() +{ + SharedMemory::closeMapping(m_users); + SharedMemory::closeMapping(m_notifications); + SharedMemory::closeMapping(m_services); + SharedMemory::closeMapping(m_comboPackages); + SharedMemory::closeMapping(m_inventoryItems); + SharedMemory::closeMapping(m_serviceBookings); + SharedMemory::closeMapping(m_jobCards); + SharedMemory::closeMapping(m_invoices); + SharedMemory::closeMapping(m_payments); + SharedMemory::closeMapping(m_serviceManagementObservers); + SharedMemory::closeMapping(m_paymentManagementObservers); + SharedMemory::closeMapping(m_inventoryManagementObservers); + if (m_globalMutex != NULL) + { + CloseHandle(m_globalMutex); + m_globalMutex = NULL; + } +} /* Function: getInstance @@ -26,104 +157,326 @@ DataStore& DataStore::getInstance() /* Function: getUsers -Description: Retrieves the internal map of users. +Description: Retrieves all user records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all users. + - util::Map>: Collection of user records */ -util::Map& DataStore::getUsers() +util::Map> DataStore::getUsers() { - return m_users; + return util::Map>(); +} + +/* +Function: getNotifications +Description: Retrieves all notification records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of notification records +*/ +util::Map> DataStore::getNotifications() +{ + return util::Map>(); } /* Function: getServices -Description: Retrieves the internal map of services. +Description: Retrieves all service records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all services. + - util::Map>: Collection of service records */ -util::Map& DataStore::getServices() +util::Map> DataStore::getServices() { - return m_services; + return util::Map>(); } /* Function: getComboPackages -Description: Retrieves the internal map of combo packages. +Description: Retrieves all combo package records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all combo packages. + - util::Map>: Collection of combo package records */ -util::Map& DataStore::getComboPackages() +util::Map> DataStore::getComboPackages() { - return m_comboPackages; -} - -/* -Function: getServiceBookings -Description: Retrieves the internal map of service bookings. -Parameters: - - None -Returns: - - Reference to util::Map containing all service bookings. -*/ -util::Map& DataStore::getServiceBookings() -{ - return m_serviceBookings; -} - -/* -Function: getJobCards -Description: Retrieves the internal map of job cards. -Parameters: - - None -Returns: - - Reference to util::Map containing all job cards. -*/ -util::Map& DataStore::getJobCards() -{ - return m_jobCards; + return util::Map>(); } /* Function: getInventoryItems -Description: Retrieves the internal map of inventory items. +Description: Retrieves all inventory item records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all inventory items. + - util::Map>: Collection of inventory item records */ -util::Map& DataStore::getInventoryItems() +util::Map> DataStore::getInventoryItems() { - return m_inventoryItems; + return util::Map>(); +} + +/* +Function: getServiceBookings +Description: Retrieves all service booking records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of service booking records +*/ +util::Map> DataStore::getServiceBookings() +{ + return util::Map>(); +} + +/* +Function: getJobCards +Description: Retrieves all job card records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of job card records +*/ +util::Map> DataStore::getJobCards() +{ + return util::Map>(); } /* Function: getInvoices -Description: Retrieves the internal map of invoices. +Description: Retrieves all invoice records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all invoices. + - util::Map>: Collection of invoice records */ -util::Map& DataStore::getInvoices() +util::Map> DataStore::getInvoices() { - return m_invoices; + return util::Map>(); } /* Function: getPayments -Description: Retrieves the internal map of payments. +Description: Retrieves all payment records from the datastore. Parameters: - None Returns: - - Reference to util::Map containing all payments. + - util::Map>: Collection of payment records */ -util::Map& DataStore::getPayments() +util::Map> DataStore::getPayments() { - return m_payments; + return util::Map>(); +} + +/* +Function: getServiceManagementObservers +Description: Retrieves all service management observer records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of observer records +*/ +util::Map> DataStore::getServiceManagementObservers() +{ + return util::Map>(); +} + +/* +Function: getPaymentManagementObservers +Description: Retrieves all payment management observer records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of observer records +*/ +util::Map> DataStore::getPaymentManagementObservers() +{ + return util::Map>(); +} + +/* +Function: getInventoryManagementObservers +Description: Retrieves all inventory management observer records from the datastore. +Parameters: + - None +Returns: + - util::Map>: Collection of observer records +*/ +util::Map> DataStore::getInventoryManagementObservers() +{ + return util::Map>(); +} + +/* +Function: saveUsers +Description: Persists all user records to the datastore. +Parameters: + - users: util::Map>&, collection of user records +Returns: + - None +*/ +void DataStore::saveUsers(util::Map>& users) +{ +} + +/* +Function: saveNotifications +Description: Persists all notification records to the datastore. +Parameters: + - notifications: util::Map>&, collection of notification records +Returns: + - None +*/ +void DataStore::saveNotifications(util::Map>& notifications) +{ +} + +/* +Function: saveServices +Description: Persists all service records to the datastore. +Parameters: + - services: util::Map>&, collection of service records +Returns: + - None +*/ +void DataStore::saveServices(util::Map>& services) +{ +} + +/* +Function: saveComboPackages +Description: Persists all combo package records to the datastore. +Parameters: + - comboPackages: util::Map>&, collection of combo package records +Returns: + - None +*/ +void DataStore::saveComboPackages(util::Map>& comboPackages) +{ +} + +/* +Function: saveInventoryItems +Description: Persists all inventory item records to the datastore. +Parameters: + - inventoryItems: util::Map>&, collection of inventory item records +Returns: + - None +*/ +void DataStore::saveInventoryItems(util::Map>& inventoryItems) +{ +} + +/* +Function: saveServiceBookings +Description: Persists all service booking records to the datastore. +Parameters: + - bookings: util::Map>&, collection of service booking records +Returns: + - None +*/ +void DataStore::saveServiceBookings(util::Map>& bookings) +{ +} + +/* +Function: saveJobCards +Description: Persists all job card records to the datastore. +Parameters: + - jobCards: util::Map>&, collection of job card records +Returns: + - None +*/ +void DataStore::saveJobCards(util::Map>& jobCards) +{ +} + +/* +Function: saveInvoices +Description: Persists all invoice records to the datastore. +Parameters: + - invoices: util::Map>&, collection of invoice records +Returns: + - None +*/ +void DataStore::saveInvoices(util::Map>& invoices) +{ +} + +/* +Function: savePayments +Description: Persists all payment records to the datastore. +Parameters: + - payments: util::Map>&, collection of payment records +Returns: + - None +*/ +void DataStore::savePayments(util::Map>& payments) +{ +} + +/* +Function: saveServiceManagementObservers +Description: Persists all service management observer records to the datastore. +Parameters: + - observers: util::Map>&, collection of observer records +Returns: + - None +*/ +void DataStore::saveServiceManagementObservers(util::Map>& observers) +{ +} + +/* +Function: savePaymentManagementObservers +Description: Persists all payment management observer records to the datastore. +Parameters: + - observers: util::Map>&, collection of observer records +Returns: + - None +*/ +void DataStore::savePaymentManagementObservers(util::Map>& observers) +{ +} + +/* +Function: saveInventoryManagementObservers +Description: Persists all inventory management observer records to the datastore. +Parameters: + - observers: util::Map>&, collection of observer records +Returns: + - None +*/ +void DataStore::saveInventoryManagementObservers(util::Map>& observers) +{ +} + +/* +Function: lockDataStore +Description: Acquires exclusive access to the datastore. +Parameters: + - None +Returns: + - bool: True if the datastore was successfully locked, otherwise false +*/ +bool DataStore::lockDataStore() +{ + return false; +} + +/* +Function: unlockDataStore +Description: Releases exclusive access to the datastore. +Parameters: + - None +Returns: + - bool: True if the datastore was successfully unlocked, otherwise false +*/ +bool DataStore::unlockDataStore() +{ + return false; } \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.h index 3a2e9fa..a0d6ae0 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.h @@ -40,6 +40,9 @@ private: MappingInfo m_jobCards; MappingInfo m_invoices; MappingInfo m_payments; + MappingInfo m_serviceManagementObservers; + MappingInfo m_paymentManagementObservers; + MappingInfo m_inventoryManagementObservers; public: static DataStore& getInstance(); bool initialize(); @@ -53,6 +56,9 @@ public: util::Map> getJobCards(); util::Map> getInvoices(); util::Map> getPayments(); + util::Map> getServiceManagementObservers(); + util::Map> getPaymentManagementObservers(); + util::Map> getInventoryManagementObservers(); void saveUsers(util::Map>& users); void saveNotifications(util::Map>& notifications); void saveServices(util::Map>& services); @@ -62,6 +68,9 @@ public: void saveJobCards(util::Map>& jobCards); void saveInvoices(util::Map>& invoices); void savePayments(util::Map>& payments); + void saveServiceManagementObservers(util::Map>& observers); + void savePaymentManagementObservers(util::Map>& observers); + void saveInventoryManagementObservers(util::Map>& observers); bool lockDataStore(); bool unlockDataStore(); private: diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SerializedRecords.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SerializedRecords.h index d376183..62dfacf 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SerializedRecords.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SerializedRecords.h @@ -90,3 +90,8 @@ struct SerializedInvoice util::PaymentMode paymentMethod; util::PaymentStatus status; }; + +struct SerializedObserver +{ + char id[64]; +}; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SharedMemory.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SharedMemory.cpp index e48107e..aa0c494 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SharedMemory.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/sharedmemory/SharedMemory.cpp @@ -167,24 +167,6 @@ void* SharedMemory::getRecordAddress(MappingInfo& mapping, size_t index) return reinterpret_cast(mapping.mappedView) + sizeof(FileHeader) + index * mapping.recordSize; } -/* -Function: getRecordAddress -Description: Returns the address of a record at the specified index within the mapped memory region. -Parameters: - - mapping: MappingInfo&, mapping information and handles - - index: size_t, record index -Returns: - - void*: Pointer to the record, or nullptr if the mapping is not valid -*/ -void* SharedMemory::getRecordAddress(MappingInfo& mapping, size_t index) -{ - if (mapping.mappedView == nullptr) - { - return nullptr; - } - return reinterpret_cast(mapping.mappedView) + sizeof(FileHeader) + index * mapping.recordSize; -} - /* Function: getRecordCount Description: Returns the number of records currently stored in the mapping. diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h index dd5eaa8..bddaf61 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h @@ -29,16 +29,16 @@ namespace config namespace file { const size_t INITIAL_CAPACITY = 100; - constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.csv"; - constexpr const char* USER_FILE = "files/User.csv"; - constexpr const char* NOTIFICATION_FILE = "files/Notification.csv"; - constexpr const char* SERVICE_FILE = "files/Service.csv"; - constexpr const char* COMBOPACKAGE_FILE = "files/ComboPackage.csv"; - constexpr const char* SERVICEBOOKING_FILE = "files/ServiceBooking.csv"; - constexpr const char* JOBCARD_FILE = "files/JobCard.csv"; - constexpr const char* INVOICE_FILE = "files/Invoice.csv"; - constexpr const char* SERVICEMANAGEMENTOBSERVERS = "files/ServiceManagementObservers.csv"; - constexpr const char* PAYMENTMANAGEMENTOBSERVERS = "files/PaymentManagementObservers.csv"; - constexpr const char* INVENTORYMANAGEMENTOBSERVERS = "files/InventoryManagementObservers.csv"; + constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.dat"; + constexpr const char* USER_FILE = "files/User.dat"; + constexpr const char* NOTIFICATION_FILE = "files/Notification.dat"; + constexpr const char* SERVICE_FILE = "files/Service.dat"; + constexpr const char* COMBOPACKAGE_FILE = "files/ComboPackage.dat"; + constexpr const char* SERVICEBOOKING_FILE = "files/ServiceBooking.dat"; + constexpr const char* JOBCARD_FILE = "files/JobCard.dat"; + constexpr const char* INVOICE_FILE = "files/Invoice.dat"; + constexpr const char* SERVICEMANAGEMENTOBSERVERS = "files/ServiceManagementObservers.dat"; + constexpr const char* PAYMENTMANAGEMENTOBSERVERS = "files/PaymentManagementObservers.dat"; + constexpr const char* INVENTORYMANAGEMENTOBSERVERS = "files/InventoryManagementObservers.dat"; } }