use crate::effect::EffectHandler;
use crate::engine::{ObsEvent, ProtocolMachineConfig, ProtocolMachineError, RunStatus, StepResult};
use crate::loader::CodeImage;
use crate::owned::OwnedSession;
use crate::threaded::ThreadedProtocolMachine;
#[doc(alias = "ThreadedGuestRuntime")]
pub struct NativeThreadedDriver {
machine: ThreadedProtocolMachine,
}
impl NativeThreadedDriver {
#[must_use]
pub fn with_workers(config: ProtocolMachineConfig, workers: usize) -> Self {
Self {
machine: ThreadedProtocolMachine::with_workers(config, workers),
}
}
#[must_use]
pub fn auto(config: ProtocolMachineConfig) -> Self {
Self {
machine: ThreadedProtocolMachine::auto(config),
}
}
#[must_use]
pub fn with_vm(machine: ThreadedProtocolMachine) -> Self {
Self { machine }
}
#[must_use]
pub fn machine(&self) -> &ThreadedProtocolMachine {
&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> {
self.machine.step_round(handler, n)
}
pub fn run(
&mut self,
handler: &dyn EffectHandler,
max_rounds: usize,
) -> Result<RunStatus, ProtocolMachineError> {
self.machine.run(handler, max_rounds)
}
#[must_use]
pub fn trace(&self) -> &[ObsEvent] {
self.machine.trace()
}
}