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-09 21:25:22 +01:00
|
|
|
#include "../../ipc/MutexGuard.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
|
|
|
|
QueueMapManager* QueueMapManager::mqManagerInstance = nullptr;
|
|
|
|
|
|
|
|
QueueMapManager::QueueMapManager() {
|
|
|
|
mapLock = MutexFactory::instance()->createMutex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueMapManager* QueueMapManager::instance() {
|
|
|
|
if (mqManagerInstance == nullptr){
|
|
|
|
mqManagerInstance = new QueueMapManager();
|
|
|
|
}
|
|
|
|
return QueueMapManager::mqManagerInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t QueueMapManager::addMessageQueue(
|
|
|
|
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
2021-02-04 13:46:27 +01:00
|
|
|
/* Not thread-safe, but it is assumed all message queues are created at software initialization
|
|
|
|
now. If this is to be made thread-safe in the future, it propably would be sufficient to lock
|
|
|
|
the increment operation here. */
|
2020-09-05 20:18:52 +02:00
|
|
|
uint32_t currentId = queueCounter++;
|
|
|
|
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
|
|
|
if(not returnPair.second) {
|
2021-02-04 13:46:27 +01:00
|
|
|
/* This should never happen for the atomic variable. */
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-02-04 13:46:27 +01:00
|
|
|
sif::error << "QueueMapManager::addMessageQueue This ID is already "
|
|
|
|
"inside the map!" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printError("QueueMapManager::addMessageQueue This ID is already "
|
|
|
|
"inside the map!\n");
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-09-05 20:18:52 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (id != nullptr) {
|
|
|
|
*id = currentId;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueIF* QueueMapManager::getMessageQueue(
|
|
|
|
MessageQueueId_t messageQueueId) const {
|
2021-03-09 21:25:22 +01:00
|
|
|
MutexGuard(mapLock, MutexIF::TimeoutType::WAITING, 50);
|
2020-09-05 20:18:52 +02:00
|
|
|
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-02-04 13:46:27 +01:00
|
|
|
sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId <<
|
|
|
|
" does not exists in the map!" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n",
|
|
|
|
messageQueueId);
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-09-05 20:18:52 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|