2020-09-05 21:19:53 +02:00
|
|
|
#include "QueueMapManager.h"
|
|
|
|
|
2021-02-28 13:56:16 +01:00
|
|
|
#include "../../serviceinterface/ServiceInterface.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
#include "../../ipc/MutexFactory.h"
|
2021-03-20 12:49:15 +01:00
|
|
|
#include "../../ipc/MutexGuard.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
|
|
|
|
QueueMapManager* QueueMapManager::mqManagerInstance = nullptr;
|
|
|
|
|
|
|
|
QueueMapManager::QueueMapManager() {
|
|
|
|
mapLock = MutexFactory::instance()->createMutex();
|
|
|
|
}
|
|
|
|
|
2021-04-08 18:57:24 +02:00
|
|
|
QueueMapManager::~QueueMapManager() {
|
|
|
|
MutexFactory::instance()->deleteMutex(mapLock);
|
|
|
|
}
|
|
|
|
|
2020-09-05 20:18:52 +02:00
|
|
|
QueueMapManager* QueueMapManager::instance() {
|
2021-05-27 13:12:34 +02:00
|
|
|
if (mqManagerInstance == nullptr){
|
|
|
|
mqManagerInstance = new QueueMapManager();
|
|
|
|
}
|
|
|
|
return QueueMapManager::mqManagerInstance;
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t QueueMapManager::addMessageQueue(
|
2021-05-27 13:12:34 +02:00
|
|
|
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
|
|
|
MutexGuard lock(mapLock);
|
|
|
|
uint32_t currentId = queueCounter++;
|
2021-07-19 14:40:32 +02:00
|
|
|
if(currentId == MessageQueueIF::NO_QUEUE) {
|
|
|
|
// Skip the NO_QUEUE value
|
|
|
|
currentId = queueCounter++;
|
|
|
|
}
|
2021-05-27 13:12:34 +02:00
|
|
|
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
|
|
|
if(not returnPair.second) {
|
|
|
|
/* This should never happen for the atomic variable. */
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-05-27 13:12:34 +02:00
|
|
|
sif::error << "QueueMapManager::addMessageQueue This ID is already "
|
|
|
|
"inside the map!" << std::endl;
|
2021-02-04 13:46:27 +01:00
|
|
|
#else
|
2021-05-27 13:12:34 +02:00
|
|
|
sif::printError("QueueMapManager::addMessageQueue This ID is already "
|
2021-02-04 13:46:27 +01:00
|
|
|
"inside the map!\n");
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2021-05-27 13:12:34 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (id != nullptr) {
|
|
|
|
*id = currentId;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueIF* QueueMapManager::getMessageQueue(
|
2021-05-27 13:12:34 +02:00
|
|
|
MessageQueueId_t messageQueueId) const {
|
|
|
|
auto queueIter = queueMap.find(messageQueueId);
|
|
|
|
if(queueIter != queueMap.end()) {
|
|
|
|
return queueIter->second;
|
|
|
|
}
|
|
|
|
else {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-05-27 13:12:34 +02:00
|
|
|
sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId <<
|
|
|
|
" does not exists in the map!" << std::endl;
|
2021-02-04 13:46:27 +01:00
|
|
|
#else
|
2021-05-27 13:12:34 +02:00
|
|
|
sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n",
|
|
|
|
messageQueueId);
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2021-05-27 13:12:34 +02:00
|
|
|
}
|
|
|
|
return nullptr;
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|