harmos_operations/lifecycle/
shutdown.rs1use harmos_domain::{MemorySize, schema::Described};
22
23harmos_domain::postcard_product!(Shutdown {});
28
29#[harmos::operation(harmos_path = crate, codec = manual, id = "harmos.shutdown", response = (), policy = super::POLICY, )]
34#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
35pub struct Shutdown {}
36
37#[cfg(feature = "lifecycle")]
38pub struct Control {
39 #[cfg(feature = "lifecycle")]
40 instance: Box<dyn harmos_sdk::operations::lifecycle::LifecycleInstance>,
41}
42
43impl Described for Shutdown {
50 const NAME: &'static str = <harmos_domain::model::operations::lifecycle::ShutdownSchema as Described>::NAME;
51 const FIELDS: &'static [harmos_domain::schema::declaration::Field] =
52 <harmos_domain::model::operations::lifecycle::ShutdownSchema as Described>::FIELDS;
53 const MARKER: &'static [u8] = <harmos_domain::model::operations::lifecycle::ShutdownSchema as Described>::MARKER;
54}
55
56impl MemorySize for Shutdown {
57 fn memory_size(&self) -> usize {
58 std::mem::size_of::<Self>()
59 }
60}
61
62#[cfg(feature = "lifecycle")]
63impl harmos_sdk::operations::Carrier for Control {
64 type Declaration = Shutdown;
65 type Error = super::ControlError;
66 type StreamEndpoints = ();
67 async fn bind(context: crate::ExecutionContext) -> Result<Self, Self::Error> {
68 let access = context.resource::<harmos_sdk::operations::lifecycle::LifecycleAccess>()?;
69 Ok(Self {
70 instance: access.0.clone().begin(super::Action::Shutdown),
71 })
72 }
73 async fn attempt(
74 &mut self, context: crate::ExecutionContext, request: &mut Shutdown, _: &mut (),
75 ) -> Result<crate::Response<()>, Self::Error> {
76 let _ = &request;
77 self.instance.run(context, &[], &[], &[]).await.map_err(super::ControlError::Access)?;
78 Ok(().into())
79 }
80 async fn cleanup(&mut self) -> Result<(), Self::Error> {
81 self.instance.cleanup().await.map_err(super::ControlError::Access)
82 }
83}
84
85#[cfg(feature = "lifecycle")]
86impl crate::Executable for Shutdown {
87 type Carrier = Control;
88}
89
90