Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update libs #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ default = []
introspection = ["xml-rs"]

[dependencies]
dbus = { git = "https://github.com/diwic/dbus-rs" }
dbus-tokio = { git = "https://github.com/diwic/dbus-rs" }
dbus = { version = "0.9", features = ["futures"]}
dbus-tokio = { version = "0.7" }
thiserror = "1.0.11"
tokio = "0.2.13"
tokio = "1.21.2"
xml-rs = { version = "0.3", optional = true }

[dev-dependencies]
tokio = { version = "1.21.2", features = ["full"] }
hex = "0.3"
structopt = "0.2"
8 changes: 1 addition & 7 deletions examples/wifi_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ async fn main() {
let maybe_svc = services.iter().find(|svc| {
//wifi_ffffffffffff_00112233aabbccdd_managed_psk
//tech_mac.addr...._hex.ssid........_security...
let pathv = svc
.path()
.as_cstr()
.to_str()
.unwrap()
.split("_")
.collect::<Vec<&str>>();
let pathv = svc.path().split("_").collect::<Vec<&str>>();
let svc_hex_ssid = *pathv.get(2).unwrap();
let found = svc_hex_ssid == hex_ssid;
if found {
Expand Down
10 changes: 8 additions & 2 deletions src/api/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ impl<T: NonblockReply, C: Deref<Target = T> + Clone> Manager<C> {
pub async fn get_services(&self) -> Result<Vec<Service<C>>, Error> {
let connclone = self.proxy.connection.clone();

let v = IManager::get_services(&self.proxy).await?;
Ok(v.into_iter()
let services = IManager::get_services(&self.proxy).await?;
Ok(services
.into_iter()
.filter_map(|(path, args)| {
Service::new(connclone.clone(), path, args, self.timeout).ok()
})
.collect())
}

pub async fn register_agent(&self, path: dbus::Path<'static>) -> Result<(), Error> {
IManager::register_agent(&self.proxy, path).await?;
Ok(())
}
}

impl<T: NonblockReply, C: Deref<Target = T>> Manager<C> {
Expand Down
16 changes: 10 additions & 6 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#[rustfmt::skip]
mod gen;

pub use gen::manager::ManagerServicesChanged;
pub use gen::service::ServicePropertyChanged;
pub use gen::technology::TechnologyPropertyChanged;

pub mod manager;
pub mod service;
pub mod technology;
Expand Down Expand Up @@ -44,11 +48,11 @@ fn get_property<T: Clone + 'static>(
) -> Result<T, PropertyError> {
properties
.get(prop_name)
.ok_or_else(|| PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.and_then(|variant| {
cast::<T>(&variant.0)
.cloned()
.ok_or_else(|| PropertyError::Cast(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::Cast(Cow::Borrowed(prop_name)))
})
}

Expand All @@ -59,12 +63,12 @@ fn get_property_fromstr<T: FromStr + 'static>(
) -> Result<T, PropertyError> {
properties
.get(prop_name)
.ok_or_else(|| PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.and_then(|variant| {
variant
.as_str()
.and_then(|s| T::from_str(s).ok())
.ok_or_else(|| PropertyError::Cast(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::Cast(Cow::Borrowed(prop_name)))
})
}

Expand All @@ -75,12 +79,12 @@ fn get_property_argiter<'a>(
) -> Result<RefArgIter<'a>, PropertyError> {
properties
.get(prop_name)
.ok_or_else(|| PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::NotPresent(Cow::Borrowed(prop_name)))
.and_then(|variant| {
variant
.0
.as_iter()
.ok_or_else(|| PropertyError::Cast(Cow::Borrowed(prop_name)))
.ok_or(PropertyError::Cast(Cow::Borrowed(prop_name)))
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/technology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl From<PropertyKind> for &'static str {
}
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Type {
Ethernet,
Wifi,
Expand Down