breaking(features): add mdns feature + example
This commit is contained in:
2
.github/workflows/python-build.yml
vendored
2
.github/workflows/python-build.yml
vendored
@@ -35,4 +35,4 @@ jobs:
|
||||
with:
|
||||
files: |
|
||||
target/wheels/pyadb_client*.whl
|
||||
target/wheels/pyadb_client*.tar.gz
|
||||
target/wheels/pyadb_client*.tar.gz
|
||||
|
||||
6
.github/workflows/rust-build.yml
vendored
6
.github/workflows/rust-build.yml
vendored
@@ -18,6 +18,6 @@ jobs:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build project
|
||||
run: cargo build --release --all-features
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build project
|
||||
run: cargo build --release --all-features
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
members = ["adb_cli", "adb_client", "pyadb_client"]
|
||||
members = ["adb_cli", "adb_client", "examples/mdns", "pyadb_client"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
|
||||
@@ -11,7 +11,7 @@ rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
adb_client = { version = "^2.0.0" }
|
||||
adb_client = { version = "^2.0.0", features = ["mdns"] }
|
||||
anyhow = { version = "1.0.94" }
|
||||
clap = { version = "4.5.23", features = ["derive"] }
|
||||
env_logger = { version = "0.11.5" }
|
||||
|
||||
@@ -10,6 +10,14 @@ repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
mdns = ["dep:mdns-sd"]
|
||||
|
||||
[dependencies]
|
||||
base64 = { version = "0.22.1" }
|
||||
bincode = { version = "1.3.3" }
|
||||
@@ -18,9 +26,6 @@ chrono = { version = "0.4.40", default-features = false, features = ["std"] }
|
||||
homedir = { version = "= 0.3.4" }
|
||||
image = { version = "0.25.5", default-features = false }
|
||||
log = { version = "0.4.26" }
|
||||
mdns-sd = { version = "0.13.9", default-features = false, features = [
|
||||
"logging",
|
||||
] }
|
||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
||||
num-traits = { version = "0.2.19" }
|
||||
quick-protobuf = { version = "0.8.1" }
|
||||
@@ -39,6 +44,13 @@ serde_repr = { version = "0.1.19" }
|
||||
sha1 = { version = "0.10.6", features = ["oid"] }
|
||||
thiserror = { version = "2.0.7" }
|
||||
|
||||
#########
|
||||
# MDNS dependencies
|
||||
mdns-sd = { version = "0.13.9", default-features = false, features = [
|
||||
"logging",
|
||||
], optional = true }
|
||||
#########
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = { version = "1.0.93" }
|
||||
criterion = { version = "0.6.0" } # Used for benchmarks
|
||||
|
||||
@@ -16,6 +16,19 @@ Add `adb_client` crate as a dependency by simply adding it to your `Cargo.toml`:
|
||||
adb_client = "*"
|
||||
```
|
||||
|
||||
## Crate features
|
||||
|
||||
|Feature|Description|Default?|
|
||||
|:-----:|:---------:|:-----:|
|
||||
|`mdns`|Enables mDNS device discovery on local network.|No|
|
||||
|
||||
To deactivate some features you can use the `default-features = false` option in your `Cargo.toml` file and manually specify the features you want to activate:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
adb_client = { version = "*", default-features = false, features=[""] }
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
||||
|
||||
@@ -13,7 +13,7 @@ pub trait ADBDeviceExt {
|
||||
|
||||
/// Starts an interactive shell session on the device.
|
||||
/// Input data is read from reader and write to writer.
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()>;
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<dyn Write + Send>) -> Result<()>;
|
||||
|
||||
/// Display the stat information for a remote file
|
||||
fn stat(&mut self, remote_path: &str) -> Result<AdbStatResponse>;
|
||||
|
||||
@@ -11,7 +11,7 @@ impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
||||
self.shell_command(command, output)
|
||||
}
|
||||
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<dyn Write + Send>) -> Result<()> {
|
||||
self.shell(reader, writer)
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ impl ADBDeviceExt for ADBTcpDevice {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<dyn Write + Send>) -> Result<()> {
|
||||
self.inner.shell(reader, writer)
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ impl ADBDeviceExt for ADBUSBDevice {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn shell<'a>(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
fn shell<'a>(&mut self, reader: &mut dyn Read, writer: Box<dyn Write + Send>) -> Result<()> {
|
||||
self.inner.shell(reader, writer)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn shell(
|
||||
&mut self,
|
||||
mut reader: &mut dyn Read,
|
||||
mut writer: Box<(dyn Write + Send)>,
|
||||
mut writer: Box<dyn Write + Send>,
|
||||
) -> Result<()> {
|
||||
self.open_session(b"shell:\0")?;
|
||||
|
||||
|
||||
@@ -112,9 +112,13 @@ pub enum RustADBError {
|
||||
#[error("upgrade error: {0}")]
|
||||
UpgradeError(String),
|
||||
/// An error occurred while getting mdns devices
|
||||
#[cfg(feature = "mdns")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||
#[error(transparent)]
|
||||
MDNSError(#[from] mdns_sd::Error),
|
||||
/// An error occurred while sending data to channel
|
||||
#[cfg(feature = "mdns")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||
#[error(transparent)]
|
||||
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
||||
/// An unknown transport has been provided
|
||||
|
||||
@@ -3,12 +3,19 @@
|
||||
#![forbid(missing_debug_implementations)]
|
||||
#![forbid(missing_docs)]
|
||||
#![doc = include_str!("../README.md")]
|
||||
// Feature `doc_cfg` is currently only available on nightly.
|
||||
// It is activated when cfg `docsrs` is enabled.
|
||||
// Documentation can be build locally using:
|
||||
// `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features`
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
mod adb_device_ext;
|
||||
mod constants;
|
||||
mod device;
|
||||
mod emulator_device;
|
||||
mod error;
|
||||
#[cfg(feature = "mdns")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||
mod mdns;
|
||||
mod models;
|
||||
mod server;
|
||||
@@ -20,6 +27,8 @@ pub use adb_device_ext::ADBDeviceExt;
|
||||
pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
|
||||
pub use emulator_device::ADBEmulatorDevice;
|
||||
pub use error::{Result, RustADBError};
|
||||
#[cfg(feature = "mdns")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||
pub use mdns::*;
|
||||
pub use models::{AdbStatResponse, RebootType};
|
||||
pub use server::*;
|
||||
|
||||
@@ -49,7 +49,7 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
fn shell(
|
||||
&mut self,
|
||||
mut reader: &mut dyn Read,
|
||||
mut writer: Box<(dyn Write + Send)>,
|
||||
mut writer: Box<dyn Write + Send>,
|
||||
) -> Result<()> {
|
||||
let supported_features = self.host_features()?;
|
||||
if !supported_features.contains(&HostFeatures::ShellV2)
|
||||
|
||||
15
examples/mdns/Cargo.toml
Normal file
15
examples/mdns/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "mdns"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
keywords.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
version.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
adb_client = { path = "../../adb_client", default-features = false, features = [
|
||||
"mdns",
|
||||
] }
|
||||
21
examples/mdns/src/main.rs
Normal file
21
examples/mdns/src/main.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use adb_client::{MDNSDevice, MDNSDiscoveryService};
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Starting mDNS device discovery...");
|
||||
|
||||
// Create a channel to receive discovered devices information
|
||||
let (sender, receiver) = mpsc::channel::<MDNSDevice>();
|
||||
|
||||
// Create and start the discovery service
|
||||
let mut discovery = MDNSDiscoveryService::new()?;
|
||||
discovery.start(sender)?;
|
||||
|
||||
loop {
|
||||
if let Ok(device) = receiver.recv_timeout(Duration::from_millis(100)) {
|
||||
println!("Found device: {}", device.fullname);
|
||||
println!(" Addresses: {:?}", device.addresses);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user