Skip to main content

bornera_core/connection/
input.rs

1//! Data-only inputs accepted by one connection epoch.
2
3use calandria::Moment;
4
5use crate::{CloseReason, ConnectionEpoch, OperationId};
6
7/// An observation or command applied to the deterministic epoch machine.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9#[non_exhaustive]
10pub enum ConnectionInput {
11    /// The protocol session owner completed establishment.
12    OpenAdmission {
13        /// Exact epoch whose protocol session was established.
14        epoch: ConnectionEpoch,
15    },
16    /// Explicitly cancel local operation ownership.
17    Cancel {
18        /// Epoch named by the caller.
19        epoch: ConnectionEpoch,
20        /// Operation to cancel.
21        operation: OperationId,
22    },
23    /// A scheduled absolute deadline was observed.
24    DeadlineElapsed {
25        /// Epoch named by the timer event.
26        epoch: ConnectionEpoch,
27        /// Operation whose deadline was scheduled.
28        operation: OperationId,
29        /// Current fixed-width monotonic moment.
30        now: Moment,
31    },
32    /// The adapter rejected a complete inbound frame as malformed.
33    ReplyMalformed {
34        /// Epoch that produced the malformed frame.
35        epoch: ConnectionEpoch,
36    },
37    /// Close admission, then finish already accepted work.
38    BeginDrain {
39        /// Exact epoch whose admission should close before draining.
40        epoch: ConnectionEpoch,
41    },
42    /// Force closure of this epoch.
43    CloseRequested {
44        /// Epoch named by the requester or capability.
45        epoch: ConnectionEpoch,
46        /// Mechanical closure reason.
47        reason: CloseReason,
48    },
49    /// Confirm that the physical capability is closed.
50    EpochClosed {
51        /// Epoch whose capability closed.
52        epoch: ConnectionEpoch,
53    },
54}
55
56/// A complete opaque frame classified by an adapter as a reply.
57#[derive(Clone, Debug, Eq, PartialEq)]
58pub struct InboundReply<F> {
59    pub(crate) epoch: ConnectionEpoch,
60    pub(crate) key: crate::MatchKey,
61    pub(crate) frame: F,
62}
63
64impl<F> InboundReply<F> {
65    /// Creates a reply input after protocol-specific classification.
66    pub const fn new(epoch: ConnectionEpoch, key: crate::MatchKey, frame: F) -> Self {
67        Self { epoch, key, frame }
68    }
69
70    /// Returns the epoch that produced the frame.
71    pub const fn epoch(&self) -> ConnectionEpoch {
72        self.epoch
73    }
74
75    /// Returns the protocol-visible match key extracted by the adapter.
76    pub const fn key(&self) -> crate::MatchKey {
77        self.key
78    }
79
80    /// Recovers the opaque frame before it is applied to a machine.
81    pub fn into_frame(self) -> F {
82        self.frame
83    }
84}