use linuxcnc_hal_sys::HAL_NAME_LEN;
#[derive(thiserror::Error, Debug, PartialEq)]
pub enum StorageError {
#[error("pointer is null")]
Null,
#[error("pointer is not aligned")]
Alignment,
}
#[derive(thiserror::Error, Debug, PartialEq)]
pub enum PinRegisterError {
#[error("pin name is too long. Must be no longer than {} bytes", HAL_NAME_LEN)]
NameLength,
#[error("pin name could not be converted to a valid C string")]
NameConversion,
#[error("failed to allocate shared memory storage for pin")]
Storage(StorageError),
#[error("HAL method returned invalid (EINVAL) status code")]
Invalid,
#[error("HAL is locked")]
LockedHal,
#[error("not enough free memory to allocate storage")]
Memory,
}
#[derive(thiserror::Error, Debug, PartialEq)]
pub enum ParameterRegisterError {
#[error(
"Parameter name is too long. Must be no longer than {} bytes",
HAL_NAME_LEN
)]
NameLength,
#[error("Parameter name could not be converted to a valid C string")]
NameConversion,
#[error("failed to allocate shared memory storage for parameter")]
Storage(StorageError),
#[error("HAL method returned invalid (EINVAL) status code")]
Invalid,
#[error("HAL is locked")]
LockedHal,
#[error("not enough free memory to allocate storage")]
Memory,
}
#[derive(thiserror::Error, Debug)]
pub enum ComponentInitError {
#[error(
"component name is too long. Must be no longer than {} bytes",
HAL_NAME_LEN
)]
NameLength,
#[error("component name cannot be converted to valid C string")]
InvalidName,
#[error("not enough free memory to allocate storage")]
Memory,
#[error("failed to register signal handlers")]
Signals(std::io::Error),
#[error("failed to register resources with component")]
ResourceRegistration(ResourcesError),
#[error("failed to initialise component")]
Init,
#[error("failed to ready component")]
Ready,
}
#[derive(thiserror::Error, Debug)]
pub enum ResourcesError {
#[error("pin registration failed")]
Pin(PinRegisterError),
#[error("parameter registration failed")]
Parameter(ParameterRegisterError),
}
impl From<PinRegisterError> for ResourcesError {
fn from(e: PinRegisterError) -> Self {
Self::Pin(e)
}
}
impl From<ParameterRegisterError> for ResourcesError {
fn from(e: ParameterRegisterError) -> Self {
Self::Parameter(e)
}
}