rta_for_fps_lib/
server.rs1use crate::curve::AggregateExt;
6
7use crate::iterators::server::constrained_demand::ConstrainedServerDemandIterator;
8use crate::iterators::{CurveIterator, ReclassifyIterator};
9use crate::task::Task;
10use crate::time::TimeUnit;
11
12#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
14pub struct AggregatedServerDemand;
15
16#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
18pub struct ConstrainedServerDemand;
19
20#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
22pub struct HigherPriorityServerDemand;
23
24#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
26pub struct HigherPriorityServerExecution;
27
28#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
30pub struct UnconstrainedServerExecution;
31
32#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
34pub struct ActualServerExecution;
35
36#[derive(Debug, Clone)]
45pub struct Server<'a> {
46 pub tasks: &'a [Task],
49 pub properties: ServerProperties,
51}
52
53#[derive(Debug, Clone, Copy)]
55pub struct ServerProperties {
56 pub capacity: TimeUnit,
58 pub interval: TimeUnit,
60 pub server_type: ServerKind,
62}
63
64#[derive(Debug, Clone, Copy)]
66pub enum ServerKind {
67 Deferrable,
70 Periodic,
73}
74
75impl<'a> Server<'a> {
76 #[must_use]
78 pub const fn new(
79 tasks: &'a [Task],
80 capacity: TimeUnit,
81 interval: TimeUnit,
82 server_type: ServerKind,
83 ) -> Self {
84 Server {
85 tasks,
86 properties: ServerProperties {
87 capacity,
88 interval,
89 server_type,
90 },
91 }
92 }
93
94 #[must_use]
96 pub const fn as_tasks(&self) -> &'a [Task] {
97 self.tasks
98 }
99
100 #[must_use]
103 pub fn aggregated_demand_curve_iter(
104 &self,
105 ) -> impl CurveIterator<CurveKind = AggregatedServerDemand> + Clone + '_ {
106 self.tasks
107 .iter()
108 .map(|task| task.into_iter())
109 .aggregate::<ReclassifyIterator<_, _>>()
110 }
111
112 #[must_use]
114 pub fn constraint_demand_curve_iter(
115 &self,
116 ) -> impl CurveIterator<CurveKind = ConstrainedServerDemand> + Clone + '_ {
117 ConstrainedServerDemandIterator::new(self.properties, self.aggregated_demand_curve_iter())
118 }
119}