Loading system/gd/rust/linux/stack/src/bluetooth_adv.rs +31 −34 Original line number Diff line number Diff line Loading @@ -398,7 +398,7 @@ impl Into<bt_topshim::profiles::gatt::PeriodicAdvertisingParameters> // Keeps information of an advertising set. #[derive(Debug, PartialEq, Copy, Clone)] pub(crate) struct AdvertisingSetInfo { struct AdvertisingSetInfo { /// Identifies the advertising set when it's started successfully. adv_id: Option<AdvertiserId>, Loading Loading @@ -431,7 +431,7 @@ pub(crate) struct AdvertisingSetInfo { } impl AdvertisingSetInfo { pub(crate) fn new( fn new( callback_id: CallbackId, adv_timeout: u16, adv_events: u8, Loading @@ -452,73 +452,73 @@ impl AdvertisingSetInfo { } /// Gets advertising set registration ID. pub(crate) fn reg_id(&self) -> RegId { fn reg_id(&self) -> RegId { self.reg_id } /// Gets associated callback ID. pub(crate) fn callback_id(&self) -> CallbackId { fn callback_id(&self) -> CallbackId { self.callback_id } /// Updates advertiser ID. pub(crate) fn set_adv_id(&mut self, id: Option<AdvertiserId>) { fn set_adv_id(&mut self, id: Option<AdvertiserId>) { self.adv_id = id; } /// Gets advertiser ID, which is required for advertising |BleAdvertiserInterface|. pub(crate) fn adv_id(&self) -> u8 { fn adv_id(&self) -> u8 { // As advertiser ID was from topshim originally, type casting is safe. self.adv_id.unwrap_or(INVALID_ADV_ID) as u8 } /// Updates advertising set status. pub(crate) fn set_enabled(&mut self, enabled: bool) { fn set_enabled(&mut self, enabled: bool) { self.enabled = enabled; } /// Returns true if the advertising set has been enabled, false otherwise. pub(crate) fn is_enabled(&self) -> bool { fn is_enabled(&self) -> bool { self.enabled } /// Marks the advertising set as paused or not. pub(crate) fn set_paused(&mut self, paused: bool) { fn set_paused(&mut self, paused: bool) { self.paused = paused; } /// Returns true if the advertising set has been paused, false otherwise. pub(crate) fn is_paused(&self) -> bool { fn is_paused(&self) -> bool { self.paused } /// Marks the advertising set as stopped. pub(crate) fn set_stopped(&mut self) { fn set_stopped(&mut self) { self.stopped = true; } /// Returns true if the advertising set has been stopped, false otherwise. pub(crate) fn is_stopped(&self) -> bool { fn is_stopped(&self) -> bool { self.stopped } /// Gets adv_timeout. pub(crate) fn adv_timeout(&self) -> u16 { fn adv_timeout(&self) -> u16 { self.adv_timeout } /// Gets adv_events. pub(crate) fn adv_events(&self) -> u8 { fn adv_events(&self) -> u8 { self.adv_events } /// Returns whether the legacy advertisement will be used. pub(crate) fn is_legacy(&self) -> bool { fn is_legacy(&self) -> bool { self.legacy } /// Returns whether the advertising set is valid. pub(crate) fn is_valid(&self) -> bool { fn is_valid(&self) -> bool { self.adv_id.is_some() } } Loading Loading @@ -556,31 +556,31 @@ impl AdvertiseManager { } // Returns the minimum unoccupied register ID from 0. pub(crate) fn new_reg_id(&mut self) -> RegId { fn new_reg_id(&mut self) -> RegId { (0..) .find(|id| !self.sets.contains_key(id)) .expect("There must be an unoccupied register ID") } /// Adds an advertising set. pub(crate) fn add(&mut self, s: AdvertisingSetInfo) { fn add(&mut self, s: AdvertisingSetInfo) { if let Some(old) = self.sets.insert(s.reg_id(), s) { warn!("An advertising set with the same reg_id ({}) exists. Drop it!", old.reg_id); } } /// Returns an iterator of valid advertising sets. pub(crate) fn valid_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn valid_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.sets.iter().filter_map(|(_, s)| s.adv_id.map(|_| s)) } /// Returns an iterator of enabled advertising sets. pub(crate) fn enabled_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn enabled_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_enabled()) } /// Returns an iterator of stopped advertising sets. pub(crate) fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_stopped()) } Loading @@ -594,17 +594,17 @@ impl AdvertiseManager { } /// Returns a mutable reference to the advertising set with the reg_id specified. pub(crate) fn get_mut_by_reg_id(&mut self, reg_id: RegId) -> Option<&mut AdvertisingSetInfo> { fn get_mut_by_reg_id(&mut self, reg_id: RegId) -> Option<&mut AdvertisingSetInfo> { self.sets.get_mut(®_id) } /// Returns a shared reference to the advertising set with the reg_id specified. pub(crate) fn get_by_reg_id(&self, reg_id: RegId) -> Option<&AdvertisingSetInfo> { fn get_by_reg_id(&self, reg_id: RegId) -> Option<&AdvertisingSetInfo> { self.sets.get(®_id) } /// Returns a mutable reference to the advertising set with the advertiser ID specified. pub(crate) fn get_mut_by_advertiser_id( fn get_mut_by_advertiser_id( &mut self, adv_id: AdvertiserId, ) -> Option<&mut AdvertisingSetInfo> { Loading @@ -615,7 +615,7 @@ impl AdvertiseManager { } /// Returns a shared reference to the advertising set with the advertiser ID specified. pub(crate) fn get_by_advertiser_id(&self, adv_id: AdvertiserId) -> Option<&AdvertisingSetInfo> { fn get_by_advertiser_id(&self, adv_id: AdvertiserId) -> Option<&AdvertisingSetInfo> { if let Some(reg_id) = self.find_reg_id(adv_id) { return self.get_by_reg_id(reg_id); } Loading @@ -625,17 +625,14 @@ impl AdvertiseManager { /// Removes the advertising set with the reg_id specified. /// /// Returns the advertising set if found, None otherwise. pub(crate) fn remove_by_reg_id(&mut self, reg_id: RegId) -> Option<AdvertisingSetInfo> { fn remove_by_reg_id(&mut self, reg_id: RegId) -> Option<AdvertisingSetInfo> { self.sets.remove(®_id) } /// Removes the advertising set with the specified advertiser ID. /// /// Returns the advertising set if found, None otherwise. pub(crate) fn remove_by_advertiser_id( &mut self, adv_id: AdvertiserId, ) -> Option<AdvertisingSetInfo> { fn remove_by_advertiser_id(&mut self, adv_id: AdvertiserId) -> Option<AdvertisingSetInfo> { if let Some(reg_id) = self.find_reg_id(adv_id) { return self.remove_by_reg_id(reg_id); } Loading @@ -643,7 +640,7 @@ impl AdvertiseManager { } /// Returns callback of the advertising set. pub(crate) fn get_callback( fn get_callback( &mut self, s: &AdvertisingSetInfo, ) -> Option<&mut Box<dyn IAdvertisingSetCallback + Send>> { Loading @@ -651,7 +648,7 @@ impl AdvertiseManager { } /// Update suspend mode. pub(crate) fn set_suspend_mode(&mut self, suspend_mode: SuspendMode) { fn set_suspend_mode(&mut self, suspend_mode: SuspendMode) { if suspend_mode != self.suspend_mode { self.suspend_mode = suspend_mode; self.notify_suspend_mode(); Loading @@ -659,7 +656,7 @@ impl AdvertiseManager { } /// Gets current suspend mode. pub(crate) fn suspend_mode(&mut self) -> SuspendMode { fn suspend_mode(&mut self) -> SuspendMode { self.suspend_mode.clone() } Loading Loading @@ -718,7 +715,7 @@ impl AdvertiseManager { } } pub(crate) trait IBluetoothAdvertiseManager { pub trait IBluetoothAdvertiseManager { /// Registers callback for BLE advertising. fn register_callback(&mut self, callback: Box<dyn IAdvertisingSetCallback + Send>) -> u32; Loading Loading
system/gd/rust/linux/stack/src/bluetooth_adv.rs +31 −34 Original line number Diff line number Diff line Loading @@ -398,7 +398,7 @@ impl Into<bt_topshim::profiles::gatt::PeriodicAdvertisingParameters> // Keeps information of an advertising set. #[derive(Debug, PartialEq, Copy, Clone)] pub(crate) struct AdvertisingSetInfo { struct AdvertisingSetInfo { /// Identifies the advertising set when it's started successfully. adv_id: Option<AdvertiserId>, Loading Loading @@ -431,7 +431,7 @@ pub(crate) struct AdvertisingSetInfo { } impl AdvertisingSetInfo { pub(crate) fn new( fn new( callback_id: CallbackId, adv_timeout: u16, adv_events: u8, Loading @@ -452,73 +452,73 @@ impl AdvertisingSetInfo { } /// Gets advertising set registration ID. pub(crate) fn reg_id(&self) -> RegId { fn reg_id(&self) -> RegId { self.reg_id } /// Gets associated callback ID. pub(crate) fn callback_id(&self) -> CallbackId { fn callback_id(&self) -> CallbackId { self.callback_id } /// Updates advertiser ID. pub(crate) fn set_adv_id(&mut self, id: Option<AdvertiserId>) { fn set_adv_id(&mut self, id: Option<AdvertiserId>) { self.adv_id = id; } /// Gets advertiser ID, which is required for advertising |BleAdvertiserInterface|. pub(crate) fn adv_id(&self) -> u8 { fn adv_id(&self) -> u8 { // As advertiser ID was from topshim originally, type casting is safe. self.adv_id.unwrap_or(INVALID_ADV_ID) as u8 } /// Updates advertising set status. pub(crate) fn set_enabled(&mut self, enabled: bool) { fn set_enabled(&mut self, enabled: bool) { self.enabled = enabled; } /// Returns true if the advertising set has been enabled, false otherwise. pub(crate) fn is_enabled(&self) -> bool { fn is_enabled(&self) -> bool { self.enabled } /// Marks the advertising set as paused or not. pub(crate) fn set_paused(&mut self, paused: bool) { fn set_paused(&mut self, paused: bool) { self.paused = paused; } /// Returns true if the advertising set has been paused, false otherwise. pub(crate) fn is_paused(&self) -> bool { fn is_paused(&self) -> bool { self.paused } /// Marks the advertising set as stopped. pub(crate) fn set_stopped(&mut self) { fn set_stopped(&mut self) { self.stopped = true; } /// Returns true if the advertising set has been stopped, false otherwise. pub(crate) fn is_stopped(&self) -> bool { fn is_stopped(&self) -> bool { self.stopped } /// Gets adv_timeout. pub(crate) fn adv_timeout(&self) -> u16 { fn adv_timeout(&self) -> u16 { self.adv_timeout } /// Gets adv_events. pub(crate) fn adv_events(&self) -> u8 { fn adv_events(&self) -> u8 { self.adv_events } /// Returns whether the legacy advertisement will be used. pub(crate) fn is_legacy(&self) -> bool { fn is_legacy(&self) -> bool { self.legacy } /// Returns whether the advertising set is valid. pub(crate) fn is_valid(&self) -> bool { fn is_valid(&self) -> bool { self.adv_id.is_some() } } Loading Loading @@ -556,31 +556,31 @@ impl AdvertiseManager { } // Returns the minimum unoccupied register ID from 0. pub(crate) fn new_reg_id(&mut self) -> RegId { fn new_reg_id(&mut self) -> RegId { (0..) .find(|id| !self.sets.contains_key(id)) .expect("There must be an unoccupied register ID") } /// Adds an advertising set. pub(crate) fn add(&mut self, s: AdvertisingSetInfo) { fn add(&mut self, s: AdvertisingSetInfo) { if let Some(old) = self.sets.insert(s.reg_id(), s) { warn!("An advertising set with the same reg_id ({}) exists. Drop it!", old.reg_id); } } /// Returns an iterator of valid advertising sets. pub(crate) fn valid_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn valid_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.sets.iter().filter_map(|(_, s)| s.adv_id.map(|_| s)) } /// Returns an iterator of enabled advertising sets. pub(crate) fn enabled_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn enabled_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_enabled()) } /// Returns an iterator of stopped advertising sets. pub(crate) fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_stopped()) } Loading @@ -594,17 +594,17 @@ impl AdvertiseManager { } /// Returns a mutable reference to the advertising set with the reg_id specified. pub(crate) fn get_mut_by_reg_id(&mut self, reg_id: RegId) -> Option<&mut AdvertisingSetInfo> { fn get_mut_by_reg_id(&mut self, reg_id: RegId) -> Option<&mut AdvertisingSetInfo> { self.sets.get_mut(®_id) } /// Returns a shared reference to the advertising set with the reg_id specified. pub(crate) fn get_by_reg_id(&self, reg_id: RegId) -> Option<&AdvertisingSetInfo> { fn get_by_reg_id(&self, reg_id: RegId) -> Option<&AdvertisingSetInfo> { self.sets.get(®_id) } /// Returns a mutable reference to the advertising set with the advertiser ID specified. pub(crate) fn get_mut_by_advertiser_id( fn get_mut_by_advertiser_id( &mut self, adv_id: AdvertiserId, ) -> Option<&mut AdvertisingSetInfo> { Loading @@ -615,7 +615,7 @@ impl AdvertiseManager { } /// Returns a shared reference to the advertising set with the advertiser ID specified. pub(crate) fn get_by_advertiser_id(&self, adv_id: AdvertiserId) -> Option<&AdvertisingSetInfo> { fn get_by_advertiser_id(&self, adv_id: AdvertiserId) -> Option<&AdvertisingSetInfo> { if let Some(reg_id) = self.find_reg_id(adv_id) { return self.get_by_reg_id(reg_id); } Loading @@ -625,17 +625,14 @@ impl AdvertiseManager { /// Removes the advertising set with the reg_id specified. /// /// Returns the advertising set if found, None otherwise. pub(crate) fn remove_by_reg_id(&mut self, reg_id: RegId) -> Option<AdvertisingSetInfo> { fn remove_by_reg_id(&mut self, reg_id: RegId) -> Option<AdvertisingSetInfo> { self.sets.remove(®_id) } /// Removes the advertising set with the specified advertiser ID. /// /// Returns the advertising set if found, None otherwise. pub(crate) fn remove_by_advertiser_id( &mut self, adv_id: AdvertiserId, ) -> Option<AdvertisingSetInfo> { fn remove_by_advertiser_id(&mut self, adv_id: AdvertiserId) -> Option<AdvertisingSetInfo> { if let Some(reg_id) = self.find_reg_id(adv_id) { return self.remove_by_reg_id(reg_id); } Loading @@ -643,7 +640,7 @@ impl AdvertiseManager { } /// Returns callback of the advertising set. pub(crate) fn get_callback( fn get_callback( &mut self, s: &AdvertisingSetInfo, ) -> Option<&mut Box<dyn IAdvertisingSetCallback + Send>> { Loading @@ -651,7 +648,7 @@ impl AdvertiseManager { } /// Update suspend mode. pub(crate) fn set_suspend_mode(&mut self, suspend_mode: SuspendMode) { fn set_suspend_mode(&mut self, suspend_mode: SuspendMode) { if suspend_mode != self.suspend_mode { self.suspend_mode = suspend_mode; self.notify_suspend_mode(); Loading @@ -659,7 +656,7 @@ impl AdvertiseManager { } /// Gets current suspend mode. pub(crate) fn suspend_mode(&mut self) -> SuspendMode { fn suspend_mode(&mut self) -> SuspendMode { self.suspend_mode.clone() } Loading Loading @@ -718,7 +715,7 @@ impl AdvertiseManager { } } pub(crate) trait IBluetoothAdvertiseManager { pub trait IBluetoothAdvertiseManager { /// Registers callback for BLE advertising. fn register_callback(&mut self, callback: Box<dyn IAdvertisingSetCallback + Send>) -> u32; Loading