diff --git a/Cargo.toml b/Cargo.toml index c9ac9ed..8e08a3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libdvb" -version = "0.2.3" +version = "0.3.0" description = "Interface for DVB-API v5 devices in Linux" authors = ["Cesbo Developers Team "] license = "MIT" diff --git a/README.md b/README.md index 4a19303..ba4792e 100644 --- a/README.md +++ b/README.md @@ -36,21 +36,21 @@ let cmdseq = vec![ DtvProperty::new(DTV_TUNE, 0), ]; -let fe = FeDevice::open_rw("/dev/dvb/adapter0/frontend0")?; +let fe = FeDevice::open_rw(0, 0)?; fe.set_properties(&cmdseq)?; ``` Frontend information: ```rust -let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?; +let fe = FeDevice::open_ro(0, 0)?; println!("{}", &fe); ``` Frontend status: ```rust -let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?; +let fe = FeDevice::open_ro(0, 0)?; let mut status = FeStatus::default(); status.read(&fe)?; println!("{}", &status); diff --git a/examples/cainfo.rs b/examples/cainfo.rs index 42a4aa2..ca9bc07 100644 --- a/examples/cainfo.rs +++ b/examples/cainfo.rs @@ -3,7 +3,11 @@ use { os::unix::io::AsRawFd, }, - anyhow::Result, + anyhow::{ + bail, + Context, + Result, + }, nix::{ poll::{ diff --git a/examples/feinfo.rs b/examples/feinfo.rs index 6c96776..76971d6 100644 --- a/examples/feinfo.rs +++ b/examples/feinfo.rs @@ -25,7 +25,7 @@ fn main() -> Result<()> { None => 0, }; - let fe = FeDevice::open(adapter, device, true)?; + let fe = FeDevice::open_ro(adapter, device)?; println!("{}", &fe); let mut status = FeStatus::default(); diff --git a/examples/femon.rs b/examples/femon.rs index 9afa5fc..a31f8cf 100644 --- a/examples/femon.rs +++ b/examples/femon.rs @@ -30,7 +30,7 @@ fn main() -> Result<()> { None => 0, }; - let fe = FeDevice::open(adapter, device, true)?; + let fe = FeDevice::open_ro(adapter, device)?; let mut status = FeStatus::default(); let delay = Duration::from_secs(1); diff --git a/src/fe/mod.rs b/src/fe/mod.rs index 80bc487..14829a7 100644 --- a/src/fe/mod.rs +++ b/src/fe/mod.rs @@ -168,12 +168,11 @@ impl FeDevice { Ok(()) } - /// Attempts to open a frontend device in read-only mode - pub fn open(adapter: u32, device: u32, readonly: bool) -> Result { + fn open(adapter: u32, device: u32, is_write: bool) -> Result { let path = format!("/dev/dvb/adapter{}/frontend{}", adapter, device); let file = OpenOptions::new() .read(true) - .write(!readonly) + .write(is_write) .custom_flags(::nix::libc::O_NONBLOCK) .open(&path) .with_context(|| format!("FE: failed to open device {}", &path))?; @@ -198,6 +197,20 @@ impl FeDevice { Ok(fe) } + /// Attempts to open frontend device in read-only mode + #[inline] + pub fn open_ro(adapter: u32, device: u32) -> Result + { + Self::open(adapter, device, false) + } + + /// Attempts to open frontend device in read-write mode + #[inline] + pub fn open_rw(adapter: u32, device: u32) -> Result + { + Self::open(adapter, device, true) + } + fn check_properties(&self, cmdseq: &[DtvProperty]) -> Result<()> { for p in cmdseq { match p.cmd {