Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
schedule.h
Go to the documentation of this file.
1
5#pragma once
6#include "utils/queue.h"
8namespace Schedule {
9//XXX: figure out a way to simplify this whole namespace
10//I'm not satisfied with each schedulable deciding whether it wants to
11//run by itself. That probably belongs into the registries instead.
12//Then we could probably do away with the whole 'Schedulable' concept
13//and just keep 'callable's or smth
21 virtual ~Schedulable(){}
23 virtual bool schedule(uint32_t) { return true; }
25 virtual void call()=0;
26};
36struct Registry {
37 Buffer<Schedulable *> list = 20;
38 ~Registry() {
39 for (auto &entry: list) {
40 delete entry;
41 }
42 }
43};
44}
45
47struct Scheduler {
48 // this is pointing to the actual callables in the registries
49 // we do not own them
52 bool schedule(uint32_t time, Schedule::Registry &reg) {
53 for (auto &c: reg.list) {
54 if (q.full()) return false;
55 if (c->schedule(time)) q.push(c);
56 }
57 return true;
58 }
60 void run() {
61 while (!q.empty()) {
62 auto s = q.pop();
63 s->call();
64 }
65 }
66};
simple Buffer backed queue implementation
Definition queue.h:12
T pop() override
remove front of queue and return it
Definition queue.h:65
bool empty() override
check if queue is empty
Definition queue.h:83
bool full() override
return true if queue is full
Definition queue.h:87
void push(T &&val) override
move element into queue
Definition queue.h:49
namespace wrapping all functionality to do with scheduling
Definition evented.h:7
Copyright (c) 2023 IACE.
dynamically allocated, but fixed-size buffer template
Definition buffer.h:18
a registry of Schedulable which can be given to the Scheduler for actual scheduling of calls
Definition schedule.h:36
represents an object that can be scheduled for later calling
Definition schedule.h:20
virtual void call()=0
this method is called to run the Schedulable
virtual bool schedule(uint32_t)
return true if object should be scheduled at this time
Definition schedule.h:23
round robin, because we're not smart enough for anything else
Definition schedule.h:47
bool schedule(uint32_t time, Schedule::Registry &reg)
schedule all registered schedulables of registry if necessary
Definition schedule.h:52
void run()
run scheduled calls
Definition schedule.h:60