fsfw/src/fsfw/osal/host/TaskFactory.cpp

58 lines
2.2 KiB
C++
Raw Normal View History

2022-02-02 10:29:30 +01:00
#include "fsfw/tasks/TaskFactory.h"
#include <chrono>
#include "fsfw/osal/host/FixedTimeslotTask.h"
#include "fsfw/osal/host/PeriodicTask.h"
#include "fsfw/osal/host/taskHelpers.h"
2022-08-16 12:48:22 +02:00
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/tasks/PeriodicTaskIF.h"
2020-09-05 20:18:52 +02:00
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
// Not used for the host implementation for now because C++ thread abstraction is used
2020-09-05 20:18:52 +02:00
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = 0;
TaskFactory::TaskFactory() = default;
2020-09-05 20:18:52 +02:00
TaskFactory::~TaskFactory() = default;
2020-09-05 20:18:52 +02:00
2022-02-02 10:29:30 +01:00
TaskFactory* TaskFactory::instance() { return TaskFactory::factoryInstance; }
2020-09-05 20:18:52 +02:00
2023-03-24 13:25:34 +01:00
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_, TaskPriority taskPriority_,
TaskStackSize stackSize_,
TaskPeriod periodInSeconds_,
TaskDeadlineMissedFunction deadLineMissedFunction_,
void* args) {
2022-02-02 10:29:30 +01:00
return new PeriodicTask(name_, taskPriority_, stackSize_, periodInSeconds_,
deadLineMissedFunction_);
2020-09-05 20:18:52 +02:00
}
2022-02-02 10:29:30 +01:00
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(
TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_,
2023-03-24 13:25:34 +01:00
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_, void* args) {
2022-02-02 10:29:30 +01:00
return new FixedTimeslotTask(name_, taskPriority_, stackSize_, periodInSeconds_,
deadLineMissedFunction_);
2020-09-05 20:18:52 +02:00
}
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
2022-02-02 10:29:30 +01:00
// This might block for some time!
delete task;
2022-08-15 20:28:16 +02:00
return returnvalue::FAILED;
2020-09-05 20:18:52 +02:00
}
2022-02-02 10:29:30 +01:00
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs) {
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2020-09-05 20:18:52 +02:00
}
void TaskFactory::printMissedDeadline() {
2022-02-02 10:29:30 +01:00
std::string name = tasks::getTaskName(std::this_thread::get_id());
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "TaskFactory::printMissedDeadline: " << name << std::endl;
#else
2022-02-02 10:29:30 +01:00
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
}