use std::sync::Arc;
use epics_base_rs::error::CaResult;
use epics_base_rs::server::device_support::DeviceSupport;
use epics_base_rs::server::record::Record;
use super::AsynRecord;
use super::io_intr::IoIntrScan;
pub const ASYN_RECORD_DTYP: &str = "asynRecordDevice";
pub struct AsynRecordDevice {
scan: Option<Arc<IoIntrScan>>,
}
impl Default for AsynRecordDevice {
fn default() -> Self {
Self::new()
}
}
impl AsynRecordDevice {
pub fn new() -> Self {
Self { scan: None }
}
}
impl DeviceSupport for AsynRecordDevice {
fn init(&mut self, record: &mut dyn Record) -> CaResult<()> {
self.scan = record
.as_any_mut()
.and_then(|any| any.downcast_mut::<AsynRecord>())
.map(|rec| rec.io_intr_scan());
Ok(())
}
fn write(&mut self, _record: &mut dyn Record) -> CaResult<()> {
Ok(())
}
fn dtyp(&self) -> &str {
ASYN_RECORD_DTYP
}
fn io_intr_receiver(&mut self) -> Option<tokio::sync::mpsc::Receiver<()>> {
self.scan.as_ref()?.take_receiver()
}
fn io_intr_scan_independent(&self) -> bool {
true
}
}