use crate::effect::EffectHandler;
use crate::engine::{
ObsEvent, ProtocolMachine, ProtocolMachineConfig, ProtocolMachineError, RunStatus, StepResult,
};
use crate::kernel::ProtocolMachineKernel;
use crate::loader::CodeImage;
use crate::owned::OwnedSession;
#[doc(alias = "GuestRuntime")]
#[derive(Debug)]
pub struct NativeSingleThreadDriver {
machine: ProtocolMachine,
}
impl NativeSingleThreadDriver {
#[must_use]
pub fn new(config: ProtocolMachineConfig) -> Self {
Self {
machine: ProtocolMachine::new(config),
}
}
#[must_use]
pub fn with_vm(machine: ProtocolMachine) -> Self {
Self { machine }
}
#[must_use]
pub fn machine(&self) -> &ProtocolMachine {
&self.machine
}
pub fn load_choreography_owned(
&mut self,
image: &CodeImage,
owner_id: impl Into<String>,
) -> Result<OwnedSession, ProtocolMachineError> {
self.machine.load_choreography_owned(image, owner_id)
}
pub fn step_round(
&mut self,
handler: &dyn EffectHandler,
n: usize,
) -> Result<StepResult, ProtocolMachineError> {
ProtocolMachineKernel::step_round(&mut self.machine, handler, n)
}
pub fn run(
&mut self,
handler: &dyn EffectHandler,
max_rounds: usize,
n: usize,
) -> Result<RunStatus, ProtocolMachineError> {
ProtocolMachineKernel::run_concurrent(&mut self.machine, handler, max_rounds, n)
}
#[must_use]
pub fn trace(&self) -> &[ObsEvent] {
self.machine.trace()
}
}