2021-03-21 16:20:13 +01:00
|
|
|
#include "../../tasks/TaskFactory.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
#include "../../osal/host/FixedTimeslotTask.h"
|
|
|
|
#include "../../osal/host/PeriodicTask.h"
|
|
|
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
|
|
|
#include "../../tasks/PeriodicTaskIF.h"
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#include "../windows/winTaskHelpers.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-09-05 20:18:52 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
// 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() {
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskFactory::~TaskFactory() {
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskFactory* TaskFactory::instance() {
|
|
|
|
return TaskFactory::factoryInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,
|
|
|
|
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
|
|
|
TaskPeriod periodInSeconds_,
|
|
|
|
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
|
|
|
return new PeriodicTask(name_, taskPriority_, stackSize_, periodInSeconds_,
|
|
|
|
deadLineMissedFunction_);
|
|
|
|
}
|
|
|
|
|
|
|
|
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,
|
|
|
|
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
|
|
|
TaskPeriod periodInSeconds_,
|
|
|
|
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
|
|
|
return new FixedTimeslotTask(name_, taskPriority_, stackSize_,
|
|
|
|
periodInSeconds_, deadLineMissedFunction_);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
|
|
|
|
// This might block for some time!
|
|
|
|
delete task;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs){
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:43:09 +01:00
|
|
|
void TaskFactory::printMissedDeadline() {
|
2021-03-21 16:20:13 +01:00
|
|
|
#ifdef __unix__
|
|
|
|
char name[20] = {0};
|
|
|
|
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
if(status == 0) {
|
|
|
|
sif::warning << "TaskFactory::printMissedDeadline: " << name << "" << std::endl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::warning << "TaskFactory::printMissedDeadline: Unknown task name" << status <<
|
|
|
|
std::endl;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(status == 0) {
|
|
|
|
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::printWarning("TaskFactory::printMissedDeadline: Unknown task name\n", name);
|
|
|
|
}
|
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
std::string name = tasks::getTaskName(std::this_thread::get_id());
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "TaskFactory::printMissedDeadline: " << name << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
|
|
#endif /* defined(_WIN32) */
|
2021-02-22 18:43:09 +01:00
|
|
|
}
|
|
|
|
|
2020-09-05 20:18:52 +02:00
|
|
|
|