use crate::error::CaResult;
use crate::server::record::{ProcessAction, Record, ScanType};
pub fn is_soft_dtyp(dtyp: &str) -> bool {
dtyp.is_empty()
|| dtyp == "Soft Channel"
|| dtyp == "Raw Soft Channel"
|| dtyp == "Async Soft Channel"
|| dtyp == "Soft Timestamp"
|| dtyp == "Sec Past Epoch"
}
pub trait WriteCompletion: Send + 'static {
fn wait(&self, timeout: std::time::Duration) -> CaResult<()>;
}
#[derive(Default)]
pub struct DeviceReadOutcome {
pub actions: Vec<ProcessAction>,
pub did_compute: bool,
}
impl DeviceReadOutcome {
pub fn ok() -> Self {
Self::default()
}
pub fn computed() -> Self {
Self {
did_compute: true,
actions: Vec::new(),
}
}
pub fn computed_with(actions: Vec<ProcessAction>) -> Self {
Self {
did_compute: true,
actions,
}
}
}
pub trait DeviceSupport: Send + Sync + 'static {
fn init(&mut self, _record: &mut dyn Record) -> CaResult<()> {
Ok(())
}
fn read(&mut self, record: &mut dyn Record) -> CaResult<DeviceReadOutcome> {
let _ = record;
Ok(DeviceReadOutcome::ok())
}
fn write(&mut self, record: &mut dyn Record) -> CaResult<()>;
fn dtyp(&self) -> &str;
fn last_alarm(&self) -> Option<(u16, u16)> {
None
}
fn last_timestamp(&self) -> Option<std::time::SystemTime> {
None
}
fn set_record_info(&mut self, _name: &str, _scan: ScanType) {}
fn io_intr_receiver(&mut self) -> Option<crate::runtime::sync::mpsc::Receiver<()>> {
None
}
fn write_begin(
&mut self,
_record: &mut dyn Record,
) -> CaResult<Option<Box<dyn WriteCompletion>>> {
Ok(None)
}
fn handle_command(
&mut self,
_record: &mut dyn Record,
_command: &str,
_args: &[crate::types::EpicsValue],
) -> CaResult<()> {
Ok(())
}
}