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

Mark all errors Sync + Send #24

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use blurz::bluetooth_adapter::BluetoothAdapter as Adapter;
use blurz::bluetooth_device::BluetoothDevice as Device;
use blurz::bluetooth_session::BluetoothSession as Session;

fn test() -> Result<(), Box<Error>> {
fn test() -> Result<(), Box<Error + Send + Sync>> {
let session = &Session::create_session(None).unwrap();
let adapter: Adapter = try!(Adapter::init(session));
let device: Device = try!(adapter.get_first_device());
Expand Down
2 changes: 1 addition & 1 deletion examples/test2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use blurz::bluetooth_gatt_descriptor::BluetoothGATTDescriptor as Descriptor;
use blurz::bluetooth_gatt_service::BluetoothGATTService as Service;
use blurz::bluetooth_session::BluetoothSession as Session;

fn test2() -> Result<(), Box<Error>> {
fn test2() -> Result<(), Box<Error + Send + Sync>> {
let bt_session = &Session::create_session(None)?;
let adapter: Adapter = try!(Adapter::init(bt_session));
let session = try!(DiscoverySession::create_session(
Expand Down
2 changes: 1 addition & 1 deletion examples/test3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use blurz::bluetooth_device::BluetoothDevice as Device;
use blurz::bluetooth_discovery_session::BluetoothDiscoverySession as DiscoverySession;
use blurz::bluetooth_session::BluetoothSession as Session;

fn test3() -> Result<(), Box<Error>> {
fn test3() -> Result<(), Box<Error + Send + Sync>> {
let bt_session = &Session::create_session(None)?;
let adapter: Adapter = try!(Adapter::init(bt_session));
try!(adapter.set_powered(true));
Expand Down
2 changes: 1 addition & 1 deletion examples/test4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use blurz::bluetooth_obex::{
};
use blurz::bluetooth_session::BluetoothSession as Session;

fn test_obex_file_transfer() -> Result<(), Box<Error>> {
fn test_obex_file_transfer() -> Result<(), Box<Error + Send + Sync>> {
let session = &Session::create_session(None)?;
let adapter: Adapter = Adapter::init(session)?;
let devices: Vec<String> = adapter.get_device_list()?;
Expand Down
2 changes: 1 addition & 1 deletion examples/test5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::error::Error;
use blurz::bluetooth_event::BluetoothEvent;
use blurz::bluetooth_session::BluetoothSession as Session;

fn test5() -> Result<(), Box<Error>> {
fn test5() -> Result<(), Box<Error + Send + Sync>> {
let session = &Session::create_session(Some("/org/bluez/hci0")).unwrap();
loop {
for event in session.incoming(1000).map(BluetoothEvent::from) {
Expand Down
64 changes: 32 additions & 32 deletions src/bluetooth_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> BluetoothAdapter<'a> {
}
}

pub fn init(session: &BluetoothSession) -> Result<BluetoothAdapter, Box<Error>> {
pub fn init(session: &BluetoothSession) -> Result<BluetoothAdapter, Box<Error + Send + Sync>> {
let adapters = try!(bluetooth_utils::get_adapters(session.get_connection()));

if adapters.is_empty() {
Expand All @@ -34,7 +34,7 @@ impl<'a> BluetoothAdapter<'a> {
pub fn create_adapter(
session: &BluetoothSession,
object_path: String,
) -> Result<BluetoothAdapter, Box<Error>> {
) -> Result<BluetoothAdapter, Box<Error + Send + Sync>> {
let adapters = try!(bluetooth_utils::get_adapters(session.get_connection()));

for adapter in adapters {
Expand All @@ -49,7 +49,7 @@ impl<'a> BluetoothAdapter<'a> {
self.object_path.clone()
}

pub fn get_first_device(&self) -> Result<BluetoothDevice, Box<Error>> {
pub fn get_first_device(&self) -> Result<BluetoothDevice, Box<Error + Send + Sync>> {
let devices = try!(bluetooth_utils::list_devices(
self.session.get_connection(),
&self.object_path
Expand All @@ -61,11 +61,11 @@ impl<'a> BluetoothAdapter<'a> {
Ok(BluetoothDevice::new(self.session, devices[0].clone()))
}

pub fn get_device_list(&self) -> Result<Vec<String>, Box<Error>> {
pub fn get_device_list(&self) -> Result<Vec<String>, Box<Error + Send + Sync>> {
bluetooth_utils::list_devices(self.session.get_connection(), &self.object_path)
}

fn get_property(&self, prop: &str) -> Result<MessageItem, Box<Error>> {
fn get_property(&self, prop: &str) -> Result<MessageItem, Box<Error + Send + Sync>> {
bluetooth_utils::get_property(
self.session.get_connection(),
ADAPTER_INTERFACE,
Expand All @@ -74,7 +74,7 @@ impl<'a> BluetoothAdapter<'a> {
)
}

fn set_property<T>(&self, prop: &str, value: T, timeout_ms: i32) -> Result<(), Box<Error>>
fn set_property<T>(&self, prop: &str, value: T, timeout_ms: i32) -> Result<(), Box<Error + Send + Sync>>
where
T: Into<MessageItem>,
{
Expand All @@ -93,7 +93,7 @@ impl<'a> BluetoothAdapter<'a> {
method: &str,
param: Option<&[MessageItem]>,
timeout_ms: i32,
) -> Result<(), Box<Error>> {
) -> Result<(), Box<Error + Send + Sync>> {
bluetooth_utils::call_method(
self.session.get_connection(),
ADAPTER_INTERFACE,
Expand All @@ -109,97 +109,97 @@ impl<'a> BluetoothAdapter<'a> {
*/

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n108
pub fn get_address(&self) -> Result<String, Box<Error>> {
pub fn get_address(&self) -> Result<String, Box<Error + Send + Sync>> {
let address = try!(self.get_property("Address"));
Ok(String::from(address.inner::<&str>().unwrap()))
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n112
pub fn get_name(&self) -> Result<String, Box<Error>> {
pub fn get_name(&self) -> Result<String, Box<Error + Send + Sync>> {
let name = try!(self.get_property("Name"));
Ok(String::from(name.inner::<&str>().unwrap()))
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n120
pub fn get_alias(&self) -> Result<String, Box<Error>> {
pub fn get_alias(&self) -> Result<String, Box<Error + Send + Sync>> {
let alias = try!(self.get_property("Alias"));
Ok(String::from(alias.inner::<&str>().unwrap()))
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n120
pub fn set_alias(&self, value: String) -> Result<(), Box<Error>> {
pub fn set_alias(&self, value: String) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("Alias", value, 1000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n139
pub fn get_class(&self) -> Result<u32, Box<Error>> {
pub fn get_class(&self) -> Result<u32, Box<Error + Send + Sync>> {
let class = try!(self.get_property("Class"));
Ok(class.inner::<u32>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n147
pub fn is_powered(&self) -> Result<bool, Box<Error>> {
pub fn is_powered(&self) -> Result<bool, Box<Error + Send + Sync>> {
let powered = try!(self.get_property("Powered"));
Ok(powered.inner::<bool>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n147
pub fn set_powered(&self, value: bool) -> Result<(), Box<Error>> {
pub fn set_powered(&self, value: bool) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("Powered", value, 10000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n156
pub fn is_discoverable(&self) -> Result<bool, Box<Error>> {
pub fn is_discoverable(&self) -> Result<bool, Box<Error + Send + Sync>> {
let discoverable = try!(self.get_property("Discoverable"));
Ok(discoverable.inner::<bool>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n156
pub fn set_discoverable(&self, value: bool) -> Result<(), Box<Error>> {
pub fn set_discoverable(&self, value: bool) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("Discoverable", value, 1000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n176
pub fn is_pairable(&self) -> Result<bool, Box<Error>> {
pub fn is_pairable(&self) -> Result<bool, Box<Error + Send + Sync>> {
let pairable = try!(self.get_property("Pairable"));
Ok(pairable.inner::<bool>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n176
pub fn set_pairable(&self, value: bool) -> Result<(), Box<Error>> {
pub fn set_pairable(&self, value: bool) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("Pairable", value, 1000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n187
pub fn get_pairable_timeout(&self) -> Result<u32, Box<Error>> {
pub fn get_pairable_timeout(&self) -> Result<u32, Box<Error + Send + Sync>> {
let pairable_timeout = try!(self.get_property("PairableTimeout"));
Ok(pairable_timeout.inner::<u32>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n187
pub fn set_pairable_timeout(&self, value: u32) -> Result<(), Box<Error>> {
pub fn set_pairable_timeout(&self, value: u32) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("PairableTimeout", value, 1000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n196
pub fn get_discoverable_timeout(&self) -> Result<u32, Box<Error>> {
pub fn get_discoverable_timeout(&self) -> Result<u32, Box<Error + Send + Sync>> {
let discoverable_timeout = try!(self.get_property("DiscoverableTimeout"));
Ok(discoverable_timeout.inner::<u32>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n196
pub fn set_discoverable_timeout(&self, value: u32) -> Result<(), Box<Error>> {
pub fn set_discoverable_timeout(&self, value: u32) -> Result<(), Box<Error + Send + Sync>> {
self.set_property("DiscoverableTimeout", value, 1000)
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n205
pub fn is_discovering(&self) -> Result<bool, Box<Error>> {
pub fn is_discovering(&self) -> Result<bool, Box<Error + Send + Sync>> {
let discovering = try!(self.get_property("Discovering"));
Ok(discovering.inner::<bool>().unwrap())
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n209
pub fn get_uuids(&self) -> Result<Vec<String>, Box<Error>> {
pub fn get_uuids(&self) -> Result<Vec<String>, Box<Error + Send + Sync>> {
let uuids = try!(self.get_property("UUIDs"));
let z: &[MessageItem] = uuids.inner().unwrap();
let mut v: Vec<String> = Vec::new();
Expand All @@ -210,7 +210,7 @@ impl<'a> BluetoothAdapter<'a> {
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n215
pub fn get_modalias(&self) -> Result<(String, u32, u32, u32), Box<Error>> {
pub fn get_modalias(&self) -> Result<(String, u32, u32, u32), Box<Error + Send + Sync>> {
let modalias = try!(self.get_property("Modalias"));
let m = modalias.inner::<&str>().unwrap();
let ids: Vec<&str> = m.split(":").collect();
Expand All @@ -228,22 +228,22 @@ impl<'a> BluetoothAdapter<'a> {
))
}

pub fn get_vendor_id_source(&self) -> Result<String, Box<Error>> {
pub fn get_vendor_id_source(&self) -> Result<String, Box<Error + Send + Sync>> {
let (vendor_id_source, _, _, _) = try!(self.get_modalias());
Ok(vendor_id_source)
}

pub fn get_vendor_id(&self) -> Result<u32, Box<Error>> {
pub fn get_vendor_id(&self) -> Result<u32, Box<Error + Send + Sync>> {
let (_, vendor_id, _, _) = try!(self.get_modalias());
Ok(vendor_id)
}

pub fn get_product_id(&self) -> Result<u32, Box<Error>> {
pub fn get_product_id(&self) -> Result<u32, Box<Error + Send + Sync>> {
let (_, _, product_id, _) = try!(self.get_modalias());
Ok(product_id)
}

pub fn get_device_id(&self) -> Result<u32, Box<Error>> {
pub fn get_device_id(&self) -> Result<u32, Box<Error + Send + Sync>> {
let (_, _, _, device_id) = try!(self.get_modalias());
Ok(device_id)
}
Expand All @@ -253,17 +253,17 @@ impl<'a> BluetoothAdapter<'a> {
*/

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n12
pub fn start_discovery(&self) -> Result<(), Box<Error>> {
pub fn start_discovery(&self) -> Result<(), Box<Error + Send + Sync>> {
Err(Box::from("Deprecated, use Discovery Session"))
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n27
pub fn stop_discovery(&self) -> Result<(), Box<Error>> {
pub fn stop_discovery(&self) -> Result<(), Box<Error + Send + Sync>> {
Err(Box::from("Deprecated, use Discovery Session"))
}

// http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n40
pub fn remove_device(&self, device: String) -> Result<(), Box<Error>> {
pub fn remove_device(&self, device: String) -> Result<(), Box<Error + Send + Sync>> {
self.call_method(
"RemoveDevice",
Some(&[MessageItem::ObjectPath(device.into())]),
Expand Down
Loading