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

Export stuff and make WiFiDevice owning its Device #124

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use errors::*;
use dbus_nm::DBusNetworkManager;

use wifi::{new_wifi_device, WiFiDevice};
use wifi::WiFiDevice;

#[derive(Clone)]
pub struct Device {
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Device {

pub fn as_wifi_device(&self) -> Option<WiFiDevice> {
if self.device_type == DeviceType::WiFi {
Some(new_wifi_device(&self.dbus_manager, self))
Some(WiFiDevice::new(self.dbus_manager.clone(), self.clone()))
} else {
None
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ mod ssid;
pub use manager::{Connectivity, NetworkManager};
pub use connection::{Connection, ConnectionSettings, ConnectionState};
pub use device::{Device, DeviceState, DeviceType};
pub use wifi::{AccessPoint, AccessPointCredentials, Security};
pub use wifi::{AccessPoint, AccessPointCredentials, Security, WiFiDevice};
pub use service::ServiceState;
pub use ssid::{Ssid, SsidSlice};
4 changes: 0 additions & 4 deletions src/ssid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ impl Ssid {
}
}

pub trait IntoSsid: Sized {
fn into_ssid(self) -> Result<Ssid>;
}

impl Deref for Ssid {
type Target = SsidSlice;

Expand Down
35 changes: 22 additions & 13 deletions src/wifi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::rc::Rc;
use std::net::Ipv4Addr;
use std::ops::Deref;

use errors::*;
use dbus_nm::DBusNetworkManager;
Expand All @@ -8,12 +9,22 @@ use connection::{connect_to_access_point, create_hotspot, Connection, Connection
use device::{Device, PathGetter};
use ssid::{AsSsidSlice, Ssid, SsidSlice};

pub struct WiFiDevice<'a> {
pub struct WiFiDevice {
dbus_manager: Rc<DBusNetworkManager>,
device: &'a Device,
device: Device,
}

impl<'a> WiFiDevice<'a> {
impl WiFiDevice {
pub(crate) fn new(
dbus_manager: Rc<DBusNetworkManager>,
device: Device,
) -> WiFiDevice {
WiFiDevice {
dbus_manager,
device,
}
}

/// Get the list of access points visible to this device.
///
/// # Examples
Expand Down Expand Up @@ -85,6 +96,14 @@ impl<'a> WiFiDevice<'a> {
}
}

impl Deref for WiFiDevice {
type Target = Device;

fn deref(&self) -> &Self::Target {
&self.device
}
}

#[derive(Debug)]
pub struct AccessPoint {
pub path: String,
Expand Down Expand Up @@ -166,16 +185,6 @@ bitflags! {
}
}

pub fn new_wifi_device<'a>(
dbus_manager: &Rc<DBusNetworkManager>,
device: &'a Device,
) -> WiFiDevice<'a> {
WiFiDevice {
dbus_manager: Rc::clone(dbus_manager),
device: device,
}
}

fn get_access_point(manager: &DBusNetworkManager, path: &str) -> Result<Option<AccessPoint>> {
if let Some(ssid) = manager.get_access_point_ssid(path) {
let strength = manager.get_access_point_strength(path)?;
Expand Down