2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tasks/TaskFactory.h"
|
|
|
|
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/osal/linux/FixedTimeslotTask.h"
|
|
|
|
#include "fsfw/osal/linux/PeriodicPosixTask.h"
|
|
|
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
// TODO: Different variant than the lazy loading in QueueFactory. What's better and why?
|
2018-07-13 18:28:26 +02:00
|
|
|
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
TaskFactory::~TaskFactory() {}
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
TaskFactory* TaskFactory::instance() { return TaskFactory::factoryInstance; }
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
PeriodicTaskIF* TaskFactory::createPeriodicTask(
|
|
|
|
TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_,
|
|
|
|
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
2022-05-18 15:42:18 +02:00
|
|
|
return new PeriodicPosixTask(name_, taskPriority_, stackSize_, periodInSeconds_,
|
2022-02-02 10:29:30 +01:00
|
|
|
deadLineMissedFunction_);
|
2018-07-13 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(
|
|
|
|
TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_,
|
|
|
|
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
2022-05-18 15:42:18 +02:00
|
|
|
return new FixedTimeslotTask(name_, taskPriority_, stackSize_, periodInSeconds_);
|
2018-07-13 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
|
2022-02-02 10:29:30 +01:00
|
|
|
// TODO not implemented
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2018-07-13 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs) {
|
|
|
|
return PosixThread::sleep(delayMs * 1000000ull);
|
2018-07-13 18:28:26 +02:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:43:09 +01:00
|
|
|
void TaskFactory::printMissedDeadline() {
|
2022-02-02 10:29:30 +01:00
|
|
|
char name[20] = {0};
|
|
|
|
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
|
2021-02-22 18:43:09 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
if (status == 0) {
|
|
|
|
sif::warning << "task::printMissedDeadline: " << name << "" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "task::printMissedDeadline: Unknown task name" << status << std::endl;
|
|
|
|
}
|
2021-02-22 18:43:09 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
if (status == 0) {
|
|
|
|
sif::printWarning("task::printMissedDeadline: %s\n", name);
|
|
|
|
} else {
|
|
|
|
sif::printWarning("task::printMissedDeadline: Unknown task name\n", name);
|
|
|
|
}
|
2021-02-22 18:43:09 +01:00
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
TaskFactory::TaskFactory() {}
|