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_ */
|
@ -23,9 +23,7 @@ QueueMapManager* QueueMapManager::instance() {
|
|||||||
|
|
||||||
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
|
|
||||||
the increment operation here. */
|
|
||||||
uint32_t currentId = queueCounter++;
|
uint32_t currentId = queueCounter++;
|
||||||
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
||||||
if(not returnPair.second) {
|
if(not returnPair.second) {
|
||||||
@ -47,7 +45,6 @@ ReturnValue_t QueueMapManager::addMessageQueue(
|
|||||||
|
|
||||||
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;
|
||||||
@ -60,7 +57,7 @@ MessageQueueIF* QueueMapManager::getMessageQueue(
|
|||||||
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,7 +15,9 @@ using QueueMap = std::unordered_map<MessageQueueId_t, MessageQueueIF*>;
|
|||||||
*/
|
*/
|
||||||
class QueueMapManager {
|
class QueueMapManager {
|
||||||
public:
|
public:
|
||||||
//! Returns the single instance of SemaphoreFactory.
|
|
||||||
|
|
||||||
|
//! Returns the single instance of QueueMapManager.
|
||||||
static QueueMapManager* instance();
|
static QueueMapManager* instance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,14 +29,15 @@ public:
|
|||||||
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
|
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
|
||||||
id = nullptr);
|
id = nullptr);
|
||||||
/**
|
/**
|
||||||
* Get the message queue handle by providing a message queue ID.
|
* 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
|
* @param messageQueueId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
MessageQueueIF* getMessageQueue(MessageQueueId_t messageQueueId) const;
|
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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user