#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use super::visa_ffi::*;
use super::err::VisaWrapperError;
use dlopen2::wrapper::Container;
use std::borrow::Cow;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub enum Binary {
Keysight,
NiVisa,
#[default]
PlatformDefault,
Custom(String),
}
impl Binary {
fn binary_name(&self) -> Result<Cow<str>, VisaWrapperError> {
Ok(match self {
Binary::Keysight => {
if cfg!(target_family = "windows") {
"ktvisa32.dll".into()
} else if cfg!(target_family = "unix") && cfg!(target_pointer_width = "64") {
"libiovisa.so".into()
} else {
return Err(VisaWrapperError::UnsupportedPlatform);
}
} Binary::NiVisa => {
if cfg!(target_family = "windows") && cfg!(target_pointer_width = "64") {
"nivisa64.dll".into()
} else if cfg!(target_family = "windows") && cfg!(target_pointer_width = "32") {
"visa32.dll".into()
} else if cfg!(target_family = "unix") && cfg!(target_pointer_width = "64") {
"libvisa.so".into()
} else {
return Err(VisaWrapperError::UnsupportedPlatform);
}
} Binary::PlatformDefault => {
if cfg!(target_family = "windows") {
"visa32".into()
} else if cfg!(target_family = "unix") && cfg!(target_pointer_width = "64") {
"libvisa.so".into()
} else if cfg!(target_family = "unix") && cfg!(target_pointer_width = "32") {
"libvisa32.so".into()
} else {
return Err(VisaWrapperError::UnsupportedPlatform);
}
}
Binary::Custom(path) => path.into(),
})
}
}
impl ToString for Binary {
fn to_string(&self) -> String {
self.binary_name()
.unwrap_or_else(|e| e.to_string().into())
.into()
}
}
pub fn make(bin: &Binary) -> Result<Container<VisaFFI>, VisaWrapperError> {
unsafe { Container::load(bin.binary_name()?.as_ref()).map_err(|e| VisaWrapperError::from(e)) }
}