Skip to content

Commit

Permalink
Auto-merge for PR #80 via VersionBot
Browse files Browse the repository at this point in the history
Enabling automatic Cargo.toml version bump by VersionBot
  • Loading branch information
resin-io-modules-versionbot[bot] authored Jun 15, 2017
2 parents e99b519 + 8b1c0d0 commit 28ba008
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 231 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v0.3.1 - 2017-06-15

* VersionBot config update for automatic Cargo.toml version bump [majorz]

## v0.3.0 - 2017-06-01

* Export publicly ConnectionState and DeviceState [majorz]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "network_manager"
version = "0.3.0"
version = "0.3.1"
authors = ["Joseph Roberts <[email protected]>", "Zahari Petkov <[email protected]>"]

[dependencies]
Expand Down
6 changes: 3 additions & 3 deletions examples/hotspot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn find_device(manager: &NetworkManager, interface: Option<String>) -> Option<De
} else {
let devices = manager.get_devices().unwrap();

let index = devices
.iter()
.position(|d| *d.device_type() == DeviceType::WiFi);
let index = devices.iter().position(
|d| *d.device_type() == DeviceType::WiFi,
);

if let Some(index) = index {
Some(devices[index].clone())
Expand Down
43 changes: 26 additions & 17 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ impl Connection {
fn init(dbus_manager: &Rc<DBusNetworkManager>, path: &str) -> Result<Self, String> {
let settings = dbus_manager.get_connection_settings(path)?;

Ok(
Connection {
dbus_manager: dbus_manager.clone(),
path: path.to_string(),
settings: settings,
}
)
Ok(Connection {
dbus_manager: dbus_manager.clone(),
path: path.to_string(),
settings: settings,
})
}

pub fn settings(&self) -> &ConnectionSettings {
Expand Down Expand Up @@ -209,8 +207,9 @@ pub fn get_connections(dbus_manager: &Rc<DBusNetworkManager>) -> Result<Vec<Conn
}


pub fn get_active_connections(dbus_manager: &Rc<DBusNetworkManager>)
-> Result<Vec<Connection>, String> {
pub fn get_active_connections(
dbus_manager: &Rc<DBusNetworkManager>,
) -> Result<Vec<Connection>, String> {
let active_paths = dbus_manager.get_active_connections()?;

let mut connections = Vec::with_capacity(active_paths.len());
Expand All @@ -235,11 +234,16 @@ pub fn connect_to_access_point<P>(
security: &Security,
password: &P,
) -> Result<(Connection, ConnectionState), String>
where P: AsAsciiStr + ?Sized
where
P: AsAsciiStr + ?Sized,
{
let (path, _) =
dbus_manager
.connect_to_access_point(device_path, access_point_path, ssid, security, password)?;
let (path, _) = dbus_manager.connect_to_access_point(
device_path,
access_point_path,
ssid,
security,
password,
)?;

let connection = Connection::init(dbus_manager, &path)?;

Expand All @@ -255,11 +259,16 @@ pub fn create_hotspot<S, P>(
ssid: &S,
password: Option<&P>,
) -> Result<(Connection, ConnectionState), String>
where S: AsSsidSlice + ?Sized,
P: AsAsciiStr + ?Sized
where
S: AsSsidSlice + ?Sized,
P: AsAsciiStr + ?Sized,
{
let (path, _) = dbus_manager
.create_hotspot(device_path, interface, ssid, password)?;
let (path, _) = dbus_manager.create_hotspot(
device_path,
interface,
ssid,
password,
)?;

let connection = Connection::init(dbus_manager, &path)?;

Expand Down
63 changes: 35 additions & 28 deletions src/dbus_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@ impl DBusApi {
args: &[&RefArg],
) -> Result<Message, String> {
self.call_with_args_retry(path, interface, method, args)
.map_err(
|error| {
let message = format!(
"D-Bus '{}'::'{}' method call failed on '{}': {}",
interface,
method,
path,
error
);
error!("{}", message);
message
}
)
.map_err(|error| {
let message = format!(
"D-Bus '{}'::'{}' method call failed on '{}': {}",
interface,
method,
path,
error
);
error!("{}", message);
message
})
}

fn call_with_args_retry(
Expand Down Expand Up @@ -116,8 +114,10 @@ impl DBusApi {
}

fn send_message_checked(&self, message: Message) -> Option<Result<Message, String>> {
match self.connection
.send_with_reply_and_block(message, self.method_timeout as i32 * 1000) {
match self.connection.send_with_reply_and_block(
message,
self.method_timeout as i32 * 1000,
) {
Ok(response) => Some(Ok(response)),
Err(err) => {
let message = get_error_message(&err).to_string();
Expand All @@ -137,7 +137,8 @@ impl DBusApi {
}

pub fn property<T>(&self, path: &str, interface: &str, name: &str) -> Result<T, String>
where DBusApi: VariantTo<T>
where
DBusApi: VariantTo<T>,
{
let property_error = |details: &str| {
let message = format!(
Expand Down Expand Up @@ -170,16 +171,18 @@ impl DBusApi {
}

pub fn extract<'a, T>(&self, response: &'a Message) -> Result<T, String>
where T: Get<'a>
where
T: Get<'a>,
{
response
.get1()
.ok_or_else(|| "D-Bus wrong response type".to_string())
response.get1().ok_or_else(
|| "D-Bus wrong response type".to_string(),
)
}

pub fn extract_two<'a, T1, T2>(&self, response: &'a Message) -> Result<(T1, T2), String>
where T1: Get<'a>,
T2: Get<'a>
where
T1: Get<'a>,
T2: Get<'a>,
{
let (first, second) = response.get2();

Expand All @@ -193,8 +196,11 @@ impl DBusApi {
}

fn with_path<'a, P: Into<Path<'a>>>(&'a self, path: P) -> ConnPath<&'a DBusConnection> {
self.connection
.with_path(self.base, path, self.method_timeout as i32 * 1000)
self.connection.with_path(
self.base,
path,
self.method_timeout as i32 * 1000,
)
}
}

Expand Down Expand Up @@ -275,11 +281,12 @@ impl VariantTo<Vec<u8>> for DBusApi {


pub fn extract<'a, T>(var: &mut Variant<Iter<'a>>) -> Result<T, String>
where T: Get<'a>
where
T: Get<'a>,
{
var.0
.get::<T>()
.ok_or_else(|| format!("D-Bus variant type does not match: {:?}", var))
var.0.get::<T>().ok_or_else(|| {
format!("D-Bus variant type does not match: {:?}", var)
})
}

pub fn variant_iter_to_vec_u8(var: &mut Variant<Iter>) -> Result<Vec<u8>, String> {
Expand Down
Loading

0 comments on commit 28ba008

Please sign in to comment.