Skip to main content

dope_runtime/executor/raw/
app.rs

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