bluebus 0.1.5

A Rust library for interacting with Bluetooth devices using the org.bluez D-Bus API.
Documentation
/// Represents a Bluetooth agent that handles authentication requests.
/// This struct manages PIN codes and passkeys for pairing operations.
pub struct Agent {
    /// The PIN code used for pairing.
    pincode: String,
    /// The passkey used for authentication.
    passkey: u32,
}

impl Agent {
    /// Creates a new agent with a given PIN code and passkey.
    /// 
    /// # Arguments
    /// * `pincode` - A string representing the PIN code.
    /// * `passkey` - A 32-bit unsigned integer representing the passkey.
    /// 
    /// # Returns
    /// A new `Agent` instance.
    pub fn new(pincode: String, passkey: u32) -> Self {
        Self { pincode, passkey }
    }

    /// Releases the agent, indicating it is no longer in use.
    /// 
    /// # Returns
    /// A `Result` indicating success or failure.
    pub async fn release(&self) -> zbus::fdo::Result<()> {
        println!("Agent Released");
        Ok(())
    }

    /// Handles a request for a PIN code from a Bluetooth device.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the requesting device.
    /// 
    /// # Returns
    /// The PIN code as a string.
    pub async fn request_pin_code(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
    ) -> zbus::fdo::Result<String> {
        println!(
            "RequestPinCode -> device: {}, pincode: {}",
            device, self.pincode
        );
        Ok(self.pincode.clone())
    }

    /// Displays a PIN code on the device for user verification.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the device.
    /// * `pincode` - The PIN code to display.
    pub async fn display_pin_code(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
        pincode: &str,
    ) -> zbus::fdo::Result<()> {
        println!("DisplayPinCode -> dev: {}, pincode: {}", device, pincode);
        Ok(())
    }

    /// Handles a request for a passkey from a Bluetooth device.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the requesting device.
    /// 
    /// # Returns
    /// The passkey as a 32-bit unsigned integer.
    pub async fn request_passkey(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
    ) -> zbus::fdo::Result<u32> {
        println!(
            "RequestPasskey -> dev: {}, passkey: {}",
            device, self.passkey
        );
        Ok(self.passkey)
    }

    /// Displays the passkey and entered digits on the device.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the device.
    /// * `passkey` - The passkey to display.
    /// * `entered` - The number of entered digits.
    pub async fn display_passkey(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
        passkey: u32,
        entered: u16,
    ) -> zbus::fdo::Result<()> {
        println!(
            "DisplayPasskey -> dev: {}, passkey: {}, entered: {}",
            device, passkey, entered
        );
        Ok(())
    }

    /// Requests user confirmation for pairing based on the passkey.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the device.
    /// * `passkey` - The passkey for verification.
    pub fn request_confirmation(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
        passkey: u32,
    ) -> zbus::fdo::Result<()> {
        println!(
            "RequestConfirmation -> dev: {}, passkey: {}",
            device, passkey
        );
        Ok(())
    }

    /// Requests user authorization for a connection.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the device.
    pub async fn request_authorization(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
    ) -> zbus::fdo::Result<()> {
        println!("RequestAuthorization -> dev: {}", device);
        Ok(())
    }

    /// Authorizes a service request from a Bluetooth device.
    /// 
    /// # Arguments
    /// * `device` - The D-Bus object path of the device.
    /// * `uuid` - The UUID of the requested service.
    pub async fn authorize_service(
        &self,
        device: &zbus::zvariant::OwnedObjectPath,
        uuid: &str,
    ) -> zbus::fdo::Result<()> {
        println!("AuthorizeService -> dev: {}, uuid: {}", device, uuid);
        Ok(())
    }

    /// Cancels an ongoing pairing or authentication process.
    pub async fn cancel(&self) -> zbus::fdo::Result<()> {
        println!("Cancel");
        Ok(())
    }
}