2021-07-12 23:32:24 +02:00
|
|
|
#include "BinarySemaphore.h"
|
|
|
|
#include "BinSemaphUsingTask.h"
|
|
|
|
#include "CountingSemaphore.h"
|
|
|
|
#include "CountingSemaphUsingTask.h"
|
|
|
|
|
2020-09-18 13:15:14 +02:00
|
|
|
#include "../../tasks/SemaphoreFactory.h"
|
2021-07-12 23:32:24 +02:00
|
|
|
#include "../../serviceinterface/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;
|
|
|
|
|
|
|
|
SemaphoreFactory::SemaphoreFactory() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SemaphoreFactory::~SemaphoreFactory() {
|
|
|
|
delete factoryInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
SemaphoreFactory* SemaphoreFactory::instance() {
|
|
|
|
if (factoryInstance == nullptr){
|
|
|
|
factoryInstance = new SemaphoreFactory();
|
|
|
|
}
|
|
|
|
return SemaphoreFactory::factoryInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
|
|
|
|
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
|
2020-09-18 13:15:14 +02:00
|
|
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
|
|
|
"binary semaphore" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-09-18 13:15:14 +02:00
|
|
|
return new BinarySemaphore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-09-18 13:15:14 +02:00
|
|
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
|
|
|
"binary semaphore" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-09-18 13:15:14 +02:00
|
|
|
return new CountingSemaphore(maxCount, initCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
|
|
|
delete semaphore;
|
|
|
|
}
|