Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc92f4d9 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

floss: Change enum repr and D-Bus type from i32 to u32

u32 for enums is more suitable to be a convention for D-Bus data type
mapping (UINT32 rather than INT32).

Bug: 202334519
Tag: #floss
Test: Manual

Change-Id: Ib1604a8fc78d16ba7506ceca4a8bcf495815415d
parent 51584872
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -162,16 +162,16 @@ impl DisconnectWatcher {
macro_rules! impl_dbus_arg_enum {
    ($enum_type:ty) => {
        impl DBusArg for $enum_type {
            type DBusType = i32;
            type DBusType = u32;
            fn from_dbus(
                data: i32,
                data: u32,
                _conn: Option<Arc<SyncConnection>>,
                _remote: Option<dbus::strings::BusName<'static>>,
                _disconnect_watcher: Option<
                    Arc<std::sync::Mutex<dbus_projection::DisconnectWatcher>>,
                >,
            ) -> Result<$enum_type, Box<dyn std::error::Error>> {
                match <$enum_type>::from_i32(data) {
                match <$enum_type>::from_u32(data) {
                    Some(x) => Ok(x),
                    None => Err(Box::new(DBusArgError::new(String::from(format!(
                        "error converting {} to {}",
@@ -181,8 +181,8 @@ macro_rules! impl_dbus_arg_enum {
                }
            }

            fn to_dbus(data: $enum_type) -> Result<i32, Box<dyn std::error::Error>> {
                return Ok(data.to_i32().unwrap());
            fn to_dbus(data: $enum_type) -> Result<u32, Box<dyn std::error::Error>> {
                return Ok(data.to_u32().unwrap());
            }
        }
    };
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ use tokio::sync::mpsc;
pub const PID_DIR: &str = "/var/run/bluetooth";

#[derive(Debug, PartialEq, Copy, Clone)]
#[repr(i32)]
#[repr(u32)]
pub enum State {
    Off = 0,        // Bluetooth is not running
    TurningOn = 1,  // We are not notified that the Bluetooth is running
+1 −1
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ pub enum LePhy {
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[repr(i32)]
#[repr(u32)]
/// Scan type configuration.
pub enum ScanType {
    Active = 0,
+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ impl From<BtPropertyType> for u32 {
}

#[derive(Clone, Debug, FromPrimitive, ToPrimitive, PartialEq, PartialOrd)]
#[repr(i32)]
#[repr(u32)]
pub enum BtDiscoveryState {
    Stopped = 0x0,
    Started,