fsfw/src/fsfw/osal/freertos/SemaphoreFactory.cpp

57 lines
1.9 KiB
C++
Raw Normal View History

2022-02-02 10:29:30 +01:00
#include "fsfw/tasks/SemaphoreFactory.h"
2021-07-14 00:54:39 +02:00
#include "fsfw/osal/freertos/BinSemaphUsingTask.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/osal/freertos/BinarySemaphore.h"
2021-07-14 00:54:39 +02:00
#include "fsfw/osal/freertos/CountingSemaphUsingTask.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/osal/freertos/CountingSemaphore.h"
2022-05-18 10:51:38 +02:00
#include "fsfw/serviceinterface.h"
2020-09-18 13:15:14 +02:00
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
static const uint32_t USE_REGULAR_SEMAPHORES = 0;
static const uint32_t USE_TASK_NOTIFICATIONS = 1;
2022-02-02 10:29:30 +01:00
SemaphoreFactory::SemaphoreFactory() {}
2020-09-18 13:15:14 +02:00
2022-02-02 10:29:30 +01:00
SemaphoreFactory::~SemaphoreFactory() { delete factoryInstance; }
2020-09-18 13:15:14 +02:00
SemaphoreFactory* SemaphoreFactory::instance() {
2022-02-02 10:29:30 +01:00
if (factoryInstance == nullptr) {
factoryInstance = new SemaphoreFactory();
}
return SemaphoreFactory::factoryInstance;
2020-09-18 13:15:14 +02:00
}
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
2022-02-02 10:29:30 +01:00
if (argument == USE_REGULAR_SEMAPHORES) {
return new BinarySemaphore();
} else if (argument == USE_TASK_NOTIFICATIONS) {
return new BinarySemaphoreUsingTask();
} else {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
"binary semaphore"
<< std::endl;
#endif
2022-02-02 10:29:30 +01:00
return new BinarySemaphore();
}
2020-09-18 13:15:14 +02:00
}
2022-02-02 10:29:30 +01:00
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t maxCount, uint8_t initCount,
uint32_t argument) {
if (argument == USE_REGULAR_SEMAPHORES) {
return new CountingSemaphore(maxCount, initCount);
} else if (argument == USE_TASK_NOTIFICATIONS) {
return new CountingSemaphoreUsingTask(maxCount, initCount);
} else {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
"binary semaphore"
<< std::endl;
#endif
2022-02-02 10:29:30 +01:00
return new CountingSemaphore(maxCount, initCount);
}
2020-09-18 13:15:14 +02:00
}
2022-02-02 10:29:30 +01:00
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) { delete semaphore; }