Loading...
Searching...
No Matches
task.h
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2017 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_TASK_INCLUDED
#define ETL_TASK_INCLUDED
#include "platform.h"
#include "error_handler.h"
#include "exception.h"
#include <stdint.h>
namespace etl
{
//***************************************************************************
//***************************************************************************
class task_exception : public etl::exception
{
public:
task_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: etl::exception(reason_, file_name_, line_number_)
{
}
};
typedef uint_least8_t task_priority_t;
//***************************************************************************
//***************************************************************************
class task
{
public:
//*******************************************
//*******************************************
task(task_priority_t priority)
: task_running(true)
, task_priority(priority)
{
}
//*******************************************
//*******************************************
virtual ~task() {}
//*******************************************
//*******************************************
virtual uint32_t task_request_work() const = 0;
//*******************************************
//*******************************************
virtual void task_process_work() = 0;
//*******************************************
//*******************************************
virtual void on_task_added()
{
// Do nothing.
}
//*******************************************
//*******************************************
void set_task_running(bool task_running_)
{
task_running = task_running_;
}
//*******************************************
//*******************************************
bool task_is_running() const
{
return task_running;
}
//*******************************************
//*******************************************
etl::task_priority_t get_task_priority() const
{
return task_priority;
}
private:
bool task_running;
etl::task_priority_t task_priority;
};
} // namespace etl
#endif
etl::task::set_task_running
void set_task_running(bool task_running_)
Set the running state for the task.
Definition task.h:98
etl::task::on_task_added
virtual void on_task_added()
Called when the task has been added to the scheduler.
Definition task.h:90
etl::task::task_request_work
virtual uint32_t task_request_work() const =0
etl::task::get_task_priority
etl::task_priority_t get_task_priority() const
Definition task.h:115
etl::task::task
task(task_priority_t priority)
Constructor.
Definition task.h:65
etl::task::~task
virtual ~task()
Destructor.
Definition task.h:74
etl::task::task_is_running
bool task_is_running() const
Get the running state for the task.
Definition task.h:106
etl::task::task_process_work
virtual void task_process_work()=0
Called to get the task to do work.
error_handler.h
exception.h
etl::exception
Definition exception.h:59
etl
Definition absolute.h:40
platform.h