fsfw/src/fsfw/osal/freertos/QueueMapManager.cpp

64 lines
2.0 KiB
C++
Raw Normal View History

2021-07-14 00:54:39 +02:00
#include "fsfw/osal/freertos/QueueMapManager.h"
2022-02-02 10:29:30 +01:00
2021-07-14 00:54:39 +02:00
#include "fsfw/ipc/MutexFactory.h"
#include "fsfw/ipc/MutexGuard.h"
2021-05-27 13:12:34 +02:00
2021-05-27 13:38:40 +02:00
QueueMapManager* QueueMapManager::mqManagerInstance = nullptr;
2022-02-02 10:29:30 +01:00
QueueMapManager::QueueMapManager() { mapLock = MutexFactory::instance()->createMutex(); }
2021-05-27 13:12:34 +02:00
2021-05-27 13:38:40 +02:00
QueueMapManager* QueueMapManager::instance() {
2022-02-02 10:29:30 +01:00
if (mqManagerInstance == nullptr) {
mqManagerInstance = new QueueMapManager();
}
return QueueMapManager::mqManagerInstance;
2021-05-27 13:38:40 +02:00
}
2021-05-27 13:12:34 +02:00
ReturnValue_t QueueMapManager::addMessageQueue(QueueHandle_t queue, MessageQueueId_t* id) {
2022-02-02 10:29:30 +01:00
MutexGuard lock(mapLock);
uint32_t currentId = queueCounter;
queueCounter++;
if (currentId == MessageQueueIF::NO_QUEUE) {
// Skip the NO_QUEUE value
currentId = queueCounter;
2021-07-19 15:01:43 +02:00
queueCounter++;
2022-02-02 10:29:30 +01:00
}
auto returnPair = queueMap.emplace(currentId, queue);
if (not returnPair.second) {
2021-05-27 13:12:34 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "QueueMapManager::addMessageQueue This ID is already "
"inside the map!"
<< std::endl;
2021-05-27 13:12:34 +02:00
#else
2022-05-18 10:51:38 +02:00
// TODO: FMTLOG
// sif::printError(
// "QueueMapManager::addMessageQueue This ID is already "
// "inside the map!\n");
2021-05-27 13:12:34 +02:00
#endif
2022-02-02 10:29:30 +01:00
return HasReturnvaluesIF::RETURN_FAILED;
}
if (id != nullptr) {
*id = currentId;
}
return HasReturnvaluesIF::RETURN_OK;
2021-05-27 13:12:34 +02:00
}
QueueHandle_t QueueMapManager::getMessageQueue(MessageQueueId_t messageQueueId) const {
2022-02-02 10:29:30 +01:00
auto queueIter = queueMap.find(messageQueueId);
if (queueIter != queueMap.end()) {
return queueIter->second;
} else {
2021-05-27 13:12:34 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId
<< " does not exists in the map!" << std::endl;
2021-05-27 13:12:34 +02:00
#else
2022-05-18 10:51:38 +02:00
// TODO: FMTLOG
// sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n",
// messageQueueId);
2021-05-27 13:12:34 +02:00
#endif
2022-02-02 10:29:30 +01:00
}
return nullptr;
2021-05-27 13:12:34 +02:00
}
2022-02-02 10:29:30 +01:00
QueueMapManager::~QueueMapManager() { MutexFactory::instance()->deleteMutex(mapLock); }