Skip to main content

bornera_core/admission/
options.rs

1//! Absolute-deadline and retained-capacity operation options.
2
3use calandria::{Deadline, RetainedBytes};
4
5use super::AdmissionClass;
6
7/// Mechanical condition that releases an accepted operation.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum CompletionMode {
10    /// Retain the operation after writing until a matching reply arrives.
11    ReplyExpected,
12    /// Complete once the full application frame leaves Bornera write ownership.
13    ///
14    /// A buffering transport may still own encoded output that has not reached the
15    /// operating system.
16    WriteComplete,
17}
18
19/// Mechanical resources and timing attached to one operation reservation.
20#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21pub struct OperationOptions {
22    deadline: Deadline,
23    class: AdmissionClass,
24    retained_bytes: RetainedBytes,
25    write_retained_bytes: RetainedBytes,
26    completion_mode: CompletionMode,
27}
28
29impl OperationOptions {
30    /// Creates regular-work options with an absolute deadline.
31    pub const fn until(deadline: Deadline) -> Self {
32        Self {
33            deadline,
34            class: AdmissionClass::Regular,
35            retained_bytes: RetainedBytes::ZERO,
36            write_retained_bytes: RetainedBytes::ZERO,
37            completion_mode: CompletionMode::ReplyExpected,
38        }
39    }
40
41    /// Marks this as session-establishment work.
42    #[must_use]
43    pub const fn session(mut self) -> Self {
44        self.class = AdmissionClass::Session;
45        self
46    }
47
48    /// Sets semantic memory retained while the operation remains owned.
49    #[must_use]
50    pub const fn retained_bytes(mut self, retained_bytes: RetainedBytes) -> Self {
51        self.retained_bytes = retained_bytes;
52        self
53    }
54
55    /// Reserves the maximum memory retained by the complete outbound frame.
56    #[must_use]
57    pub const fn write_retained_bytes(mut self, retained_bytes: RetainedBytes) -> Self {
58        self.write_retained_bytes = retained_bytes;
59        self
60    }
61
62    /// Selects whether this operation waits for a reply or completes on write.
63    #[must_use]
64    pub const fn completion_mode(mut self, completion_mode: CompletionMode) -> Self {
65        self.completion_mode = completion_mode;
66        self
67    }
68
69    /// Returns the absolute deadline.
70    pub const fn deadline(self) -> Deadline {
71        self.deadline
72    }
73
74    /// Returns the admission class.
75    pub const fn class(self) -> AdmissionClass {
76        self.class
77    }
78
79    /// Returns semantic retained bytes.
80    pub const fn retained(self) -> RetainedBytes {
81        self.retained_bytes
82    }
83
84    /// Returns reserved complete-frame retained memory.
85    pub const fn write_retained(self) -> RetainedBytes {
86        self.write_retained_bytes
87    }
88
89    /// Returns the mechanical completion condition.
90    pub const fn completion(self) -> CompletionMode {
91        self.completion_mode
92    }
93}