mirror of
https://github.com/danog/libdvb.git
synced 2024-11-30 04:19:00 +01:00
fe: open by adapter and device number
This commit is contained in:
parent
8fe2424f56
commit
c4c33e86ad
@ -1,9 +1,6 @@
|
||||
use {
|
||||
std::{
|
||||
path::Path,
|
||||
},
|
||||
|
||||
anyhow::{
|
||||
bail,
|
||||
Context,
|
||||
Result,
|
||||
},
|
||||
@ -15,10 +12,20 @@ use {
|
||||
};
|
||||
|
||||
|
||||
fn check_frontend(path: &Path) -> Result<()> {
|
||||
println!("Frontend: {}", path.display());
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
|
||||
let fe = FeDevice::open_rd(path)?;
|
||||
let adapter = match args.next() {
|
||||
Some(v) => v.parse::<u32>().context("adapter number")?,
|
||||
None => bail!("adapter number not defined"),
|
||||
};
|
||||
|
||||
let device = match args.next() {
|
||||
Some(v) => v.parse::<u32>().context("device number")?,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let fe = FeDevice::open(adapter, device, true)?;
|
||||
println!("{}", &fe);
|
||||
|
||||
let mut status = FeStatus::default();
|
||||
@ -27,54 +34,3 @@ fn check_frontend(path: &Path) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn list_devices(path: &Path) -> Result<()> {
|
||||
for entry in path.read_dir().context("list adapter directory")? {
|
||||
let entry = entry?;
|
||||
let device_path = entry.path();
|
||||
|
||||
let file_name = device_path.file_name()
|
||||
.unwrap_or_default()
|
||||
.to_str()
|
||||
.unwrap_or_default();
|
||||
|
||||
if file_name.starts_with("frontend") {
|
||||
if let Err(e) = check_frontend(&device_path) {
|
||||
eprintln!("failed to get frontend info");
|
||||
for cause in e.chain() {
|
||||
eprintln!("> {}", &cause);
|
||||
}
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn start(fepath: Option<&str>) -> Result<()> {
|
||||
if let Some(fepath) = fepath {
|
||||
let path = Path::new(fepath);
|
||||
check_frontend(&path)?;
|
||||
} else {
|
||||
let path = Path::new("/dev/dvb");
|
||||
|
||||
for entry in path.read_dir().context("list dvb directory")? {
|
||||
let entry = entry?;
|
||||
let adapter_path = entry.path();
|
||||
if let Err(e) = list_devices(&adapter_path) {
|
||||
eprintln!("failed to list devices in {}\n{}", adapter_path.display(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
start(args.next().as_deref())
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
use {
|
||||
std::{
|
||||
path::Path,
|
||||
time::Duration,
|
||||
thread,
|
||||
},
|
||||
|
||||
anyhow::{
|
||||
anyhow,
|
||||
bail,
|
||||
Context,
|
||||
Result,
|
||||
},
|
||||
|
||||
@ -17,28 +17,26 @@ use {
|
||||
};
|
||||
|
||||
|
||||
pub fn start(fepath: &str) -> Result<()> {
|
||||
let fepath = Path::new(fepath);
|
||||
println!("Frontend: {}", fepath.display());
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
|
||||
let fe = FeDevice::open_rd(fepath)?;
|
||||
let adapter = match args.next() {
|
||||
Some(v) => v.parse::<u32>().context("adapter number")?,
|
||||
None => bail!("adapter number not defined"),
|
||||
};
|
||||
|
||||
let device = match args.next() {
|
||||
Some(v) => v.parse::<u32>().context("device number")?,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let fe = FeDevice::open(adapter, device, true)?;
|
||||
let mut status = FeStatus::default();
|
||||
|
||||
let delay = Duration::from_secs(1);
|
||||
|
||||
loop {
|
||||
status.read(&fe)?;
|
||||
println!("{}", &status);
|
||||
thread::sleep(delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
if let Some(ref fepath) = args.next() {
|
||||
start(fepath)
|
||||
} else {
|
||||
Err(anyhow!("Path to frontend not defined"))
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
use anyhow::{Context, bail};
|
||||
|
||||
use {
|
||||
anyhow::Result,
|
||||
anyhow::{
|
||||
bail,
|
||||
Context,
|
||||
Result,
|
||||
},
|
||||
|
||||
libdvb::NetDevice,
|
||||
};
|
||||
|
@ -48,6 +48,9 @@ pub use {
|
||||
/// A reference to the frontend device and device information
|
||||
#[derive(Debug)]
|
||||
pub struct FeDevice {
|
||||
adapter: u32,
|
||||
device: u32,
|
||||
|
||||
file: File,
|
||||
|
||||
api_version: u16,
|
||||
@ -166,15 +169,20 @@ impl FeDevice {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn open<P: AsRef<Path>>(path: P, w: bool) -> Result<FeDevice> {
|
||||
/// Attempts to open a frontend device in read-only mode
|
||||
pub fn open(adapter: u32, device: u32, readonly: bool) -> Result<FeDevice> {
|
||||
let path = format!("/dev/dvb/adapter{}/frontend{}", adapter, device);
|
||||
let file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(w)
|
||||
.write(!readonly)
|
||||
.custom_flags(::nix::libc::O_NONBLOCK)
|
||||
.open(path)
|
||||
.open(&path)
|
||||
.context("FE: open")?;
|
||||
|
||||
let mut fe = FeDevice {
|
||||
adapter,
|
||||
device,
|
||||
|
||||
file,
|
||||
|
||||
api_version: 0,
|
||||
@ -191,14 +199,6 @@ impl FeDevice {
|
||||
Ok(fe)
|
||||
}
|
||||
|
||||
/// Attempts to open a frontend device in read-only mode
|
||||
#[inline]
|
||||
pub fn open_rd<P: AsRef<Path>>(path: P) -> Result<FeDevice> { Self::open(path, false) }
|
||||
|
||||
/// Attempts to open a frontend device in read-write mode
|
||||
#[inline]
|
||||
pub fn open_rw<P: AsRef<Path>>(path: P) -> Result<FeDevice> { Self::open(path, true) }
|
||||
|
||||
fn check_properties(&self, cmdseq: &[DtvProperty]) -> Result<()> {
|
||||
for p in cmdseq {
|
||||
match p.cmd {
|
||||
|
Loading…
Reference in New Issue
Block a user