fsfw/datapoollocal/LocalDataPoolManager.cpp

98 lines
3.2 KiB
C++
Raw Normal View History

2020-06-07 02:22:18 +02:00
#include <framework/datapoollocal/LocalDataPoolManager.h>
2020-06-05 20:35:08 +02:00
#include <framework/datapoollocal/LocalDataSet.h>
2020-05-17 01:17:11 +02:00
#include <framework/returnvalues/HasReturnvaluesIF.h>
2020-06-07 18:53:55 +02:00
#include <framework/objectmanager/frameworkObjects.h>
2020-05-17 01:17:11 +02:00
#include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h>
2020-06-05 20:35:08 +02:00
#include <array>
2020-06-07 02:22:18 +02:00
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) {
2020-05-17 01:17:11 +02:00
if(owner == nullptr) {
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
std::exit(0);
}
this->owner = owner;
mutex = MutexFactory::instance()->createMutex();
2020-06-07 18:53:55 +02:00
if(mutex == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not create mutex." << std::endl;
}
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if(ipcStore == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not set IPC store." << std::endl;
}
2020-05-17 01:17:11 +02:00
}
2020-06-07 02:22:18 +02:00
LocalDataPoolManager::~LocalDataPoolManager() {}
2020-05-17 01:17:11 +02:00
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
2020-05-17 01:17:11 +02:00
if(not mapInitialized) {
2020-06-07 02:22:18 +02:00
ReturnValue_t result =
owner->initializeHousekeepingPoolEntries(localDpMap);
2020-05-17 01:17:11 +02:00
if(result == HasReturnvaluesIF::RETURN_OK) {
mapInitialized = true;
}
return result;
}
2020-06-05 20:35:08 +02:00
sif::warning << "HousekeepingManager: The map" << std::endl;
2020-05-17 01:17:11 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
HousekeepingMessage& message) {
return HasReturnvaluesIF::RETURN_FAILED;
2020-05-17 01:17:11 +02:00
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::printPoolEntry(
2020-06-05 20:35:08 +02:00
lp_id_t localPoolId) {
auto poolIter = localDpMap.find(localPoolId);
if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl;
2020-06-07 02:22:18 +02:00
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
2020-06-05 20:35:08 +02:00
}
poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-07 02:22:18 +02:00
MutexIF* LocalDataPoolManager::getMutexHandle() {
2020-05-17 01:17:11 +02:00
return mutex;
}
2020-06-07 18:53:55 +02:00
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
2020-06-05 20:35:08 +02:00
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
2020-06-07 18:53:55 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
store_address_t storeId;
size_t hkSize = dataSetToSerialize->getSerializedSize();
uint8_t* storePtr = nullptr;
ReturnValue_t result = ipcStore->getFreeElement(&storeId, hkSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result;
2020-06-05 20:35:08 +02:00
}
size_t size = 0;
2020-06-07 18:53:55 +02:00
dataSetToSerialize->serialize(&storePtr, &size, hkSize, false);
// and now we have to set a HK message and send it the queue.
return HasReturnvaluesIF::RETURN_OK;
2020-05-17 01:17:11 +02:00
}
2020-06-07 02:22:18 +02:00
void LocalDataPoolManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
2020-05-17 01:17:11 +02:00
this->hkPacketQueue = msgQueue;
}
2020-06-05 20:35:08 +02:00
2020-06-07 18:53:55 +02:00
void LocalDataPoolManager::setHkReplyQueue(MessageQueueIF *replyQueue) {
this->hkReplyQueue = replyQueue;
}
2020-06-07 02:22:18 +02:00
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
2020-06-05 20:35:08 +02:00
return owner;
}