changes
This commit is contained in:
@@ -340,6 +340,37 @@ util::Map<std::string, TrackedRecord<Invoice>>& DataStore::getInvoices()
|
|||||||
return m_invoiceCache;
|
return m_invoiceCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getObservers
|
||||||
|
Description: Retrieves observer records from the specified observer mapping
|
||||||
|
and resolves them to User objects.
|
||||||
|
Parameters:
|
||||||
|
- mapping: Observer mapping to read from
|
||||||
|
Returns:
|
||||||
|
- util::Map<std::string, User*>: Collection of observer records
|
||||||
|
Throws:
|
||||||
|
- std::runtime_error if an observer references an invalid user ID
|
||||||
|
*/
|
||||||
|
util::Map<std::string, User*> DataStore::getObservers(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
auto& users = getUsers();
|
||||||
|
util::Map<std::string, User*> observers;
|
||||||
|
SharedMemory::ensureLatestMapping(mapping);
|
||||||
|
size_t recordCount = SharedMemory::getRecordCount(mapping);
|
||||||
|
for (size_t index = 0; index < recordCount; index++)
|
||||||
|
{
|
||||||
|
const SerializedObserver* observer = static_cast<SerializedObserver*>(SharedMemory::getRecordAddress(mapping, index));
|
||||||
|
int userIndex = users.find(observer->id);
|
||||||
|
if (userIndex == -1)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid observer user ID");
|
||||||
|
}
|
||||||
|
User* user = users.getValueAt(userIndex).data;
|
||||||
|
observers.insert(user->getId(), user);
|
||||||
|
}
|
||||||
|
return observers;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: getServiceManagementObservers
|
Function: getServiceManagementObservers
|
||||||
Description: Retrieves all service management observer records from the datastore.
|
Description: Retrieves all service management observer records from the datastore.
|
||||||
@@ -350,7 +381,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
util::Map<std::string, User*> DataStore::getServiceManagementObservers()
|
util::Map<std::string, User*> DataStore::getServiceManagementObservers()
|
||||||
{
|
{
|
||||||
return util::Map<std::string, User*>();
|
return getObservers(m_serviceManagementObservers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -363,7 +394,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
util::Map<std::string, User*> DataStore::getPaymentManagementObservers()
|
util::Map<std::string, User*> DataStore::getPaymentManagementObservers()
|
||||||
{
|
{
|
||||||
return util::Map<std::string, User*>();
|
return getObservers(m_paymentManagementObservers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -376,7 +407,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
util::Map<std::string, User*> DataStore::getInventoryManagementObservers()
|
util::Map<std::string, User*> DataStore::getInventoryManagementObservers()
|
||||||
{
|
{
|
||||||
return util::Map<std::string, User*>();
|
return getObservers(m_inventoryManagementObservers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -478,16 +509,49 @@ void DataStore::saveInvoices()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: saveObservers
|
||||||
|
Description: Persists observer records to the specified observer mapping.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, observer mapping to save to
|
||||||
|
- observers: util::Map<std::string, User*>&, collection of observer records
|
||||||
|
Returns:
|
||||||
|
- None
|
||||||
|
*/
|
||||||
|
void DataStore::saveObservers(MappingInfo& mapping, util::Map<std::string, User*>& observers)
|
||||||
|
{
|
||||||
|
size_t observerCount = static_cast<size_t>(observers.getSize());
|
||||||
|
size_t capacity = config::file::INITIAL_CAPACITY;
|
||||||
|
while (capacity < observerCount)
|
||||||
|
{
|
||||||
|
capacity *= config::file::GROWTH_FACTOR;
|
||||||
|
}
|
||||||
|
if (!SharedMemory::resizeMapping(mapping, capacity))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Failed to resize observer mapping");
|
||||||
|
}
|
||||||
|
SharedMemory::setRecordCount(mapping, observerCount);
|
||||||
|
for (size_t index = 0; index < observerCount; index++)
|
||||||
|
{
|
||||||
|
SerializedObserver serializedObserver;
|
||||||
|
User* user = observers.getValueAt(static_cast<int>(index));
|
||||||
|
strcpy_s(serializedObserver.id, user->getId().c_str());
|
||||||
|
SerializedObserver* destination = static_cast<SerializedObserver*>(SharedMemory::getRecordAddress(mapping, index));
|
||||||
|
*destination = serializedObserver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: saveServiceManagementObservers
|
Function: saveServiceManagementObservers
|
||||||
Description: Persists all service management observer records to the datastore.
|
Description: Persists all service management observer records to the datastore.
|
||||||
Parameters:
|
Parameters:
|
||||||
- observers: util::Map<std::string, TrackedRecord<std::string>>&, collection of observer records
|
- observers: util::Map<std::string, User*>&, collection of observer records
|
||||||
Returns:
|
Returns:
|
||||||
- None
|
- None
|
||||||
*/
|
*/
|
||||||
void DataStore::saveServiceManagementObservers(util::Map<std::string, User*>& observers)
|
void DataStore::saveServiceManagementObservers(util::Map<std::string, User*>& observers)
|
||||||
{
|
{
|
||||||
|
saveObservers(m_serviceManagementObservers, observers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -500,6 +564,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
void DataStore::savePaymentManagementObservers(util::Map<std::string, User*>& observers)
|
void DataStore::savePaymentManagementObservers(util::Map<std::string, User*>& observers)
|
||||||
{
|
{
|
||||||
|
saveObservers(m_paymentManagementObservers, observers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -512,6 +577,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
void DataStore::saveInventoryManagementObservers(util::Map<std::string, User*>& observers)
|
void DataStore::saveInventoryManagementObservers(util::Map<std::string, User*>& observers)
|
||||||
{
|
{
|
||||||
|
saveObservers(m_inventoryManagementObservers, observers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ private:
|
|||||||
void saveRecords(MappingInfo& mapping, util::Map<std::string, TrackedRecord<TObject>>& records);
|
void saveRecords(MappingInfo& mapping, util::Map<std::string, TrackedRecord<TObject>>& records);
|
||||||
template<typename TObject> void clearCache(util::Map<std::string, TrackedRecord<TObject>>&cache);
|
template<typename TObject> void clearCache(util::Map<std::string, TrackedRecord<TObject>>&cache);
|
||||||
template<typename TObject> void refreshCache(util::Map<std::string, TrackedRecord<TObject>>&cache, util::Map<std::string, TrackedRecord<TObject>>&refreshedCache);
|
template<typename TObject> void refreshCache(util::Map<std::string, TrackedRecord<TObject>>&cache, util::Map<std::string, TrackedRecord<TObject>>&refreshedCache);
|
||||||
|
util::Map<std::string, User*> getObservers(MappingInfo& mapping);
|
||||||
|
void saveObservers(MappingInfo& mapping, util::Map<std::string, User*>& observers);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+1
-1
@@ -320,7 +320,7 @@ bool SharedMemory::ensureCapacityForInsert(MappingInfo& mapping)
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return resizeMapping(mapping, capacity * 2);
|
return resizeMapping(mapping, capacity * config::file::GROWTH_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+4
@@ -26,6 +26,7 @@ Date:19-May-2026
|
|||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "UserManagementService.h"
|
#include "UserManagementService.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
#include "DataStoreLockGuard.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: purchaseService
|
Function: purchaseService
|
||||||
@@ -122,6 +123,9 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
void ServiceManagementService::attach(User* user)
|
void ServiceManagementService::attach(User* user)
|
||||||
{
|
{
|
||||||
|
DataStoreLockGuard lock(m_dataStore);
|
||||||
|
m_observers.clear();
|
||||||
|
m_observers = m_dataStore.getServiceManagementObservers();
|
||||||
if (user)
|
if (user)
|
||||||
{
|
{
|
||||||
const std::string& userID = user->getId();
|
const std::string& userID = user->getId();
|
||||||
|
|||||||
-2
@@ -53,6 +53,4 @@ public:
|
|||||||
void saveServiceBookings();
|
void saveServiceBookings();
|
||||||
void loadJobCards();
|
void loadJobCards();
|
||||||
void saveJobCards();
|
void saveJobCards();
|
||||||
void loadObservers();
|
|
||||||
void saveObservers();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace config
|
|||||||
namespace file
|
namespace file
|
||||||
{
|
{
|
||||||
const size_t INITIAL_CAPACITY = 100;
|
const size_t INITIAL_CAPACITY = 100;
|
||||||
|
const size_t GROWTH_FACTOR = 2;
|
||||||
constexpr const char* DIRECTORY = "files/";
|
constexpr const char* DIRECTORY = "files/";
|
||||||
constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.dat";
|
constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.dat";
|
||||||
constexpr const char* USER_FILE = "files/User.dat";
|
constexpr const char* USER_FILE = "files/User.dat";
|
||||||
|
|||||||
Reference in New Issue
Block a user