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, 'root>(
42        app: pin::Pin<&'app mut Self>,
43        plan: &mut Self::ParkPlan,
44        park: executor::raw::Park<'driver, 'turn, 'root, 'd>,
45    ) where
46        'd: 'driver + 'turn + 'root;
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, 'root>(
74        _: pin::Pin<&'app mut Self>,
75        _: executor::raw::Activate<'driver, 'turn, 'root, 'd>,
76    ) -> bool
77    where
78        'd: 'driver + 'turn + 'root,
79    {
80        false
81    }
82
83    fn dispatch<'app, 'driver, 'turn, 'root>(
84        call: executor::raw::Dispatch<'app, 'driver, 'turn, 'root, 'd, Self>,
85    ) -> ops::ControlFlow<io::Event<'d>>
86    where
87        'd: 'root,
88        Self: 'root,
89    {
90        ops::ControlFlow::Break(call.into_event())
91    }
92
93    fn progress(
94        app: pin::Pin<&Self>,
95        view: executor::raw::Progress<'_, '_, 'd>,
96    ) -> schedule::Progress<'d>;
97
98    fn stopping(
99        app: pin::Pin<&Self>,
100        view: executor::raw::Progress<'_, '_, 'd>,
101    ) -> schedule::Progress<'d>;
102
103    fn shutdown<'app, 'turn, 'driver, 'owner>(
104        shutdown: executor::raw::Shutdown<'app, 'turn, 'driver, 'owner, 'd, Self>,
105    ) -> executor::raw::Shutdown<'app, 'turn, 'driver, 'owner, 'd, Self>
106    where
107        'd: 'owner,
108    {
109        shutdown
110    }
111
112    fn finish<'app, 'finish, 'owner, 'epoch>(
113        finish: executor::raw::Finish<'app, 'finish, 'owner, 'epoch, 'd, Self>,
114    ) -> executor::raw::Finish<'app, 'finish, 'owner, 'epoch, 'd, Self> {
115        finish
116    }
117}