1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! Application lifecycle and resource ownership.
//!
//! Apps lease capabilities from a [`Registry`] when they are created and must
//! return every lease when they are released. This makes resource availability
//! predictable as the platform switches between apps.
use Box;
use Future;
use Pin;
use crateRegistry;
/// An application that can be selected and run by the xpanse firmware.
///
/// `can_run` should mirror the resource set acquired by `new`, without mutating
/// the registry. After `run` completes, the platform passes the app to
/// `release`, which must return all of its resource leases.
///
/// Apps run on core 1, so any task spawned will also run core 1
///
/// Apps can use slint ui or direct video to show stuff on the screen
///
/// # Example
///
/// ```ignore
/// use std::{boxed::Box, future::Future, pin::Pin};
/// use xpanse_api::{
/// app::App,
/// registry::{Registry, ResourceLease},
/// };
///
/// struct StatusLed;
///
/// struct StatusApp {
/// led: ResourceLease<StatusLed>,
/// }
///
/// impl App for StatusApp {
/// const NAME: &'static str = "Status";
///
/// fn can_run(registry: &Registry) -> bool {
/// registry.has::<StatusLed>()
/// }
///
/// fn new(registry: &mut Registry) -> Option<Self> {
/// Some(Self { led: registry.take_resource()? })
/// }
///
/// fn run<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
/// Box::pin(async move {
/// let _led = self.led.resource_mut();
/// // Drive the capability until the app decides to exit.
/// })
/// }
///
/// fn release(self, registry: &mut Registry) {
/// registry.return_resource(self.led);
/// }
/// }
/// ```