use base::Error as SysError;
use base::TubeError;
use net_util::Error as TapError;
use remain::sorted;
use thiserror::Error;
#[cfg(any(target_os = "android", target_os = "linux"))]
use vhost::Error as VhostError;
mod control_socket;
pub use self::control_socket::*;
cfg_if::cfg_if! {
    if #[cfg(any(target_os = "android", target_os = "linux"))] {
        #[cfg(feature = "net")]
        mod net;
        pub mod vsock;
        #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
        pub mod scmi;
        mod worker;
        #[cfg(feature = "net")]
        pub use self::net::Net;
        pub use self::vsock::Vsock;
        #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
        pub use self::scmi::Scmi;
    } else if #[cfg(windows)] {}
}
#[sorted]
#[derive(Error, Debug)]
pub enum Error {
    #[error("failed to clone kill event: {0}")]
    CloneKillEvent(SysError),
    #[error("failed to create kill event: {0}")]
    CreateKillEvent(SysError),
    #[error("failed to create tube: {0}")]
    CreateTube(TubeError),
    #[error("failed to create poll context: {0}")]
    CreateWaitContext(SysError),
    #[error("failed to enable tap interface: {0}")]
    TapEnable(TapError),
    #[error("failed to open tap device: {0}")]
    TapOpen(TapError),
    #[error("failed to set tap IP: {0}")]
    TapSetIp(TapError),
    #[error("failed to set tap mac address: {0}")]
    TapSetMacAddress(TapError),
    #[error("failed to set tap netmask: {0}")]
    TapSetNetmask(TapError),
    #[error("failed to set tap interface offload flags: {0}")]
    TapSetOffload(TapError),
    #[error("failed to set vnet header size: {0}")]
    TapSetVnetHdrSize(TapError),
    #[error("failed to read vhost error event: {0}")]
    VhostErrorRead(SysError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to get features: {0}")]
    VhostGetFeatures(VhostError),
    #[error("Vhost IOTLB required but not supported")]
    VhostIotlbUnsupported,
    #[error("failed to create vhost event: {0}")]
    VhostIrqCreate(SysError),
    #[error("failed to read vhost interrupt event: {0}")]
    VhostIrqRead(SysError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("net set backend failed: {0}")]
    VhostNetSetBackend(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to open vhost device: {0}")]
    VhostOpen(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set features: {0}")]
    VhostSetFeatures(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set mem table: {0}")]
    VhostSetMemTable(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set owner: {0}")]
    VhostSetOwner(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring addr: {0}")]
    VhostSetVringAddr(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring base: {0}")]
    VhostSetVringBase(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring call: {0}")]
    VhostSetVringCall(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring err: {0}")]
    VhostSetVringErr(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring kick: {0}")]
    VhostSetVringKick(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set vring num: {0}")]
    VhostSetVringNum(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to set CID for guest: {0}")]
    VhostVsockSetCid(VhostError),
    #[cfg(any(target_os = "android", target_os = "linux"))]
    #[error("failed to start vhost-vsock driver: {0}")]
    VhostVsockStart(VhostError),
    #[error("queue missing vring base")]
    VringBaseMissing,
    #[error("failed waiting for events: {0}")]
    WaitError(SysError),
}
pub type Result<T> = std::result::Result<T, Error>;