You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-41Lines changed: 41 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,62 +1,62 @@
1
-
# ArduinoServiceScheduler
2
-
An Arduino Object Oriented Cooperative Service Scheduler to Replace Them All
1
+
# ArduinoProcessScheduler
2
+
An Arduino Object Oriented Cooperative Process Scheduler to Replace Them All
3
3
4
4
## Features
5
-
- Fine Grained Control Over How Often a Service Runs (Periodically, Iterations, or as Often as Possible)
5
+
- Fine Grained Control Over How Often a Process Runs (Periodically, Iterations, or as Often as Possible)
6
6
- Exception Handling (wait what?!)
7
7
- Atomicity Support
8
-
- Dynamically Add/Remove and Enable/Disable Services
9
-
- Automatic Service Monitoring Statsitics (Automatically calculates % CPU time for service)
10
-
- Truly object orinted (a Service is no longer just a callback function like other libraries)
8
+
- Dynamically Add/Remove and Enable/Disable Processes
9
+
- Automatic Process Monitoring Statistics (Automatically calculates % CPU time for service)
10
+
- Truly object oriented (a Process is no longer just a callback function like other libraries)
11
11
12
12
## Basic Usage
13
-
There are two classes to worry about: `Scheduler` and `Service`.
13
+
There are two classes to worry about: `Scheduler` and `Process`.
14
14
15
15
### Class `Scheduler`:
16
-
A `Scheduler` oversees and maanges `Services`. There should only be one `Scheduler` in your project. Inside of `void loop()`, the scheduler's `run()` method should be repeatedly called.
16
+
A `Scheduler` oversees and manages `Processes`. There should only be one `Scheduler` in your project. Inside of `void loop()`, the scheduler's `run()` method should be repeatedly called.
17
17
18
-
### Class `Service`:
19
-
A service can be thought of as job or a task that needs to be run at certain times. Each Service had be scheduled to run Periodically
18
+
### Class `Process`:
19
+
A service can be thought of as job or a task that needs to be run at certain times. Each Process had be scheduled to run Periodically
20
20
Constantly, or Periodically/Constantly with a set number of run iterations.
21
21
22
-
Each project will have multiple services, here are some examples of `Services`:
23
-
- A Service to handle user input
24
-
- A Service to run a basic webserver
25
-
- A Service to update a display
26
-
27
-
`Service` is a base class that should be extended to handle your particular Service (such as the examples mentioned above). The scheduler's will call the following virtual function as an entry point when it is time for you service to run:
22
+
Each project will have multiple services, here are some examples of `Processes`:
23
+
- A Process to handle user input
24
+
- A Process to run a basic webserver
25
+
- A Process to update a display
26
+
27
+
`Process` is a base class that should be extended to handle your particular Process (such as the examples mentioned above). The scheduler's will call the following virtual function as an entry point when it is time for you service to run:
28
28
```
29
29
virtual void service();
30
30
```
31
-
From here your `service()` routine is expected to be non-blocking, and return from `service()` as soon as possible (that means no long `delay()`'s). Fortunately, since your service routine is a method inside a class, you can store the state of your service in custom class attributes before returning, so you know where you left off when the scheduler calls your Service again. As soon you return from `service()`, control is transferred back to the Scheduler (it will also be transferred back if you raise an Exception--advanced).
31
+
From here your `service()` routine is expected to be non-blocking, and return from `service()` as soon as possible (that means no long `delay()`'s). Fortunately, since your service routine is a method inside a class, you can store the state of your service in custom class attributes before returning, so you know where you left off when the scheduler calls your Process again. As soon you return from `service()`, control is transferred back to the Scheduler (it will also be transferred back if you raise an Exception--advanced).
32
32
33
-
Additionally, each Service inherits the following virtual functions which are called by the `Scheduler` at the appropriate times. Note you are guaranteed that only one of these methods will exist in the call stack at once, even if an interrupt fires trying to modify this Service at the same time (such as with `add()`, `destroy()`, `enable()`, or `disable()`). This also includes the `service()` method mentioned above. You do not have to worry about concurrency!
33
+
Additionally, each Process inherits the following virtual functions which are called by the `Scheduler` at the appropriate times. Note you are guaranteed that only one of these methods will exist in the call stack at once, even if an interrupt fires trying to modify this Process at the same time (such as with `add()`, `destroy()`, `enable()`, or `disable()`). This also includes the `service()` method mentioned above. You do not have to worry about concurrency!
34
34
35
-
**Thanks to the magic of virtual functions, you don't have to impliment any of these unless your particular Service needs them:**
35
+
**Thanks to the magic of virtual functions, you don't have to impliment any of these unless your particular Process needs them:**
This method is called by the scheduler when the Service is being added to the scheduling chain with `add()`, it is guaranteed to only be called once when a Service not part of the scheduling chain is being added (`add()`). Keep in mind it will still be called if the Service is removed from the scheduling chain with `destroy()`, then added again with `add()`.
47
+
This method is called by the scheduler when the Process is being added to the scheduling chain with `add()`, it is guaranteed to only be called once when a Process not part of the scheduling chain is being added (`add()`). Keep in mind it will still be called if the Process is removed from the scheduling chain with `destroy()`, then added again with `add()`.
48
48
49
49
#### `cleanup()`
50
-
This is only called once when a `Service` part of the scheduling chain is being removed from the scheduling chain with `destroy()`. This method should undo whatever was done in `setup()`. You are guaranteed it will not be called unless `setup()` was called previously.
50
+
This is only called once when a `Process` part of the scheduling chain is being removed from the scheduling chain with `destroy()`. This method should undo whatever was done in `setup()`. You are guaranteed it will not be called unless `setup()` was called previously.
51
51
52
52
#### `onEnable()`
53
-
This method is called only once when a disabled task is being enabled with `enable()`.
53
+
This method is called only once when a disabled task is being enabled with `enable()`.
54
54
55
55
#### `onDisable()`
56
56
This method is called only once when a enabled task is being disabled with `disable()`. You are guaranteed it will not be called unless `onEnable()` was called previously. It should undo whatever `onEnable()` did.
57
57
58
58
#### `overScheduledHandler(uint32_t behind)`
59
-
This method is called if the scheduler can not meet the current set period for the Service and is falling behind. The scheduler will pass in variable `behind` containing how many milliseconds (or microseconds) behind the scheduler is with this task. Inside this method might be a good time increase the period between when this task is run, then call `resetSchedulerWarning()` to clear the warning.
59
+
This method is called if the scheduler can not meet the current set period for the Process and is falling behind. The scheduler will pass in variable `behind` containing how many milliseconds (or microseconds) behind the scheduler is with this task. Inside this method might be a good time increase the period between when this task is run, then call `resetSchedulerWarning()` to clear the warning.
60
60
61
61
62
62
## API
@@ -85,45 +85,45 @@ ___
85
85
86
86
#### getID()
87
87
```
88
-
getID(Service &service)
88
+
getID(Process &service)
89
89
```
90
90
Get the unique id for the service. Same as `service.getID()`.
91
91
92
92
**Returns:**`uint8_t`
93
93
___
94
94
95
-
#### isRunningService()
95
+
#### isRunningProcess()
96
96
```
97
-
isRunningService(Service &service)
97
+
isRunningProcess(Process &service)
98
98
```
99
-
Determine if the scheduler is in the middle of running this service. Same as calling `service.isRunningService()`
99
+
Determine if the scheduler is in the middle of running this service. Same as calling `service.isRunningProcess()`
100
100
101
101
**Returns:**`bool`
102
102
___
103
103
104
104
#### isEnabled()
105
105
```
106
-
isEnabled(Service &service)
106
+
isEnabled(Process &service)
107
107
```
108
108
Determines if this service is enabled. Same as calling `service.isEnabled()`
109
109
110
110
**Returns:**`bool`
111
111
___
112
112
113
-
#### getCurrService()
113
+
#### getCurrProcess()
114
114
```
115
-
getCurrService()
115
+
getCurrProcess()
116
116
```
117
117
Get pointer to the current service being run by the scheduler. Return NULL if no service being currently run.
118
118
119
-
**Returns:**`Service*`
119
+
**Returns:**`Process*`
120
120
___
121
121
122
-
#### countServices()
122
+
#### countProcesses()
123
123
```
124
-
countServices(bool enabledOnly = true)
124
+
countProcesses(bool enabledOnly = true)
125
125
```
126
-
Get number of servies in the scheduler's chain. If enabledOnly is true, only the enabled Services will be counted.
126
+
Get number of servies in the scheduler's chain. If enabledOnly is true, only the enabled Processes will be counted.
127
127
128
128
**Returns:**`uint8_t`
129
129
___
@@ -140,7 +140,7 @@ ___
140
140
141
141
#### add()
142
142
```
143
-
add (Service &service))
143
+
add (Process &service))
144
144
```
145
145
Add the service to the scheduler, same as calling `service.add()`. Note, this will trigger the service's `setup()` method to fire. This method can only fail inside an interrupt routine, particularly when an interrupt interrupts any call to either `add()` or `remove()`. It will also fail if the service is already added.
146
146
@@ -149,16 +149,16 @@ ___
149
149
150
150
#### destroy()
151
151
```
152
-
destroy (Service &service))
152
+
destroy (Process &service))
153
153
```
154
-
Remove the service from the scheduler. Same as calling `service.destroy()`. Note, this will trigger the service's `cleanup()` method to fire. If the service is not disabled, it will first call `disable()`. This method can only fail inside an interrupt routine, particularly when an interrupt interrupts any call to either `add()` or `remove()`. It will first try and QUEUE the request for later, before failing. It will also fail if the service is already destroyed.
154
+
Remove the service from the scheduler. Same as calling `service.destroy()`. Note, this will trigger the service's `cleanup()` method to fire. If the service is not disabled, it will first call `disable()`. This method can only fail inside an interrupt routine, particularly when an interrupt interrupts any call to either `add()` or `remove()`. It will first try and QUEUE the request for later, before failing. It will also fail if the service is already destroyed.
155
155
156
156
**Returns:** type `SchedulerAction`, `ACTION_NONE` on failure, `ACTION_QUEUED` on Queuing it, `ACTION_SUCCESS` on success.
157
157
___
158
158
159
159
#### enable()
160
160
```
161
-
enable (Service &service))
161
+
enable (Process &service))
162
162
```
163
163
Enable a service, same as calling `service.enable()`. Note, this will trigger the service's `onEnable()` method to fire. This method call will always succeed if it was not called on itself from a method inside of this service. If it was, the scheduler will queue the request. Also, the request will fail if the service is already enabled or is destroyed.
164
164
@@ -167,7 +167,7 @@ ___
167
167
168
168
#### disable()
169
169
```
170
-
disable (Service &service))
170
+
disable (Process &service))
171
171
```
172
172
Disable a service, same as calling `service.disable()`. Note, this will trigger the service's `onDisable()` method to fire. This method call will always succeed if it was not called on itself from a method inside of this service. If it was, the scheduler will queue the request. Also, the request will fail if the service is already enabled or is destroyed.
0 commit comments