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

56 lines
2.0 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"
#include "fsfw/returnvalues/HasReturnvaluesIF.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
2022-02-02 10:29:30 +01:00
PeriodicTaskIF* TaskFactory::createPeriodicTask(
TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_,
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_) {
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_,
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_) {
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;
return HasReturnvaluesIF::RETURN_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));
return HasReturnvaluesIF::RETURN_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 */
}