use std::sync::Arc;
use meerkat_core::comms::InputSource;
use meerkat_core::handles::{DslTransitionError, SessionAdmissionHandle};
use meerkat_core::lifecycle::{InputId, RunId};
use super::HandleDslAuthority;
use crate::meerkat_machine::dsl as mm_dsl;
#[derive(Debug)]
pub struct RuntimeSessionAdmissionHandle {
dsl: Arc<HandleDslAuthority>,
}
impl RuntimeSessionAdmissionHandle {
pub fn new(dsl: Arc<HandleDslAuthority>) -> Self {
Self { dsl }
}
pub fn ephemeral() -> Self {
Self::new(Arc::new(HandleDslAuthority::ephemeral()))
}
}
impl SessionAdmissionHandle for RuntimeSessionAdmissionHandle {
fn ingest(
&self,
runtime_id: &str,
work_id: &str,
origin: InputSource,
) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::Ingest {
runtime_id: mm_dsl::AgentRuntimeId::from(runtime_id.to_string()),
work_id: mm_dsl::WorkId::from(work_id.to_string()),
origin: mm_dsl::WorkOrigin::from(origin),
},
"SessionAdmissionHandle::ingest",
)
}
fn accept_with_completion(
&self,
input_id: &InputId,
request_immediate_processing: bool,
interrupt_yielding: bool,
wake_if_idle: bool,
) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::AcceptWithCompletion {
input_id: mm_dsl::InputId::from_domain(input_id),
request_immediate_processing,
interrupt_yielding,
wake_if_idle,
},
"SessionAdmissionHandle::accept_with_completion",
)
}
fn accept_without_wake(&self, input_id: &InputId) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::AcceptWithoutWake {
input_id: mm_dsl::InputId::from_domain(input_id),
},
"SessionAdmissionHandle::accept_without_wake",
)
}
fn prepare(&self, run_id: &RunId) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::Prepare {
session_id: mm_dsl::SessionId::default(),
run_id: mm_dsl::RunId::from_domain(run_id),
},
"SessionAdmissionHandle::prepare",
)
}
fn commit(&self, input_id: &InputId, run_id: &RunId) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::Commit {
input_id: mm_dsl::InputId::from_domain(input_id),
run_id: mm_dsl::RunId::from_domain(run_id),
},
"SessionAdmissionHandle::commit",
)
}
fn recycle(&self) -> Result<(), DslTransitionError> {
self.dsl.apply_input(
mm_dsl::MeerkatMachineInput::Recycle,
"SessionAdmissionHandle::recycle",
)
}
}