added FreeRTOS queue map manager
This commit is contained in:
parent
59e7f0caae
commit
e15f03fb0a
@ -15,6 +15,7 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
TaskFactory.cpp
|
TaskFactory.cpp
|
||||||
Timekeeper.cpp
|
Timekeeper.cpp
|
||||||
TaskManagement.cpp
|
TaskManagement.cpp
|
||||||
|
QueueMapManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# FreeRTOS is required to link the FSFW now. It is recommended to compile
|
# FreeRTOS is required to link the FSFW now. It is recommended to compile
|
||||||
|
49
osal/FreeRTOS/QueueMapManager.cpp
Normal file
49
osal/FreeRTOS/QueueMapManager.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "QueueMapManager.h"
|
||||||
|
#include "../../ipc/MutexFactory.h"
|
||||||
|
#include "../../ipc/MutexGuard.h"
|
||||||
|
|
||||||
|
QueueMapManager::QueueMapManager() {
|
||||||
|
mapLock = MutexFactory::instance()->createMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t QueueMapManager::addMessageQueue(QueueHandle_t queue, MessageQueueId_t* id) {
|
||||||
|
MutexGuard lock(mapLock);
|
||||||
|
uint32_t currentId = queueCounter++;
|
||||||
|
auto returnPair = queueMap.emplace(currentId, queue);
|
||||||
|
if(not returnPair.second) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
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");
|
||||||
|
#endif
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if (id != nullptr) {
|
||||||
|
*id = currentId;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueHandle_t QueueMapManager::getMessageQueue(MessageQueueId_t messageQueueId) const {
|
||||||
|
auto queueIter = queueMap.find(messageQueueId);
|
||||||
|
if(queueIter != queueMap.end()) {
|
||||||
|
return queueIter->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
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);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueMapManager::~QueueMapManager() {
|
||||||
|
MutexFactory::instance()->deleteMutex(mapLock);
|
||||||
|
}
|
50
osal/FreeRTOS/QueueMapManager.h
Normal file
50
osal/FreeRTOS/QueueMapManager.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef FSFW_OSAL_FREERTOS_QUEUEMAPMANAGER_H_
|
||||||
|
#define FSFW_OSAL_FREERTOS_QUEUEMAPMANAGER_H_
|
||||||
|
|
||||||
|
#include "../../ipc/MutexIF.h"
|
||||||
|
#include "../../ipc/messageQueueDefinitions.h"
|
||||||
|
#include "../../ipc/MessageQueueIF.h"
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using QueueMap = std::map<MessageQueueId_t, QueueHandle_t>;
|
||||||
|
|
||||||
|
class QueueMapManager {
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Returns the single instance of QueueMapManager
|
||||||
|
static QueueMapManager* instance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a message queue and the corresponding QueueHandle into the map
|
||||||
|
* @param queue The message queue to insert.
|
||||||
|
* @param id The passed value will be set unless a nullptr is passed
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t addMessageQueue(QueueHandle_t queue, MessageQueueId_t* id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message queue handle by providing a message queue ID. Returns nullptr
|
||||||
|
* if the queue ID does not exist in the internal map.
|
||||||
|
* @param messageQueueId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QueueHandle_t getMessageQueue(MessageQueueId_t messageQueueId) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! External instantiation forbidden. Constructor still required for singleton instantiation.
|
||||||
|
QueueMapManager();
|
||||||
|
~QueueMapManager();
|
||||||
|
|
||||||
|
uint32_t queueCounter = 0;
|
||||||
|
MutexIF* mapLock;
|
||||||
|
QueueMap queueMap;
|
||||||
|
static QueueMapManager* mqManagerInstance;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_OSAL_FREERTOS_QUEUEMAPMANAGER_H_ */
|
@ -15,52 +15,49 @@ QueueMapManager::~QueueMapManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueueMapManager* QueueMapManager::instance() {
|
QueueMapManager* QueueMapManager::instance() {
|
||||||
if (mqManagerInstance == nullptr){
|
if (mqManagerInstance == nullptr){
|
||||||
mqManagerInstance = new QueueMapManager();
|
mqManagerInstance = new QueueMapManager();
|
||||||
}
|
}
|
||||||
return QueueMapManager::mqManagerInstance;
|
return QueueMapManager::mqManagerInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t QueueMapManager::addMessageQueue(
|
ReturnValue_t QueueMapManager::addMessageQueue(
|
||||||
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
||||||
/* Not thread-safe, but it is assumed all message queues are created at software initialization
|
MutexGuard lock(mapLock);
|
||||||
now. If this is to be made thread-safe in the future, it propably would be sufficient to lock
|
uint32_t currentId = queueCounter++;
|
||||||
the increment operation here. */
|
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
||||||
uint32_t currentId = queueCounter++;
|
if(not returnPair.second) {
|
||||||
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
/* This should never happen for the atomic variable. */
|
||||||
if(not returnPair.second) {
|
|
||||||
/* This should never happen for the atomic variable. */
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "QueueMapManager::addMessageQueue This ID is already "
|
sif::error << "QueueMapManager::addMessageQueue This ID is already "
|
||||||
"inside the map!" << std::endl;
|
"inside the map!" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("QueueMapManager::addMessageQueue This ID is already "
|
sif::printError("QueueMapManager::addMessageQueue This ID is already "
|
||||||
"inside the map!\n");
|
"inside the map!\n");
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
if (id != nullptr) {
|
if (id != nullptr) {
|
||||||
*id = currentId;
|
*id = currentId;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageQueueIF* QueueMapManager::getMessageQueue(
|
MessageQueueIF* QueueMapManager::getMessageQueue(
|
||||||
MessageQueueId_t messageQueueId) const {
|
MessageQueueId_t messageQueueId) const {
|
||||||
MutexGuard(mapLock, MutexIF::TimeoutType::WAITING, 50);
|
auto queueIter = queueMap.find(messageQueueId);
|
||||||
auto queueIter = queueMap.find(messageQueueId);
|
if(queueIter != queueMap.end()) {
|
||||||
if(queueIter != queueMap.end()) {
|
return queueIter->second;
|
||||||
return queueIter->second;
|
}
|
||||||
}
|
else {
|
||||||
else {
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId <<
|
sif::warning << "QueueMapManager::getQueueHandle: The ID " << messageQueueId <<
|
||||||
" does not exists in the map!" << std::endl;
|
" does not exists in the map!" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n",
|
sif::printWarning("QueueMapManager::getQueueHandle: The ID %d does not exist in the map!\n",
|
||||||
messageQueueId);
|
messageQueueId);
|
||||||
#endif
|
#endif
|
||||||
return nullptr;
|
}
|
||||||
}
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,33 +15,36 @@ using QueueMap = std::unordered_map<MessageQueueId_t, MessageQueueIF*>;
|
|||||||
*/
|
*/
|
||||||
class QueueMapManager {
|
class QueueMapManager {
|
||||||
public:
|
public:
|
||||||
//! Returns the single instance of SemaphoreFactory.
|
|
||||||
static QueueMapManager* instance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a message queue into the map and returns a message queue ID
|
//! Returns the single instance of QueueMapManager.
|
||||||
* @param queue The message queue to insert.
|
static QueueMapManager* instance();
|
||||||
* @param id The passed value will be set unless a nullptr is passed
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* Insert a message queue into the map and returns a message queue ID
|
||||||
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
|
* @param queue The message queue to insert.
|
||||||
id = nullptr);
|
* @param id The passed value will be set unless a nullptr is passed
|
||||||
/**
|
* @return
|
||||||
* Get the message queue handle by providing a message queue ID.
|
*/
|
||||||
* @param messageQueueId
|
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
|
||||||
* @return
|
id = nullptr);
|
||||||
*/
|
/**
|
||||||
MessageQueueIF* getMessageQueue(MessageQueueId_t messageQueueId) const;
|
* Get the message queue handle by providing a message queue ID. Returns nullptr
|
||||||
|
* if the queue ID is not contained inside the internal map.
|
||||||
|
* @param messageQueueId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MessageQueueIF* getMessageQueue(MessageQueueId_t messageQueueId) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! External instantiation is forbidden.
|
//! External instantiation is forbidden. Constructor still required for singleton instantiation.
|
||||||
QueueMapManager();
|
QueueMapManager();
|
||||||
~QueueMapManager();
|
~QueueMapManager();
|
||||||
|
|
||||||
uint32_t queueCounter = 0;
|
uint32_t queueCounter = 0;
|
||||||
MutexIF* mapLock;
|
MutexIF* mapLock;
|
||||||
QueueMap queueMap;
|
QueueMap queueMap;
|
||||||
static QueueMapManager* mqManagerInstance;
|
static QueueMapManager* mqManagerInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user