aboutsummaryrefslogtreecommitdiff
path: root/karld/src/schedule.rs
blob: 971c63a23096f942c5383162e1bdf9fc9a76fe8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use karlcommon::{Condition, Schedule};

use crate::TASKS;

pub fn schedule_dynamic() {
    let mut tasks = TASKS.write().unwrap();

    let mut colliders = vec![];
    let mut dynamic = vec![];
    for t in tasks.values_mut() {
        if t.schedule.is_dynamic() {
            dynamic.push(t)
        } else {
            colliders.push(t)
        }
    }

    dynamic.sort_by_key(|t| {
        if let Schedule::Dynamic { priority, .. } = t.schedule {
            // TODO increase precision by using floats
            (priority * 1000.0) as i64
        } else {
            0
        }
    });

    let cond = Condition::Invert(box Condition::Or(
        colliders
            .iter()
            .map(|c| match &c.schedule {
                Schedule::Never => Condition::Never,
                Schedule::Condition(c) => c.clone(),
                Schedule::Static(r) => Condition::Range {
                    min: r.start,
                    max: r.end,
                    modulus: None,
                    prop: karlcommon::Property::Unix,
                },
                Schedule::Dynamic { .. } => unreachable!(),
            })
            .collect(),
    ));
    println!("{:?}", cond);

    while dynamic.len() != 0 {
        todo!()
    }
}