2020-06-05 17:55:03 +02:00
|
|
|
#include <framework/ipc/MutexFactory.h>
|
|
|
|
#include <framework/ipc/MutexHelper.h>
|
|
|
|
#include <framework/osal/host/QueueMapManager.h>
|
|
|
|
|
|
|
|
QueueMapManager* QueueMapManager::mqManagerInstance = nullptr;
|
|
|
|
|
2020-06-06 21:16:47 +02:00
|
|
|
QueueMapManager::QueueMapManager() {
|
|
|
|
mapLock = MutexFactory::instance()->createMutex();
|
|
|
|
}
|
2020-06-05 17:55:03 +02:00
|
|
|
|
|
|
|
QueueMapManager* QueueMapManager::instance() {
|
|
|
|
if (mqManagerInstance == nullptr){
|
|
|
|
mqManagerInstance = new QueueMapManager();
|
|
|
|
}
|
|
|
|
return QueueMapManager::mqManagerInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t QueueMapManager::addMessageQueue(
|
|
|
|
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
2020-07-06 14:09:33 +02: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-06-05 17:55:03 +02:00
|
|
|
uint32_t currentId = queueCounter++;
|
|
|
|
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
|
|
|
if(not returnPair.second) {
|
|
|
|
// this should never happen for the atomic variable.
|
|
|
|
sif::error << "QueueMapManager: This ID is already inside the map!"
|
|
|
|
<< std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (id != nullptr) {
|
|
|
|
*id = currentId;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueIF* QueueMapManager::getMessageQueue(
|
|
|
|
MessageQueueId_t messageQueueId) const {
|
|
|
|
MutexHelper(mapLock, 50);
|
|
|
|
auto queueIter = queueMap.find(messageQueueId);
|
|
|
|
if(queueIter != queueMap.end()) {
|
|
|
|
return queueIter->second;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::warning << "QueueMapManager::getQueueHandle: The ID" <<
|
|
|
|
messageQueueId << " does not exists in the map" << std::endl;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|