Embedded Template Library  1.0
task.h
1 /******************************************************************************
2 The MIT License(MIT)
3 
4 Embedded Template Library.
5 https://github.com/ETLCPP/etl
6 https://www.etlcpp.com
7 
8 Copyright(c) 2017 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
27 ******************************************************************************/
28 
29 #ifndef ETL_TASK_INCLUDED
30 #define ETL_TASK_INCLUDED
31 
32 #include <stdint.h>
33 
34 #include "platform.h"
35 #include "error_handler.h"
36 #include "exception.h"
37 
38 #undef ETL_FILE
39 #define ETL_FILE "37"
40 
41 namespace etl
42 {
43  //***************************************************************************
45  //***************************************************************************
47  {
48  public:
49 
50  task_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
51  : etl::exception(reason_, file_name_, line_number_)
52  {
53  }
54  };
55 
56  typedef uint_least8_t task_priority_t;
57 
58  //***************************************************************************
60  //***************************************************************************
61  class task
62  {
63  public:
64 
65  //*******************************************
67  //*******************************************
68  task(task_priority_t priority)
69  : task_running(true),
70  task_priority(priority)
71  {
72  }
73 
74  //*******************************************
76  //*******************************************
77  virtual ~task()
78  {
79  }
80 
81  //*******************************************
84  //*******************************************
85  virtual uint32_t task_request_work() const = 0;
86 
87  //*******************************************
89  //*******************************************
90  virtual void task_process_work() = 0;
91 
92  //*******************************************
94  //*******************************************
95  virtual void on_task_added()
96  {
97  // Do nothing.
98  }
99 
100  //*******************************************
102  //*******************************************
103  void set_task_running(bool task_running_)
104  {
105  task_running = task_running_;
106  }
107 
108  //*******************************************
110  //*******************************************
111  bool task_is_running() const
112  {
113  return task_running;
114  }
115 
116  //*******************************************
119  //*******************************************
120  etl::task_priority_t get_task_priority() const
121  {
122  return task_priority;
123  }
124 
125  private:
126 
127  bool task_running;
128  etl::task_priority_t task_priority;
129  };
130 }
131 
132 #undef ETL_FILE
133 
134 #endif
Base exception class for task.
Definition: task.h:47
Task.
Definition: task.h:62
void set_task_running(bool task_running_)
Set the running state for the task.
Definition: task.h:103
virtual void on_task_added()
Called when the task has been added to the scheduler.
Definition: task.h:95
virtual uint32_t task_request_work() const =0
etl::task_priority_t get_task_priority() const
Definition: task.h:120
task(task_priority_t priority)
Constructor.
Definition: task.h:68
virtual ~task()
Destructor.
Definition: task.h:77
bool task_is_running() const
Get the running state for the task.
Definition: task.h:111
virtual void task_process_work()=0
Called to get the task to do work.
Definition: exception.h:47
Definition: absolute.h:37