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/ipc/MutexFactory.h>
|
|
|
|
#include <framework/ipc/MutexHelper.h>
|
2020-06-19 03:03:17 +02:00
|
|
|
#include <framework/ipc/QueueFactory.h>
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-06-05 20:35:08 +02:00
|
|
|
#include <array>
|
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner,
|
|
|
|
uint32_t replyQueueDepth, bool appendValidityBuffer):
|
|
|
|
appendValidityBuffer(appendValidityBuffer) {
|
2020-05-17 01:17:11 +02:00
|
|
|
if(owner == nullptr) {
|
|
|
|
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
|
2020-06-19 03:03:17 +02:00
|
|
|
return;
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
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-06-19 03:03:17 +02:00
|
|
|
hkQueue = QueueFactory::instance()->createMessageQueue(replyQueueDepth,
|
|
|
|
HousekeepingMessage::HK_MESSAGE_SIZE);
|
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 =
|
2020-06-19 14:25:03 +02:00
|
|
|
owner->initializePoolEntries(localDpMap);
|
2020-05-17 01:17:11 +02:00
|
|
|
if(result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
mapInitialized = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2020-06-19 03:03:17 +02:00
|
|
|
sif::warning << "HousekeepingManager: The map should only be initialized "
|
|
|
|
"once!" << 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(
|
2020-06-13 17:37:48 +02:00
|
|
|
HousekeepingMessage& message) {
|
2020-06-19 03:03:17 +02:00
|
|
|
Command_t command = message.getCommand();
|
|
|
|
switch(command) {
|
2020-06-19 14:25:03 +02:00
|
|
|
// I think those are the only commands which can be handled here..
|
|
|
|
case(HousekeepingMessage::ADD_HK_REPORT_STRUCT):
|
|
|
|
case(HousekeepingMessage::ADD_DIAGNOSTICS_REPORT_STRUCT):
|
|
|
|
// We should use OwnsLocalPoolDataIF to specify those functions..
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
|
|
|
|
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
|
|
|
|
return generateSetStructurePacket(message.getSid());
|
2020-06-19 03:03:17 +02:00
|
|
|
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
|
|
|
|
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT):
|
|
|
|
return generateHousekeepingPacket(message.getSid());
|
|
|
|
default:
|
|
|
|
return CommandMessageIF::UNKNOWN_COMMAND;
|
|
|
|
}
|
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-19 03:03:17 +02:00
|
|
|
return 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-19 03:03:17 +02:00
|
|
|
void LocalDataPoolManager::setHkPacketDestination(
|
|
|
|
MessageQueueId_t destinationQueueId) {
|
|
|
|
this->currentHkPacketDestination = destinationQueueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
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;
|
2020-06-19 03:03:17 +02:00
|
|
|
ReturnValue_t result = serializeHkPacketIntoStore(&storeId,
|
|
|
|
dataSetToSerialize);
|
2020-06-07 18:53:55 +02:00
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
2020-06-05 20:35:08 +02:00
|
|
|
}
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
// and now we set a HK message and send it the HK packet destination.
|
|
|
|
MessageQueueMessage message;
|
|
|
|
HousekeepingMessage hkMessage(&message);
|
|
|
|
hkMessage.setHkReportMessage(sid, storeId);
|
|
|
|
if(hkQueue == nullptr) {
|
|
|
|
return QUEUE_NOT_SET;
|
|
|
|
}
|
2020-06-05 20:35:08 +02:00
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
if(currentHkPacketDestination != MessageQueueIF::NO_QUEUE) {
|
|
|
|
result = hkQueue->sendMessage(currentHkPacketDestination, &hkMessage);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = hkQueue->sendToDefault(&hkMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2020-06-07 18:53:55 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 14:25:03 +02:00
|
|
|
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid) {
|
|
|
|
LocalDataSet* dataSet = dynamic_cast<LocalDataSet*>(
|
|
|
|
owner->getDataSetHandle(sid));
|
|
|
|
if(dataSet == nullptr) {
|
|
|
|
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
|
|
|
|
" Set ID not found" << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
size_t expectedSize = dataSet->getFillCount() * sizeof(lp_id_t);
|
|
|
|
uint8_t* storePtr = nullptr;
|
|
|
|
store_address_t storeId;
|
|
|
|
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
|
|
|
expectedSize,&storePtr);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
|
|
|
|
"Could not get free element from IPC store." << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
size_t size = 0;
|
|
|
|
result = dataSet->serializeLocalPoolIds(&storePtr, &size,
|
|
|
|
expectedSize, false);
|
|
|
|
if(expectedSize != size) {
|
|
|
|
sif::error << "HousekeepingManager::generateSetStructurePacket: "
|
|
|
|
"Expected size is not equal to serialized size" << std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-19 03:03:17 +02:00
|
|
|
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
|
|
|
|
store_address_t *storeId, LocalDataSet* dataSet) {
|
|
|
|
size_t hkSize = dataSet->getSerializedSize();
|
|
|
|
uint8_t* storePtr = nullptr;
|
|
|
|
ReturnValue_t result = ipcStore->getFreeElement(storeId, hkSize,&storePtr);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
2020-06-19 14:25:03 +02:00
|
|
|
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
|
2020-06-19 03:03:17 +02:00
|
|
|
"Could not get free element from IPC store." << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
if(appendValidityBuffer) {
|
|
|
|
result = dataSet->serializeWithValidityBuffer(&storePtr,
|
|
|
|
&size, hkSize, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = dataSet->serialize(&storePtr, &size, hkSize, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "HousekeepingManager::serializeHkPacketIntoStore: "
|
|
|
|
"Serialization proccess failed!" << std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
2020-06-05 20:35:08 +02:00
|
|
|
}
|
2020-06-19 03:03:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|