/* * task.hpp * * Created on: Sep 14, 2023 * Author: Dario */ #ifndef INCLUDE_TACOS_TASK_HPP_ #define INCLUDE_TACOS_TASK_HPP_ #include #include /** * @defgroup tacos_thread TACOS Thread * @ingroup tacos * @brief TACOS Thread class. */ namespace sta { namespace tacos { /** * @brief Abstract class for thread implementations in Tacos. * * @ingroup tacos_thread */ class TacosThread : public RtosThread { public: /** * @brief Create a new thread with the given name and priority. */ TacosThread(const char* name, osPriority_t prio); TacosThread(); virtual ~TacosThread(); /** * @brief Start the execution of this thread. */ void start(); /** * @brief Checks if this thread is currently running. */ bool isRunning(); /** * @brief Get the currently running instance. * * @return The currently running instance id. */ osThreadId_t getInstance(); /** * @brief Get the name of this thread. */ const char* getName() const; /** * @brief Compare two threads by their names. */ bool operator==(const TacosThread& other) const; /** * @brief Compare two threads by their names. */ bool operator<(const TacosThread& other) const; /** * @brief A function that wraps this task's functionality in a loop. This loop will run until * termination is requested. */ void loop(); /** * @brief This function is executed first when this thread is started. */ virtual void init(); /** * @brief The body of the thread's loop. Has to be implemented by the user. * This function is called repeatedly until termination is requested. */ virtual void func() = 0; /** * @brief This function is executed when the thread is terminated. Has to be implemented by the user. * This function should free all ressources used by this thread. */ virtual void cleanup(); private: /** * @brief Static function to pass to RTOS to run as a thread. Calls the loop function implemented here. */ static void entry_point(void* arg); private: osThreadId_t instance_; osThreadAttr_t attribs_; bool running_; }; } } #endif /* INCLUDE_TACOS_TASK_HPP_ */