[][src]Struct rustable::Bluetooth

pub struct Bluetooth {
    pub verbose: u8,
    // some fields omitted
}

Bluetooth is created to interact with Bluez over DBus and file descriptors.

Fields

verbose: u8

Implementations

impl Bluetooth[src]

pub fn new(dbus_name: String, blue_path: String) -> Result<Self, Error>[src]

Creates a new Bluetooth and setup a DBus client to interact with Bluez.

pub fn update_adapter_props(&mut self) -> Result<(), Error>[src]

Forces an update of the local cached adapter state by reading the properties using a Dbus message.

Generally the locally cached state of the adapter is kept up to date, by reading DBus signals coming from the Bluez daemon, so this method doesn't typically need to be called.

pub fn addr(&self) -> &MAC[src]

Get the MAC of the local adapter.

pub fn set_filter(&mut self, filter: Option<String>) -> Result<(), Error>[src]

Allows for changing which messages sources are allowed or rejected.

By default, Bluetooth's filter is set to org.bluez, only allowing it to receive messages from the bluetooth daemon. This method allows this filter to be eliminated (None) or set to something else. This can be useful for debugging.

pub fn get_path(&self) -> &Path[src]

Gets the path of the DBus client

pub fn add_service(
    &mut self,
    mut service: LocalServiceBase
) -> Result<(), Error>
[src]

Adds a service to the Bluetooth instance. Once registered with register_application(), this service will be a local service that can be interacted with by remote devices.

If register_application() has already called, the service will not be visible to Bluez (or other devices) until the application in reregistered.

pub fn get_service<T: ToUUID>(&mut self, uuid: T) -> Option<LocalService<'_>>[src]

Access a service that has been added to the Bluetooth instance.

pub fn get_device<'c>(&'c mut self, mac: &MAC) -> Option<RemoteDevice<'c>>[src]

Gets a remote device by MAC. The device must be discovered using discover_devices() from bluez, before it can be gotten with this device.

pub fn devices(&self) -> Vec<MAC>[src]

Gets a HashSet of known devices' MAC addresses.

pub fn start_adv(&mut self, mut adv: Advertisement) -> Result<u16, (u16, Error)>[src]

Registers an advertisement with Bluez. After a successful call, it will persist until the remove_advertise()/remove_advertise_no_dbus() is called or Bluez releases the advertisement (this is typically done on device connect).

Calls process_requests()

pub fn is_adv_active(&self, index: u16) -> Option<bool>[src]

Checks if an advertisement is still active, or if Bluez has signaled it has ended.

pub fn restart_adv(&mut self, index: u16) -> Result<bool, Error>[src]

Restart an inactive advertisement.

If the advertisement is already active this method, does nothing and returns false. If an advertisement is not active it tries to reregister the advertisement and returns true on success otherwise it returns and Err.

pub fn remove_adv(&mut self, index: u16) -> Result<Advertisement, Error>[src]

Unregisters an advertisement with Bluez. Returns the Advertisement if successful.

Calls process_requests()

pub fn remove_all_adv(&mut self) -> Result<(), Error>[src]

pub fn remove_adv_no_dbus(&mut self, index: u16) -> Option<Advertisement>[src]

Removes the advertisement from the Bluetooth instance but does not unregister the advertisement with Bluez. It is recommended that this is not used.

pub fn set_power(
    &mut self,
    on: bool
) -> Result<Pending<Result<(), Error>, (Rc<Cell<bool>>, bool, &'static str)>, Error>
[src]

Set the Bluez controller power on (true) or off.

pub fn set_power_wait(&mut self, on: bool) -> Result<(), Error>[src]

Set the Bluez controller power on (true) or off and waits for the response.

Calls process_requests()

pub fn set_discoverable(
    &mut self,
    on: bool
) -> Result<Pending<Result<(), Error>, (Rc<Cell<bool>>, bool, &'static str)>, Error>
[src]

Set whether the Bluez controller should be discoverable (true) or not.

pub fn discoverable(&self) -> bool[src]

Get whether the Bluez controller is currently discoverable.

pub fn set_discoverable_wait(&mut self, on: bool) -> Result<(), Error>[src]

Set whether the Bluez controller should be discoverable (true) or not and waits for the response.

Calls process_requests()

pub fn power(&mut self) -> bool[src]

Get whether the Bluez controller is currently powered.

pub fn register_application(&mut self) -> Result<(), Error>[src]

Registers the local application's GATT services/characteristics/descriptors. with the Bluez controller.

Calls process_requests()

pub fn unregister_application(&mut self) -> Result<(), Error>[src]

Unimplemented

Unregisters the local GATT services from the Bluez controller.

Calls process_requests()

pub fn process_requests(&mut self) -> Result<(), Error>[src]

Process incoming DBus requests for the local application.

When using Bluetooth this function should be called on a regular basis. Bluez uses DBus to handle read/write requests to characteristics and descriptors, as wells advertisement. Failure to call this method frequently enough could result in requests from GATT clients to timeout. Some other functions are guaranteed to call this function at least once while waiting for a responses from the Bluez controller. This property is noted in these functions' descriptions.

pub fn clear_devices(&mut self)[src]

Clear the known the devices from the local application. This function does not remove the devices from the controller. It merely causes the local application to forget them.

pub fn discover_devices(&mut self) -> Result<Vec<MAC>, Error>[src]

Used to get devices devices known to Bluez. This function does not trigger scan/discovery on the Bluez controller. Use set_scan() to initiate actual device discovery.

Calls process_requests()

pub fn try_resolve<T, V, U>(
    &mut self,
    mut pend: Pending<T, U>
) -> Result<T, ResolveError<T, U>>
[src]

Tries to resolve a Pending. If the Pending is not ready, or an error occurs it will return an Err(ResolveError)

Sometimes Calls process_requests(). If the Pending is fetching remote information then this will call [process_requests()], but some Pending are already resolved when created, such as reading a local characteristic. (These "PreResolved" Pendings exist to satisfy trait defitions.

pub fn resolve<T, U>(
    &mut self,
    mut pend: Pending<T, U>
) -> Result<T, (Pending<T, U>, Error)>
[src]

Resolve a Pending by waiting for its response.

Sometimes Calls process_requests(). If the Pending is fetching remote information then this will call [process_requests()], but some Pending are already resolved when created, such as reading a local characteristic. (These "PreResolved" Pendings exist to satisfy trait defitions.

pub fn discover_device(&mut self, mac: &MAC) -> Result<(), Error>[src]

Get a device from the Bluez controller.

Calls process_requests()

Trait Implementations

impl AsRawFd for Bluetooth[src]

Gets the underlying RawFd used to talk to DBus. This can be useful for using select/poll to check if [process_requests] needs to be called.

impl<'a, 'b: 'a, 'c: 'a> Device<'a> for Bluetooth[src]

type ServiceType = LocalService<'a>

impl<'a> HasChildren<'a> for Bluetooth[src]

type Child = &'a mut LocalServiceBase

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.