use crate::engine::{EngineAnalysisStore, EngineAnalyzeResult, EngineConfig, EngineStreamRuntime};
pub struct EngineService {
stream: EngineStreamRuntime,
}
impl Default for EngineService {
fn default() -> Self {
use std::sync::{Arc, Mutex};
use crate::engine::uci_ucci_engine::UciUcciEngine;
let engine = Arc::new(Mutex::new(UciUcciEngine::new(None)));
Self {
stream: EngineStreamRuntime::new(engine),
}
}
}
impl std::fmt::Debug for EngineService {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EngineService")
.field("streaming", &self.stream.is_running())
.finish()
}
}
impl EngineService {
pub fn ensure_stream(&self, fen: &str, cfg: &EngineConfig, want_stream: bool) {
self.stream.ensure_stream(fen, cfg, want_stream);
}
pub fn stop_stream(&self) {
self.stream.stop_infinite_stream();
}
pub fn stop_all(&self) {
self.stream.stop_all();
}
pub fn release_if_idle(&self) {
if self.stream.needs_process_release() {
self.stream.release_engine_process();
}
}
pub fn current_store(&self) -> EngineAnalysisStore {
self.stream.clone_store()
}
pub fn snapshot_if_newer(&self, last_revision: u64) -> Option<(EngineAnalysisStore, u64)> {
let revision = self.stream.store_revision();
if revision == last_revision {
return None;
}
Some((self.stream.clone_store(), revision))
}
pub fn is_streaming(&self) -> bool {
self.stream.is_running()
}
pub fn is_autoplay_running(&self) -> bool {
self.stream.is_autoplay_running()
}
pub fn spawn_autoplay_once(&self, fen: &str, cfg: &EngineConfig) {
self.stream.spawn_autoplay_once(fen, cfg);
}
pub fn poll_autoplay_done(&self) -> Option<EngineAnalyzeResult> {
self.stream.poll_autoplay_done()
}
}