fsfw/osal/host/QueueMapManager.h

54 lines
1.5 KiB
C
Raw Normal View History

2020-09-05 21:19:53 +02:00
#ifndef FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_
#define FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_
2020-09-05 20:18:52 +02:00
#include "../../ipc/MessageQueueSenderIF.h"
#include "../../osal/host/MessageQueue.h"
#include <unordered_map>
#include <atomic>
using QueueMap = std::unordered_map<MessageQueueId_t, MessageQueueIF*>;
/**
* An internal map to map message queue IDs to message queues.
* This propably should be a singleton..
*/
class QueueMapManager {
public:
2021-05-27 13:12:34 +02:00
//! Returns the single instance of QueueMapManager.
static QueueMapManager* instance();
/**
* Insert a message queue into the map and returns a message queue ID
* @param queue The message queue to insert.
* @param id The passed value will be set unless a nullptr is passed
* @return
*/
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
id = nullptr);
/**
* 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;
2020-09-05 20:18:52 +02:00
private:
2021-05-27 13:12:34 +02:00
//! External instantiation is forbidden. Constructor still required for singleton instantiation.
QueueMapManager();
~QueueMapManager();
2021-07-19 14:40:32 +02:00
// Start at 1 because 0 might be the NO_QUEUE value
uint32_t queueCounter = 1;
2021-05-27 13:12:34 +02:00
MutexIF* mapLock;
QueueMap queueMap;
static QueueMapManager* mqManagerInstance;
2020-09-05 20:18:52 +02:00
};
2020-09-05 21:19:53 +02:00
#endif /* FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_ */