Skip to main content

dope_runtime/executor/raw/
app.rs

1use std::{ops, pin};
2
3use dope_core::{
4    driver::{schedule, settings},
5    io,
6};
7
8use crate::executor;
9
10/// Application storage metadata independent of lifecycle eligibility.
11pub trait Layout<'d> {
12    /// Pre-park state selected once and retained with this pinned application.
13    type ParkPlan;
14}
15
16/// # Safety
17/// Visit each owner once through unchanged pinned projections, presence, and operation authority.
18/// Admission includes every present owner's route, without merging duplicate owners.
19/// Keep the root pinned; shutdown preserves client storage and finish destroys dependents before providers.
20pub unsafe trait App<'d>: Sized + Layout<'d> {
21    const ROUTES: settings::Routes;
22
23    /// Routes whose installed owners may receive activation.
24    const WAKE_ROUTES: settings::Routes = settings::Routes::EMPTY;
25
26    /// Upper bound on idle coordinator probes, including delegated probes.
27    const COORDS: usize;
28
29    fn select_park() -> Option<Self::ParkPlan>;
30
31    /// Prepares the selected coordinator shares once after installation.
32    /// The count does not exceed `COORDS`; field presence and shares remain
33    /// stable through finish. `None` reports count overflow.
34    fn prepare_park(_: pin::Pin<&Self>, _: &mut Self::ParkPlan) -> Option<executor::raw::Count> {
35        Some(executor::raw::Count::new(Self::COORDS))
36    }
37
38    /// # Safety
39    /// The exact pinned root is installed and this plan completed preparation
40    /// and admission for that root. The park authority belongs to the same root.
41    unsafe fn park<'app, 'driver, 'turn>(
42        app: pin::Pin<&'app mut Self>,
43        plan: &mut Self::ParkPlan,
44        park: executor::raw::Park<'driver, 'turn, 'd>,
45    ) where
46        'd: 'driver + 'turn;
47
48    /// Accumulates the routes of the owners actually present in this pinned root.
49    fn admit(
50        _: pin::Pin<&Self>,
51        needs: &mut settings::claim::Needs,
52    ) -> Result<(), settings::errors::Claim> {
53        *needs = needs.include(settings::claim::Claim::new(Self::ROUTES))?;
54        Ok(())
55    }
56
57    fn released(released: executor::raw::Released<'_, Self>) -> executor::raw::Released<'_, Self> {
58        released
59    }
60
61    fn install<'app, 'owner>(
62        install: executor::raw::Install<'app, 'owner, 'd, Self>,
63    ) -> executor::raw::Install<'app, 'owner, 'd, Self> {
64        install
65    }
66
67    /// Returns whether a present owner handled this activation. On `false`,
68    /// the caller may continue through the remaining owners of the same root.
69    ///
70    /// # Safety
71    /// The activation retains this exact installed pinned root and a target
72    /// declared by `WAKE_ROUTES`.
73    unsafe fn activate<'app, 'driver, 'turn>(
74        _: pin::Pin<&'app mut Self>,
75        _: executor::raw::Activate<'driver, 'turn, 'd>,
76    ) -> bool
77    where
78        'd: 'driver + 'turn,
79    {
80        false
81    }
82
83    fn dispatch<'app, 'driver, 'turn>(
84        call: executor::raw::Dispatch<'app, 'driver, 'turn, 'd, Self>,
85    ) -> ops::ControlFlow<io::Event<'d>> {
86        ops::ControlFlow::Break(call.into_event())
87    }
88
89    fn progress(
90        app: pin::Pin<&Self>,
91        view: executor::raw::Progress<'_, '_, 'd>,
92    ) -> schedule::Progress<'d>;
93
94    fn stopping(
95        app: pin::Pin<&Self>,
96        view: executor::raw::Progress<'_, '_, 'd>,
97    ) -> schedule::Progress<'d>;
98
99    fn shutdown<'app, 'turn, 'driver>(
100        shutdown: executor::raw::Shutdown<'app, 'turn, 'driver, 'd, Self>,
101    ) -> executor::raw::Shutdown<'app, 'turn, 'driver, 'd, Self> {
102        shutdown
103    }
104
105    fn finish<'app, 'finish, 'owner, 'epoch>(
106        finish: executor::raw::Finish<'app, 'finish, 'owner, 'epoch, 'd, Self>,
107    ) -> executor::raw::Finish<'app, 'finish, 'owner, 'epoch, 'd, Self> {
108        finish
109    }
110}